我正在尝试制作一个简单的游戏,当球落入某个区域时,你就赢了。
力学:球落在几个障碍物上,最后有两个区块,如果球接触到你赢得的左侧区块,下一个级别将包含更多的区块和更少的空间。
测试电影(点击屏幕上掉球): http://gabrielmeono.com/downloads/Lucky_Hit_Alpha.swf
这些是主要变量:
var winBox:QuickObject;//You win
var looseBox:QuickObject;//You loose
var gameBall:QuickObject;//Ball dropped
问题
有时候,球会在其中一个障碍物中被击中并且不再移动。我可以从场景中杀死/删除此对象吗?
当前代码:
package {
import flash.display.MovieClip;
import com.actionsnippet.qbox.*;
import flash.events.MouseEvent;
import flash.events.Event;
[SWF(width = 600, height = 600, frameRate = 60)]
public class LuckyHit extends MovieClip {
public var sim:QuickBox2D;
var winBox:QuickObject;
var looseBox:QuickObject;
var gameBall:QuickObject;
var simContacts:QuickContacts;
/**
* Constructor
*/
public function LuckyHit()
{
sim = new QuickBox2D(this);
simContacts = sim.addContactListener();
simContacts.addEventListener(QuickContacts.ADD, contactListener);
//sim.createStageWalls();
winBox = sim.addBox({x:5,y:600/30, width:300/30, height:10/30, density:0});
looseBox = sim.addBox({x:15,y:600/30, width:300/30, height:10/30, density:0});
// make obstacles
for (var i:int = 0; i<(stage.stageWidth/50); i++){
//End
sim.addCircle({x:1 + i * 1.5, y:16, radius:0.1, density:0});
sim.addCircle({x:2 + i * 1.5, y:15, radius:0.1, density:0});
//Mid End
sim.addCircle({x:0 + i * 2, y:14, radius:0.1, density:0});
sim.addCircle({x:0 + i * 2, y:13, radius:0.1, density:0});
sim.addCircle({x:0 + i * 2, y:12, radius:0.1, density:0});
sim.addCircle({x:0 + i * 2, y:11, radius:0.1, density:0});
sim.addCircle({x:0 + i * 2, y:10, radius:0.1, density:0});
//Middle Start
sim.addCircle({x:0 + i * 1.5, y:09, radius:0.1, density:0});
sim.addCircle({x:1 + i * 1.5, y:08, radius:0.1, density:0});
sim.addCircle({x:0 + i * 1.5, y:07, radius:0.1, density:0});
sim.addCircle({x:1 + i * 1.5, y:06, radius:0.1, density:0});
}
sim.start();
stage.addEventListener(MouseEvent.CLICK, _clicked);
}
/**
* ..
* @param e MouseEvent.CLICK
*/
private function _clicked(e:MouseEvent)
{
gameBall = sim.addCircle({x:(mouseX/30), y:(1), radius:0.25, density:5});
}
private function contactListener(e:Event)
{
if (simContacts.isCurrentContact(winBox,gameBall))
{
// Won.
trace ('You won!');
}
}
}
}
答案 0 :(得分:0)
确保您已启用睡眠功能。当身体休息时,它会“睡觉”。您可以轮询您的身体,看看哪些正在睡觉。 这是关于Box2D.org概念的一个主题。 http://www.box2d.org/forum/viewtopic.php?f=9&t=5578
答案 1 :(得分:0)
我没有使用过quickbox2d,但它看起来像是box2d的一个很好的包装器。
我认为它应该允许访问box2D功能或box2d函数/属性,如Body's isSleeping,就像Plastic Sturgeon所提到的那样,你可以找到blog articles并且我已经用于{{{{ 3}}过去。