void SpriteManager::addSpriteToRenderList(AnimatedSprite *sprite, RenderList *renderList, Viewport *viewport) { // GET THE SPRITE TYPE INFO FOR THIS SPRITE AnimatedSpriteType *spriteType = sprite->getSpriteType(); PhysicalProperties *pp = sprite->getPhysicalProperties(); if (i >= 3) { b2Body* bods= sprite->getBody(); b2Vec2 position = bods->GetPosition(); pp->setX(position.x); pp->setY(position.y); } i+=1; // IS THE SPRITE VIEWABLE? if (viewport->areWorldCoordinatesInViewport( pp->getX(), pp->getY(), spriteType->getTextureWidth(), spriteType->getTextureHeight()) ) { // SINCE IT'S VIEWABLE, ADD IT TO THE RENDER LIST RenderItem itemToAdd; itemToAdd.id = sprite->getFrameIndex(); if (spriteType->getTextureWidth()==61) { renderList->addRenderItem( sprite->getCurrentImageID(), pp->round(X-viewport->getViewportX()), pp->round(Y-25-viewport->getViewportY()), pp->round(pp->getZ()), sprite->getAlpha(), spriteType->getTextureWidth(), spriteType->getTextureHeight()); } else { renderList->addRenderItem( sprite->getCurrentImageID(), pp->round(pp->getX()-viewport->getViewportX()), pp->round(pp->getY()-viewport->getViewportY()), pp->round(pp->getZ()), sprite->getAlpha(), spriteType->getTextureWidth(), spriteType->getTextureHeight()); } } }
/* addSpriteToRenderList - This method checks to see if the sprite parameter is inside the viewport. If it is, a RenderItem is generated for that sprite and it is added to the render list. */ void SpriteManager::addSpriteToRenderList(AnimatedSprite *sprite, RenderList *renderList, Viewport *viewport) { // GET THE SPRITE TYPE INFO FOR THIS SPRITE AnimatedSpriteType *spriteType = sprite->getSpriteType(); PhysicalProperties *pp = sprite->getPhysicalProperties(); float rotation = sprite->getRotationInRadians(); // IS THE SPRITE VIEWABLE? if (viewport->areWorldCoordinatesInViewport( pp->getX(), pp->getY(), spriteType->getTextureWidth(), spriteType->getTextureHeight())) { // SINCE IT'S VIEWABLE, ADD IT TO THE RENDER LIST RenderItem itemToAdd; itemToAdd.id = sprite->getFrameIndex(); renderList->addRenderItem( sprite->getCurrentImageID(), pp->round(pp->getX()-viewport->getViewportX()), pp->round(pp->getY()-viewport->getViewportY()), pp->round(pp->getZ()), sprite->getAlpha(), spriteType->getTextureWidth(), spriteType->getTextureHeight(), rotation); } }