It's a little hard to explain so I will just post code and explain what is going on.
Here is my character class's constructor:
Character::Character (int Xpos,int Ypos,float SpriteScale,char* FileName,int BoxID,int SpriteID,b2World* world,Camera* GameCamera)
{
m_posX = Xpos;
m_posY = Ypos;
m_SpriteID = SpriteID;
m_BoxID = BoxID;
m_scale = SpriteScale/100;
bIsAlive = true;
m_FilterID = 0x0002;
m_CanFlip =true;
m_HasFliped = false;
m_initialJump = -10;
m_maxJump = -5;
m_SpeedCap = 2.5;
m_turnm_speedCapRight = -5;
m_turnm_speedCapLeft = 5;
m_canJump = false;
m_isJumping = false;
m_tCheck = 0.0f;
m_bUseFire = false;
m_abilityID = 200;
m_FileName = FileName;
int checkx;
int checky;
g_eMovement = e_Idle;
dbCreateAnimatedSprite(m_BoxID,m_FileName,4,1,m_SpriteID);
dbSprite(m_BoxID,m_posX,m_posY,m_SpriteID);
m_SpriteWidth = dbSpriteWidth(m_BoxID);
m_SpriteHeight = dbSpriteHeight(m_BoxID);
ScaleSprite(GameCamera->m_ZoomValue);
dbOffsetSprite(m_BoxID,dbSpriteWidth(m_BoxID)/2,dbSpriteHeight(m_BoxID)/2);
p_bodyDef.userData = this;
p_bodyDef.position.Set(m_posX /b2PixelRatio, m_posY /b2PixelRatio);
p_bodyDef.fixedRotation = true;
p_body = world->CreateBody(&p_bodyDef);
checkx = dbSpriteWidth(m_BoxID);
checky = dbSpriteHeight(m_BoxID);
p_shapeDef.SetAsBox((dbSpriteWidth(m_BoxID)/b2PixelRatio)/2.0f, (dbSpriteHeight(m_BoxID)/b2PixelRatio)/2.0f);
p_shapeDef.density = 1.0f;
p_shapeDef.friction = 5.0f;
p_shapeDef.filter.categoryBits = m_FilterID;
p_body->CreateShape(&p_shapeDef);
p_body->SetMassFromShapes();
GameCamera->RenderList.push_back(this);
}
Now here is the update:
void Character::Update(b2World* world,Camera* GameCamera,CKeyboard* keyboard, CMouse* mouse)
{
if (bIsAlive)
{
m_angle = p_body->GetAngle();
m_position = p_body->GetPosition();///getting the bodies position in meters
m_position.x *= b2PixelRatio;///converting it to pixels
m_position.y *= b2PixelRatio;
m_angle *= (180.0 / 3.141592653589793238);
/*Make it so my position is based off my cameras position and the scale of the level*/
m_CurrentPos.x = (m_position.x - (GameCamera->GetPosition().x * GameCamera->m_ZoomValue)) + dbScreenWidth() / 2;
m_CurrentPos.y = (m_position.y - (GameCamera->GetPosition().y * GameCamera->m_ZoomValue)) + dbScreenHeight() / 2;
/*Update the sprite to its new position
and offset so that the position is based off the center of the sprite*/
dbCreateAnimatedSprite(m_BoxID,m_FileName,4,1,m_SpriteID);
dbSprite(m_BoxID,m_CurrentPos.x,m_CurrentPos.y,m_SpriteID);
ScaleSprite(GameCamera->m_ZoomValue);
dbOffsetSprite(m_BoxID,dbSpriteWidth(m_BoxID)/2,dbSpriteHeight(m_BoxID)/2);
dbRotateSprite(m_BoxID, m_angle);
Movement(keyboard, mouse);
Primary(keyboard, mouse,world,GameCamera);
Secondary(keyboard, mouse,world,GameCamera);
if( this->GetBody()->IsFrozen())
{
this->bIsAlive = false;
}
}
else
{
this->Delete(world,GameCamera);
}
}
Okay so I call the constructor to make my character and I scale it to the size that I want when I make the constructor like so:
Guy = new Character(SpawnPosX,SpawnPosY,15,"Images//Character.png",1,45,world,GameCamera);
Now I also have a 2d camera which allows me to scale all of my game objects at run time and have there collisions boxes change as well. So here is the problem. If I preset my scale amount before I run the game like this:
GameCamera->Zoom(0.5f);//1 being 100% scale 2 being 2 times the size and so on
so when I do this before the game is running my characters collision box is way off. Now the weird thing is when I preset the scale at 1 before I run the game the collision is fine and then if I scale it while the game is running my characters collision scales just fine. Now everything else in my game scales fine when I initially call scale except my character. Now I have stepped through my constructor and the value for the Checkx and checky are exactly what they need to be and I have even hard coded the numbers in for the collision box. I have no idea how in between my constructor and my update call my collision gets completely screwed up. I would post the actual project but it is big with the libraries that I am using so does anyone know how I can get it up if I need to.
Sorry for the lengthy post and I would appreciate any suggestions cause I am all out.