Yeah I guess dbSpriteWidth and Height are based off the function dbSprite() so I was calling that function in my main loop but I wasn't calling it above. The one thing about that then is it okay for me to call that function in two different places. I say this because of how things are initialized:
this is in my main loop:
///////////////////////////////// Static Object/////////////////////////////////
float32 angle = groundBody->GetAngle();
b2Vec2 position = groundBody->GetPosition();
position.x *= b2PixelRatio;
position.y *= b2PixelRatio;
angle *= (180.0 / 3.141592653589793238);
dbSprite(1,position.x,position.y,1);
//dbOffsetSprite(1, dbSpriteWidth(1)/2,dbSpriteHeight(1)/2);
dbPasteSprite(1,position.x,position.y);
dbRotateSprite(1, angle);
The position is initialized in this loop so in order for my sprite to have the same position as the 2d physics box I had to call dbSprite in this loop rather than up in the main entry point.
So is there any harm in calling that function in both places cause this is how I have it now:
// the main entry point for the application is this function
void DarkGDK ( void )
{
dbSetDisplayMode (960 ,720, 32);
dbSetWindowPosition(wPosX,wPosY);
//////Box2d World Set UP///////
b2AABB worldAABB;
worldAABB.lowerBound.Set(wPosX,wPosY);
worldAABB.upperBound.Set(dbScreenWidth()/b2PixelRatio, dbScreenHeight()/b2PixelRatio);
b2Vec2 gravity(0.0f, 9.0f);
bool doSleep = false;
b2World world(worldAABB, gravity, doSleep);
///////////////////////////////// Static Object/////////////////////////////////
dbLoadImage("ground.png",1);
dbSprite(1,0,0,1);
dbLoadImage("character.png",2);
dbSprite(2,0,0,2);
dbOffsetSprite(1, dbSpriteWidth(1)/2,dbSpriteHeight(1)/2);
dbOffsetSprite(2, dbSpriteWidth(2)/2,dbSpriteHeight(2)/2);
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(480 / b2PixelRatio,600 / b2PixelRatio);
b2Body* groundBody = world.CreateBody(&groundBodyDef);
b2PolygonDef groundShapeDef;
groundShapeDef.SetAsBox((dbSpriteWidth(1)/b2PixelRatio)/2.0f, (dbSpriteHeight(1)/b2PixelRatio)/2.0f);
groundBody->CreateShape(&groundShapeDef);
/////////////////////////////////Rigid Body///////////////////////////////////
b2BodyDef playerBodyDef;
playerBodyDef.position.Set(320 / b2PixelRatio, 100 / b2PixelRatio);
b2Body* playerBody = world.CreateBody(&playerBodyDef);
b2PolygonDef playerShapeDef;
playerShapeDef.SetAsBox((dbSpriteWidth(2)/b2PixelRatio)/2.0f, (dbSpriteHeight(2)/b2PixelRatio)/2.0f);
playerShapeDef.density = 1.0f;
playerShapeDef.friction = 0.3f;
playerBody->CreateShape(&playerShapeDef);
playerBody->SetMassFromShapes();
playerBody->CreateShape(&playerShapeDef);
dbOffsetSprite(2, dbSpriteWidth(2)/2,dbSpriteHeight(2)/2);
dbSyncOn ( );
dbSyncRate ( 60 );
while ( LoopGDK ( ) )
{
float32 timeStep = 1.0f / 60.0f;
int32 iterations = 10;
world.Step(timeStep, iterations);
///////////////////////////////// Static Object/////////////////////////////////
float32 angle = groundBody->GetAngle();
b2Vec2 position = groundBody->GetPosition();
position.x *= b2PixelRatio;
position.y *= b2PixelRatio;
angle *= (180.0 / 3.141592653589793238);
dbSprite(1,position.x,position.y,1);
//dbOffsetSprite(1, dbSpriteWidth(1)/2,dbSpriteHeight(1)/2);
dbPasteSprite(1,position.x,position.y);
dbRotateSprite(1, angle);
/////////////////////////////////Rigid Body///////////////////////////////////
float32 playerAngle = playerBody->GetAngle();
b2Vec2 playerPosition = playerBody->GetPosition();
playerPosition.x *= b2PixelRatio;
playerPosition.y *= b2PixelRatio;
playerAngle *= (180.0 / 3.141592653589793238);
dbSprite(2,playerPosition.x,playerPosition.y,2);
//dbOffsetSprite(2, dbSpriteWidth(2)/2,dbSpriteHeight(2)/2);
dbPasteSprite(2,playerPosition.x,playerPosition.y);
dbRotateSprite(2, playerAngle);
dbSync ( );
}
// return back to windows
return;
}
Is there a better way or am I just going to have to call it twice?