How would I go about scrolling a 2D game, would I use a camera object, and if so, I would I work out the offset and how would I render that?
I’m not using any game engine, btw.
Sorry if this isnt a very descriptive post…
How would I go about scrolling a 2D game, would I use a camera object, and if so, I would I work out the offset and how would I render that?
I’m not using any game engine, btw.
Sorry if this isnt a very descriptive post…
Umm, there is no need for a camera object in a 2D game.
2D games usually draw, or move tiles/sprites around in a off-screen buffer.
I wasn’t sure if I should use one, but how would I add scrolling on the x and y axis?
There is no NEED, but it makes things very easy. For example rotating a camera vs. rotating EVERYTHING and accordingly - whats do you think makes more sense ?
Well, what are you using ?
I’m using Java2D
Never actually done this before but a basic way of doing it would be:
AffineTransform identity = new AffineTransform();
g2d.translate(-viewX, -viewY);
//
//rendering code here
//
g2d.setTransform(identity);
where viewX and viewY are the x and y coordinates of the top left corner of your view. If you wanted to stay centered on the character you could do this first:
viewX = charX - screenWidth/2;
viewY = charY - screenHeight/2;
Where charX and charY are the coordinates of the character.
of course you need to think about culling as well
in java2d I wrote my own camera, but it was just a rect and whenever I draw ANYTHING I would subtract camera.x and camera.y from that position