避免"Physics 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调度器的下一帧才会运行.

相关文章
|
9月前
|
Oracle Java 关系型数据库
对Atmosphere中AtmosphereResourceImpl "Exception during suspend() operation"问题的追踪
在Atmosphere通信正常的情况下关闭浏览器,有时候会看到log出现一行Exception during suspend() operation的错误,虽然LOG是WARN的等级感觉应该不会有什么问题,但总觉得觉得应该有什么地方出了问题,为什么具体的错误行数被隐藏起来?
61 0
|
JSON fastjson 数据格式
报错:JSONException: illegal identifier : {pos 1, line 1, column 2{{"group":"trade_p0&qu
报错:JSONException: illegal identifier : {pos 1, line 1, column 2{{"group":"trade_p0&qu
463 0
|
Java
Can't convert boolean to string automatically, because the "boolean_format" setting was "true,false"
五月 11, 2017 5:06:50 下午 freemarker.log._JULLoggerFactory$JULLogger error 严重: Error executing FreeMarker template FreeMarker template error: Can't con...
2727 0
|
自然语言处理
合同结构化文书解析失败,请联系管理员排查:{"code":3001,"message":"File transform error","success":false,"tracerId":"requestId"}报错处理
在使用自然语言处理自学习平台时,标注任务需要上传标注数据,但是使用doc格式上传文件后开始标注时出现了此提示,此篇文章简单介绍下此问题的处理方式。
614 0
合同结构化文书解析失败,请联系管理员排查:{"code":3001,"message":"File transform error","success":false,"tracerId":"requestId"}报错处理
OPA 13 - ok(oButton,"find the Create button");
Created by Wang, Jerry, last modified on Nov 08, 2015
101 0
OPA 13 - ok(oButton,"find the Create button");
|
Java
Syntax error, insert "Dimensions" to complete TypeArgument
Syntax error, insert "Dimensions" to complete TypeArgument 语法错误,插入“维度”来完成类型参数 在定义 Map 的时候出现此错误,代码如下: [java] view plain copy Map
1089 0
|
Java Android开发
"XX cannot be resolved to a type "eclipse报错及解决说明
<p>转自:<a target="_blank" href="http://zhaoningbo.iteye.com/blog/1137215">http://zhaoningbo.iteye.com/blog/1137215</a></p> <p><span style="font-family:Helvetica,Tahoma,Arial,sans-serif; font-size:
1516 0