网格节点位置未更新,在cocos3d中

时间:2013-05-23 09:26:43

标签: ios cocos3d

我正在Ball使用cocos3d开发棋盘游戏。我已经在touchevent给出了一个动作。我正在使用NSLog()将位置打印到控制台。

这是代码

-(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;
}

此处,'Ball'是MeshNode。它的位置来自cc3v(0.0, 0.0, 0.0)

当我跑步和触摸时,我发现球移动到指定位置。但我得到Ball的位置:

Location of x=0.000000 and y=0.000000

当我再次触摸时,我发现球没有移动(因为它已经移动到指定位置)。但随后它将Ball的位置显示为:

Location of x=0.000000 and y=-6.000000

为什么我第一次找不到位置?

1 个答案:

答案 0 :(得分:1)

根据你的代码,我认为问题是BounceAction1的执行持续时间为0.1,因此当执行NSLog语句时,Ball的静态属性尚未更新。要测试这个,请尝试在NSLog语句之前插入一个休眠。

相关问题