Slick2D Camera movement

Started by
11 comments, last by Zaphyk 9 years, 3 months ago

So i should create a camera class containing its x, y ,width, height and whenever i render should check if is inside its bounds before doing it. right? I didint get the part about collision, if i am always moving the map instead of the player how would i detect when the player is in front of a rock or at the boundaries of the map?

You're only "moving" the world when you draw it, at all other times(and really, logically in general) you can just think of the coordinate system as being static. If your character is at 100, 10 and is moving up then just clamp his position if he tries to move to a coordinate below zero. You can do the same thing with your camera object, if it spans 100 width and is at 0x and your "world" is constrained to 300 in width, then you just add the camera width to its position and clamp it so it can't go past that point. Think of it this way, what if you have an entire map loaded and there are enemies wandering around it, bumping into the blocked objects or the edge of the map. They will still be moving and bumping even if you can't see them, the renderer might be ignoring they exist altogether for many frames but the game logic will still be concerned with their position and other objects and entities relative to them.

Understand that in the world of the renderer there aren't boundaries or an "end" of the world, just the origin and spaces moving away from the origin. When you set up the code for the logical simulation of your world you have to decide how large it is and where to constrain the player or the camera to. Thats why it is important to always try and visualize the rendering and representation of the game world as seperate, the renderer can move and spin and change what it views while the "model" of the game world is just all the things in it and their logical positions interacting.

Another thing to understand is that coordinate systems are largely theoretical, the math only cares what coordinate system you are using at the point they ask for it. For example you position sprites from the top left of the screen generally, but if you WANT to you can just as easily define their position in some kind of class from the bottom left of the screen. All you have to do is use math to change the coordinate system right before the position gets given to the renderer.

Advertisement

I know it is for 3d rendering, but the main concept is the same: The Model View and Projection matrices

In your game the only difference is that you use 2d vectors and orthographic projection. I recommend you to understand the basics before you start to make any game.

Thank you very much to everyone i managed make it.

This topic is closed to new replies.

Advertisement