AS3: StageWidth for BOX2D?
Posted
by
Gabriel Meono
on Game Development
See other posts from Game Development
or by Gabriel Meono
Published on 2011-11-27T20:10:25Z
Indexed on
2011/11/28
2:04 UTC
Read the original article
Hit count: 571
actionscript-3
|box2d
I know BOX2D uses meters, and AS3 uses pixels.
I'm trying to create objects which are limited to the stageWidth.
If I do this variable:
for (var i:int = 0; i<(stage.stageWidth); i++){...}
The animation will freeze, and this output appears:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Box2D.Collision::b2BroadPhase/CreateProxy()
at Box2D.Collision.Shapes::b2Shape/CreateProxy()
at Box2D.Dynamics::b2Body/CreateShape()
at com.actionsnippet.qbox.objects::CircleObject/build()
at com.actionsnippet.qbox::QuickObject/init()
at com.actionsnippet.qbox::QuickObject()
at com.actionsnippet.qbox.objects::CircleObject()
at com.actionsnippet.qbox::QuickBox2D/create()
at com.actionsnippet.qbox::QuickBox2D/addCircle()
at BOX2D_Test_Tutorial_fla::MainTimeline/frame1()
Does anyone know how to fix this?
Full Code:
[SWF(width = 350, height = 600, frameRate = 60)]
import com.actionsnippet.qbox.*;
var sim:QuickBox2D = new QuickBox2D(this);
sim.createStageWalls();
// make a heavy circle
sim.addCircle({x:3, y:3, radius:0.4, density:1});
// create a few platforms
// make pins
for (var i:int = 0; i<(stage.stageWidth); i++){
//End
sim.addCircle({x:1 + i * 1.5, y:18, radius:0.1, density:0});
sim.addCircle({x:2 + i * 1.5, y:17, radius:0.1, density:0});
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});
}
sim.start();
sim.mouseDrag();
© Game Development or respective owner