I created a space where there is gravity and two objects:
var napeWorld:Space=new Space(new Vec2(0,500));
var ground:FlxNapeSprite = addBox(320, 480, 640, 20, BodyType.STATIC, FlxColor.BLUE);
var hero=addBox(320,60,20,20,BodyType.DYNAMIC, FlxColor.RED);
Here is my addBox()
function:
private function addBox(x:Float, y:Float, w:Float, h:Float,bodyType:BodyType, color:Int):FlxNapeSprite {
var sprite:FlxNapeSprite = new FlxNapeSprite(x, y);
sprite.makeGraphic(Math.ceil(w), Math.ceil(h), color);
sprite.body.type = bodyType;
sprite.body.space = napeWorld;
//sprite.createRectangularBody(w, h, bodyType);
sprite.setBodyMaterial();
add(sprite);
return sprite;
}
I call step in my update()
method:
override public function update():Void
{
super.update();
napeWorld.step(1/30);
}
I don't understand why my dynamic shape doesn't fall on the ground...
Any idea?
because you are setting it to be a static body with
BodyType.STATIC
.You need
BodyType.DYNAMIC
to make things move by themselves.