Jump to content
  • Advertisement
Sign in to follow this  
MatthewDiaz

Sprite Drawing in a Level

This topic is 2565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok so in my 2D game I have my level editor set to give all sprites placed a world location. I also keep track of the camera world location. It was looking good into I ran into this problem which needs a solution. How do i determine which sprites to draw on the screen without checking through every sprite in the level in order to reduce overhead? I thought I could look at my level as having a certain amount of screens and keep track of which sprites are in which screen. Then when I move in my level, determine if I moved into another screen, and then push any sprites in the next screen onto the vector of sprites for drawing. But I am sure there is a better and faster way. Can you help me?

Share this post


Link to post
Share on other sites
Advertisement
Well, it depends on how the sprites are arranged. If they are arranged in a grid, then you can simply have a 2D array which stores information about what sprites are in each grid tile, and then draw all the sprites which are inside the screen. If they are not arranged in a grid, then you would probably have to look into some sort of spatial partitioning system to quickly determine which sprites should be drawn on the screen.

Share this post


Link to post
Share on other sites

Well, it depends on how the sprites are arranged. If they are arranged in a grid, then you can simply have a 2D array which stores information about what sprites are in each grid tile, and then draw all the sprites which are inside the screen. If they are not arranged in a grid, then you would probably have to look into some sort of spatial partitioning system to quickly determine which sprites should be drawn on the screen.


Yeah I made like a SpriteScreen class which stores all the sprites that are in a screen. I made one vector to store all these classes and the index of the vector as the screen identifier. The bottom left of the level is screen 0. If I move one to the right it is screen 1. If my levels is 10 screens wide and 2 screens high, when I move up from screen 0, I move to screen 5. I figure every time I move I would have to check what screens I am in, and this also seems to be a lot of overhead. My question is, is this fast enough or is there a faster way?

Share this post


Link to post
Share on other sites

Yeah I made like a SpriteScreen class which stores all the sprites that are in a screen. I made one vector to store all these classes and the index of the vector as the screen identifier. The bottom left of the level is screen 0. If I move one to the right it is screen 1. If my levels is 10 screens wide and 2 screens high, when I move up from screen 0, I move to screen 5. I figure every time I move I would have to check what screens I am in, and this also seems to be a lot of overhead. My question is, is this fast enough or is there a faster way?


Well, I would think that testing the camera position against the screens would only take 2 divisions, which is practically nothing in terms of computing time. Incidentally, if you had a level 10 screens wide, shouldn't the screen on top of screen 0 be screen 10?

Share this post


Link to post
Share on other sites

[quote name='ILoveJesus' timestamp='1322901043' post='4890078']
Yeah I made like a SpriteScreen class which stores all the sprites that are in a screen. I made one vector to store all these classes and the index of the vector as the screen identifier. The bottom left of the level is screen 0. If I move one to the right it is screen 1. If my levels is 10 screens wide and 2 screens high, when I move up from screen 0, I move to screen 5. I figure every time I move I would have to check what screens I am in, and this also seems to be a lot of overhead. My question is, is this fast enough or is there a faster way?


Well, I would think that testing the camera position against the screens would only take 2 divisions, which is practically nothing in terms of computing time. Incidentally, if you had a level 10 screens wide, shouldn't the screen on top of screen 0 be screen 10?
[/quote]



Yes you are right. Just being stupid today.
One more question though should I draw only the sprites in the camera, or draw all the sprites in the screens my camera overlaps. Which would be faster?

I also must apologize that my thread is not in the right category. If a mod would move it that would be great.

Share this post


Link to post
Share on other sites
Hidden

[quote name='ILoveJesus' timestamp='1322901043' post='4890078']
Yeah I made like a SpriteScreen class which stores all the sprites that are in a screen. I made one vector to store all these classes and the index of the vector as the screen identifier. The bottom left of the level is screen 0. If I move one to the right it is screen 1. If my levels is 10 screens wide and 2 screens high, when I move up from screen 0, I move to screen 5. I figure every time I move I would have to check what screens I am in, and this also seems to be a lot of overhead. My question is, is this fast enough or is there a faster way?


Well, I would think that testing the camera position against the screens would only take 2 divisions, which is practically nothing in terms of computing time. Incidentally, if you had a level 10 screens wide, shouldn't the screen on top of screen 0 be screen 10?
[/quote]

Lol I see what are saying now. Yes you are right. My mind is so off today.

Share this post


Link to post

[quote name='RulerOfNothing' timestamp='1322901454' post='4890080']
[quote name='ILoveJesus' timestamp='1322901043' post='4890078']
Yeah I made like a SpriteScreen class which stores all the sprites that are in a screen. I made one vector to store all these classes and the index of the vector as the screen identifier. The bottom left of the level is screen 0. If I move one to the right it is screen 1. If my levels is 10 screens wide and 2 screens high, when I move up from screen 0, I move to screen 5. I figure every time I move I would have to check what screens I am in, and this also seems to be a lot of overhead. My question is, is this fast enough or is there a faster way?


Well, I would think that testing the camera position against the screens would only take 2 divisions, which is practically nothing in terms of computing time. Incidentally, if you had a level 10 screens wide, shouldn't the screen on top of screen 0 be screen 10?
[/quote]


One more question though should I draw only the sprites in the camera, or draw all the sprites in the screens my camera overlaps. Which would be faster?

[/quote]

Drawing all the sprites which your camera overlaps, but aren't visible, probably takes no time in the underlying graphics API, since they are not visible. But, honestly, I doubt you'll see a difference doing it either way.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!