Hey everyone,
I am using Dark GDK with Box 2d so I am basically pasting my sprites onto the physics boxes. Anyway I am trying to create a function that will warp my player to the mouse position.
Before I explain my problem here is my code:
When I debug this code and look at the Position.x and y they do change to the dbMouseX and Y values but when I check the function from Box2d
m_xf is still the same value. So how do I change that value to equal it to the mouse position? Or is there some other way that I can get the box2d box to my mouse position.
EDIT
Got it to work with the GetXForm function in box2d nevermind
I am using Dark GDK with Box 2d so I am basically pasting my sprites onto the physics boxes. Anyway I am trying to create a function that will warp my player to the mouse position.
Before I explain my problem here is my code:
Code:
void Character::Update()
{
////This is where I update the position for Box2d physics box. and then I paste the sprite to that position//////
Position = playerBody->GetPosition();
Position.x *= b2PixelRatio;
Position.y *= b2PixelRatio;
dbSprite(iD,Position.x,Position.y,2);
dbPasteSprite(iD,Position.x,Position.y);
/////////Move the character/////////
if ( checkLeft() )
{
playerBody->ApplyImpulse(b2Vec2(-5,0),b2Vec2(Position.x,Position.y));
}
if ( checkRight() )
{
playerBody->ApplyImpulse(b2Vec2(5,0),b2Vec2(Position.x,Position.y));
}
if ( checkUp() )
{
playerBody->ApplyImpulse(b2Vec2(0,-10),b2Vec2(Position.x,Position.y));
}
if (LeftMouseClicked())
{
Primary();
}
}
/////////this is my warp function. I am getting the value of the mouse and setting it to a float. I then take the position of the box2d and set it equal to the mouse position./////////////
void Character::Primary()
{
PlayerPositionX = dbMouseX();
PlayerPositionY = dbMouseY();
Position.x = PlayerPositionX;
Position.y = PlayerPositionY;
}
{
////This is where I update the position for Box2d physics box. and then I paste the sprite to that position//////
Position = playerBody->GetPosition();
Position.x *= b2PixelRatio;
Position.y *= b2PixelRatio;
dbSprite(iD,Position.x,Position.y,2);
dbPasteSprite(iD,Position.x,Position.y);
/////////Move the character/////////
if ( checkLeft() )
{
playerBody->ApplyImpulse(b2Vec2(-5,0),b2Vec2(Position.x,Position.y));
}
if ( checkRight() )
{
playerBody->ApplyImpulse(b2Vec2(5,0),b2Vec2(Position.x,Position.y));
}
if ( checkUp() )
{
playerBody->ApplyImpulse(b2Vec2(0,-10),b2Vec2(Position.x,Position.y));
}
if (LeftMouseClicked())
{
Primary();
}
}
/////////this is my warp function. I am getting the value of the mouse and setting it to a float. I then take the position of the box2d and set it equal to the mouse position./////////////
void Character::Primary()
{
PlayerPositionX = dbMouseX();
PlayerPositionY = dbMouseY();
Position.x = PlayerPositionX;
Position.y = PlayerPositionY;
}
When I debug this code and look at the Position.x and y they do change to the dbMouseX and Y values but when I check the function from Box2d
Code:
playerBody->GetPosition()
m_xf is still the same value. So how do I change that value to equal it to the mouse position? Or is there some other way that I can get the box2d box to my mouse position.
EDIT
Got it to work with the GetXForm function in box2d nevermind