Jump to content
  • Advertisement
Sign in to follow this  
stnal

Finding which sprite to draw in my game engine

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

Hi all,

I'm aware of similar threads that exists and discuss this topic but I'm looking into more personal replies since my game engine is implemented differently.

In my game engine I don't use tiles at all (the level editor has a grid though), any graphic can be of any size and positioned anywhere (I'm using a floating point game-unit abstraction), it works perfectly well.

Currently the rendering is performed like this:
- loop on all the layers starting from the one that is most farther back
-- loop on all assets in that layer
--- if the asset is in the view (see code below) than draw it to screen.



bool ScrolledAsset::isInRegion(float x, float y, float w, float h)
{
b2Vec2 sz = this->getAssetSize();

if ( ((mX-sz.x/2 > x+w) || (mX+sz.x/2 < x)) ||
((mY-sz.y/2 > y+h) || (mY+sz.y/2 < y)) ) {
return (false);
}

return (true);
}



Explanations -
* Parameters x,y,w,h is the region of the camera position in game units.
* mX, mY - the center position of the sprite.
* sz.x - it's width, sz.y - it's height
* The code basically tests whether the sprite extremities is outside of the display view and returns false, otherwise true

Optimizations Needed - don't loop on all sprites.
I thought about dividing the graphic assets container into multiple zones (the area of the sprite should also be taken into consideration). Is there conventional algorithm or data structure that you think I need to use?

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
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!