motorollin
Member
CODE
bool onScreen( sprite* s)
{
if ( s->x < camera.x - s->w ) return false;
if ( s->x > camera.x + camera.w ) return false;
if ( s->y < camera.y - s->h ) return false;
if ( s->y > camera.y + camera.h ) return false;
return true;
}
if ( onScreen( enemy ) ) enemy.show();
...
In a scrolling game, is it worth using code like the example above to check whether a sprite is within the viewable area or not before drawing it, or would the checks take as much time as just drawing it whether it can be seen or not?
bool onScreen( sprite* s)
{
if ( s->x < camera.x - s->w ) return false;
if ( s->x > camera.x + camera.w ) return false;
if ( s->y < camera.y - s->h ) return false;
if ( s->y > camera.y + camera.h ) return false;
return true;
}
if ( onScreen( enemy ) ) enemy.show();
...
In a scrolling game, is it worth using code like the example above to check whether a sprite is within the viewable area or not before drawing it, or would the checks take as much time as just drawing it whether it can be seen or not?