tags:

views:

95

answers:

1

I was looking for tutorials on the net for a 2d camera that follows a sprite and I found a reply from this site:

(http://stackoverflow.com/questions/712296/xna-2d-camera-engine-that-follows-sprite)

I made a simple game where in the sprite is loaded at the center of the game screen and it moves according to the direction I press from my directional key pad.

I tried implementing this code and added the Spritebatch instruction to my game. There seem to be no syntax error, but once I run the game, I only see the blue screen. Also, the sprite I used didn't appear.

(I'd like to imitate the player control of Tasty Planet where in the goo is controlled by the mouse and the screen follows it around. - trailer of the game: http://www.youtube.com/watch?v=az4VgetA_n0

A: 

Game development is sometimes best accomplished step by step. Especially when one is first learning :-)

What you want to do is first get some basics onto the screen 1) the player's avatar, and b) some static component like a wall, or floor.

With those in place and rendering on the screen, then you implement your camera component. This will be a class that takes the player's position in the world and offsets any "world" item by that much.

For example, if the player is at 10,10 in the world, and there is a tree at 5,5 ... the tree should be drawn at -5,-5, and the player drawn at 0,0 (assuming your coordinate grid's 0,0 is in the middle of the screen). And as the player's position moves, just subtract that from static world object that you draw.

Joel Martinez