Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Someone told me that the movement concept in my 2D game is bad. When left or right arrow is pressed I'm scrolling the background which makes you feel that player avatar is moving (the avatar's X-position remains the same).

So... he told me something about matrix view. I should create all walls and platforms static and scroll only the camera and move the player's rectangle. I did a little research in Google, but found nothing.

Can you tell me anything about it? How to start? Maybe links, books and resources?

share|improve this question
    
By matrix I think he means a 2D array? You're looking for Tiled based design. –  Sidar Aug 29 '12 at 0:46
1  
He's probably talking about this concept (method 2), but this example is not in Java. You need a 2D rendering API that is capable of taking a transformation matrix when drawing. –  David Gouveia Aug 29 '12 at 10:23
add comment

2 Answers

up vote 4 down vote accepted

I don't recall where I saw the demo but I think I know what he is talking about -- or at least can provide related information.

The problem with the character not moving on the screen, being fixed at the center, is that the human player will not perceive any motion. The user will immediately feel that something is wrong, but perhaps not be able to pinpoint it. If the character is moving it is essential that some kind of actual motion is done.

One of the concepts used here is the player box. This is a region of the screen where the character always resides. Unlike a fixed location however the character can actually move all around in this box. The screen only starts to scroll as they approach the edge of the box. This means that each time the user changes directions they'll actually see their sprite move on the screen (regardless of what the background is doing).

From here you can start improving the effect by experimenting. Some games slowly center the character in the box again. Some have a kind of logrithmic box so that the first movements move the sprite a lot, but less and less as they get to the side of the box -- or this may be tied to the character's speed as well. What works well depends on your game, and by no means is there a definitive "best" solution.

share|improve this answer
add comment

In a 2D game you don't need to care about matrices regarding camera. What you should do is still add a camera to the game. In the simplest case it's just x and y coordinates, but it can also contain rotation and/or zoom.

When pressing left or right, your character X position should be updated accordingly. The world should stay static. Don't move the background or objects when the player is the one moving. You should then update the camera position to follow the player movement. You can either set the camera position to match the player position or implement something better as edA-qa mort-ora-y described. When rendering, you need to subtract the camera position from all other positions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.