Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mesh node location not updated, in cocos3d

Tags:

ios

cocos3d

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?

like image 947
Karan Alangat Avatar asked May 23 '13 09:05

Karan Alangat


1 Answers

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.

like image 84
Morten Hornbech Avatar answered Nov 05 '22 04:11

Morten Hornbech