I am new to box2d and I have a question. Suppose I throw a ball up(swipe).
Something like
md.bodyA = _groundBody;
md.bodyB = _body;
md.target = locationWorld;
md.collideConnected = true;
md.maxForce = 90.0f * _body->GetMass();
_mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);
_body->SetAwake(true);
Is there a way to determine when the ball is moving up and when it is moving down? Also, is there a way to update the z-value of a sprite when its in motion? I need this because I am trying to implement a basketball game.
I have set up the hoop back on z-value 1 and hoop front on z-value 3. The ball is on z-value 2.
When I throw the ball up, I want it to be on z-value 3. On z-value 2 it looks as though the ball is going up from inside the hoop. Also, when the ball is coming down, i want it to be on z-value 2 to simulate the ball coming from inside the hoop. So I want to know whats an easy way to determine if the ball is moving up and coming down and is it possible to change the z-values of sprites at runtime.
Something like
Code:
md.bodyA = _groundBody;
md.bodyB = _body;
md.target = locationWorld;
md.collideConnected = true;
md.maxForce = 90.0f * _body->GetMass();
_mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);
_body->SetAwake(true);
Is there a way to determine when the ball is moving up and when it is moving down? Also, is there a way to update the z-value of a sprite when its in motion? I need this because I am trying to implement a basketball game.
I have set up the hoop back on z-value 1 and hoop front on z-value 3. The ball is on z-value 2.
Code:
CCSprite *hoopback = [CCSprite spriteWithFile:@"hoopback.png"];
hoopback.position = ccp(170,240);
[self addChild:hoopback z:1];
CCSprite *hoopfront = [CCSprite spriteWithFile:@"hoopfront.png"];
hoopfront.position = ccp(170,240);
[self addChild:hoopfront z:3]
_ball = [CCSprite spriteWithFile:@"basketball.png" rect:CGRectMake(0, 0, 45, 45)];
_ball.position = ccp(120, 450);
[self addChild:_ball z:2];
hoopback.position = ccp(170,240);
[self addChild:hoopback z:1];
CCSprite *hoopfront = [CCSprite spriteWithFile:@"hoopfront.png"];
hoopfront.position = ccp(170,240);
[self addChild:hoopfront z:3]
_ball = [CCSprite spriteWithFile:@"basketball.png" rect:CGRectMake(0, 0, 45, 45)];
_ball.position = ccp(120, 450);
[self addChild:_ball z:2];
When I throw the ball up, I want it to be on z-value 3. On z-value 2 it looks as though the ball is going up from inside the hoop. Also, when the ball is coming down, i want it to be on z-value 2 to simulate the ball coming from inside the hoop. So I want to know whats an easy way to determine if the ball is moving up and coming down and is it possible to change the z-values of sprites at runtime.