I am developing a board game using Ball
, in cocos3d
. In that I've given an action in touchevent
. I'm printing the location to the console using NSLog()
.
Here is the code
-(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {
CCActionInterval *BounceAction1=[CC3MoveTo actionWithDuration:0.1 moveTo:cc3v(0.0, -5.0, -0.7)];
switch (touchType) {
case kCCTouchBegan:
[Ball runAction:BounceAction1];
NSLog(@"Location of x=%f and y=%f", Ball.globalLocation.x, Ball.globalLocation.y );
break;
}
Here, 'Ball' is a MeshNode
. It's location is at origin cc3v(0.0, 0.0, 0.0)
.
When I run and touch, I find the ball moving to the specified position. But I get the Ball's location as:
Location of x=0.000000 and y=0.000000
When i touch again, i find the ball is not moving (as it has already moved to the specified location). But then it shows Ball's location as:
Location of x=0.000000 and y=-6.000000
Why I can't find the location the first time?
Based on your code I think the problem is that BounceAction1 executes with a duration of 0.1, and therefore the static property of Ball hasn't been updated when the NSLog statement executes. To test this try inserting a sleep just before the NSLog statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With