加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

避免"Physics Space Locked"错误

发布时间:2020-12-14 16:35:03 所属栏目:百科 来源:网络整理
导读:在一些cocos2d中使用物理引擎的代码中,往往会出现如下错误: Aborting due to Chipmunk error : You cannot manually reindex objects while the space is locked. Wait until the current query or step is complete.Failed condition: ! space -locked 该错

在一些cocos2d中使用物理引擎的代码中,往往会出现如下错误:

Aborting due to Chipmunk error: You cannot manually reindex objects while the space is locked. Wait until the current query or step is complete.Failed condition: !space->locked

该错误是一个著名的典型问题在大多数物理引擎中出现:在碰撞事件中,你不能修改物理世界(在Chipmunk中是space)中的特定部分.在这个例子中,播放动画将会修改节点的旋转因此旋转节点的物理对象.Chipmunk并不喜欢这样做,因为物理世界(space)被锁住了!意思是当前处理的物体需要连贯的状态,只有物理引擎自身允许修改它们的状态.(而不是在SpriteBuilder中用动画修改).

幸运的是我们可以快速简单的修正这个错误…见如下代码:

-(void)didTriggerWithNode:(CCNode *)activator{ [self scheduleBlock:^(CCTimer *timer){ [self.animationManager runAnimationsForSequenceNamed:_timelineName];
    } delay:0.0];
}

用0延时推迟调度一个block,直到Cocos2D调度器运行所有调度blocks的下一时刻中才会运行,至少它将会延时到Cocos2D调度器的下一帧才会运行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读