Advertisement

Sprites on a world

Started by February 21, 2000 03:43 PM
19 comments, last by PsYcHoPrOg 24 years, 8 months ago
As I have mentioned in several posts, I plan on, eventually, making a 2d shooter. I found out how to scroll the background by, but I still don''t know how to assign locations for the sprites on this world. For those of you who think that a shooter is like Quake, you''re lost. What I mean by shooter is like Aerofighters, Space Invaders, or 1942. What I mean by scrolling is, this: in my game, I would have the background scrolling under the users fighter jet to create the illusion of the plane flying over, let''s say, an enemy base. I found out how to do this, but I still have another problem. My problem is, when flying over the enemy base, say i''ll want an enemy tank to be in a certain spot at the base. How would I get the sprite of the tank to be in this predesignated location? Do I just specify the coordinates on the map? What should I do? How will I do this?
D:
HELP!
D:
Advertisement
You should specify everything in map coordinates. When you draw them to the screen you figure out the enemies relative position to the camera, then draw them at the same relative position on the screen.

If you want to get fancy you can do a little zooming by scaling the relative distance before putting the enemy and background on the screen, even more fancy and you rotate everything as well.
First off, It''s really annoying when you get upset because nobody posted within two hours of your original post. Not everyone sits on the internet all day just waiting to see a post by you. Get some patience!

To answer your question, your sprites x and y coordinates should be relative to the map. When you go to draw it, you should then figure out the sprites screen coordinates. The equation is simple:

SpriteDrawX = ScrollX - SpriteMapX;
SpriteDrawY = ScrollY - SpriteMapY;

Where SpriteDrawX/Y is what your sprites screen coordinates should be, and ScrollX/Y is where your view of the map is at the moment.

--TheGoop
Oops, that was me. I wish it would automatically fill out my username .

Oh yeah, and a correction, the equation should be
SpriteDrawX = SpriteMapX - ScrollX;
SpriteDrawY = SpriteMapY - ScrollY;

--TheGoop

Edited by - TheGoop on 2/21/00 6:22:24 PM
Thank you for your response. And for TheGoop, you''re right. I should be more patient. As for your formula, could you explain it a bit? I understand it, but what would I do with it. I was thinking that I would use a for loop to look through a lookup table that keeps track of where the sprites are on the map, and in the loop, it would check to see whether any sprites are currently in the "view window" and if they are, draw them. Is this gow to do it?
D:
Advertisement
This is what you were trying to say, right?
D:
Yes, that is the easiest way to do it. And that is what you should start with.

When there is a need for it you can do a little quicker culling of enemies, by using for example quad trees. But in the beginning I think it is a bit of an overkill.
Quad trees? Tell me more...
D:
Whoops, I hit the stop button too late. Sorry.
D:

This topic is closed to new replies.

Advertisement