This site requires JavaScript, please enable it in your browser!
Greenfoot back

Builderboy2005's Comments

Back to Builderboy2005's profile

Gravity would be trivial to add ^^\
That depends on how you are formatting your tileX/Y variables. That will only work if they are negative numbers, usually you are going to want to subtract them instead of adding them
Very good point! I wonder if it would be cool to have a button you could press to switch between the two algorithms, that was you could see how they differ :D
Your lines seem to be unusually thick o.O Especially when the angle of the line is 45 degrees. There is an incredibly fast (integer arithmatic only!) line drawing algorithm called the Bresenham's line algorithm that might work better in this situation.
There are several elements that go together to make the scrolling work properly. The first is the scrolling background. I have two variables tilex and tiley. These represent the camera location in a way. When tilex and tiley are both zero, the top left of the screen is the same as the top left of the world. When tilex increases, the camera moves to the right, and when tiley increases, the camera moves down. Every frame, I redraw the background using my tilemap data and the correct camera offset to give the correct illusion that the camera is moving. The second part is my new class called ActionActor. This contains many features which help out the game, but primarily it is a way to create the scrolling illusion. Each ActionActor has it's own myX and myY variables that represent the objects GLOBAL location. That is to say, even if the camera moves, myX and myY remain the same. Then at the end of each frame, every ActionActor transfers it's global location into a local location by subtracting tilex from its myX, and tiley from its myY. Since this is part of the ActionActor class, all objects that are a subclass automatically 'insert' themselves into the scrolling world. Now, with all this in place, we have two thing. We have a world camera that can move around and look at the world. And we have objects that will move accordingly when the camera is also moved. Making the camera is easy at this point. Since tilex/tiley represents the camera location, we just need to set tilex/tiley to the location of our character. It's a bit complicated, but you can always check out the source code if you want!
As an optimization, since you aren't rotating the camera along the Y axis at all, you could also take individual 'slices' of wall image and scale them instead of going pixel by pixel.
Works just fine for me. Mind telling me what is being printed out in the console, if anything?
You can look at the source for ideas and learning, just make sure not to copy the code completely and use it for your project :P
Haha that's leftover code from my 3D space shooter beta XD