Screen Offsets and Drawing with Offsets - Confused!
Hey all.
I'm very confused. Currently my 2D game has a static player character in the center of the screen and when he moves, the background scrolls in the opposite direction. Now I'm considering adding more sprites (like badies etc) and I would do that by starting them off at a specific set of coordinates and moving them every time the player moves.
I've read a lot about people using screen offsets. Like when their player character moves 5 pixels down, you set the offset to be (0,5) and then draw other sprites like draw(image, offsetX, offsetY, null). But if you actually move the player, won't it just go right off the edge of the screen? Plus, if your just drawing other sprites at different locations this isn't actually changing their x, y values so collision detection wouldn't work?
I'm confused! Any explanations?
Thanks.
of course collision detection would work, as long as you dont check collisions WITH the offset. Don't think of your character as static. Change his X,Y values too. Besides, it's impossible for him to be ALWAYS in the center, what if the viewing rectangle went off the edge of the "world," if it was trying to center the character, you'd have like a quarter of the screen of non-worldness.
You need to think of the offsets as a camera. It has nothing to do with what happens in the world, it just looks at it. Nothing like collision detection should be based on an offset, so do you all your calculations with various objects without even worrying about the offset, and then when it's time to draw, apply the offset to the current conditions. The offset is never permanently added/substracted to an object, it just performs an addition/substraction for the graphics drawing parameters.
Back to the main point- don't just move your offset. Move your character. Make sure he has actual X,Y data that changes so he can collide with stuff.