18
votes

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?

1
Because, initial position for the ball will be (0, 0)rptwsthi
Actually my problem is,after the movement also i get the position unchanged, ie get the starting position.Karan Alangat
Then you must be touching sub node of shader of your noderptwsthi
@joshbuhler Thanks for the edit, it s looks nice after that.Karan Alangat

1 Answers

1
votes

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.