How is b2EdgeShape supposed to be used in Box2DFlashAS3 2.1a?
Searching the forum I found code samples (cpp, monkey) where edge shapes are used just like any other shape (circle, box), but I'm getting an error when I try to do the same with Flash.
Here is a quick copy-paste-run code to reproduce the error:
Runtime error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Box2D.Dynamics::b2Fixture/http://www.box2d.org/ns/b2internal::CreateProxy()[C:\Documents\...\src\Box2D\Dynamics\b2Fixture.as:316]
at Box2D.Dynamics::b2Body/CreateFixture()[C:\Documents\...\src\Box2D\Dynamics\b2Body.as:129]
at MainEdgeShape/createEdge()[C:\Documents\...\src\MainEdgeShape.as:32]
at MainEdgeShape()[C:\Documents\...\src\MainEdgeShape.as:16]
Line 316 of b2Fixture.as is:
Am I missing something?
Searching the forum I found code samples (cpp, monkey) where edge shapes are used just like any other shape (circle, box), but I'm getting an error when I try to do the same with Flash.
Here is a quick copy-paste-run code to reproduce the error:
Code: Select all
package
{
import Box2D.Collision.Shapes.*;
import Box2D.Common.Math.*;
import Box2D.Dynamics.*;
import flash.display.Sprite;
public class MainEdgeShape extends Sprite
{
private var _world:b2World;
public static var WORLD_SCALE:Number = 1 / 30;
public function MainEdgeShape()
{
_world = new b2World(new b2Vec2(0, 10.0), false);
createEdge();
}
private function createEdge():void
{
var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.position.Set(10 * WORLD_SCALE, 10 * WORLD_SCALE);
var edge:b2EdgeShape = new b2EdgeShape(new b2Vec2(50 * WORLD_SCALE, 50 * WORLD_SCALE), new b2Vec2(30 * WORLD_SCALE, 30 * WORLD_SCALE));
//var edge:b2CircleShape = new b2CircleShape(20 * WORLD_SCALE); // b2CircleShape compiles fine
var fixtureDef:b2FixtureDef = new b2FixtureDef();
fixtureDef.shape = edge;
fixtureDef.density = 1;
var body:b2Body = _world.CreateBody(bodyDef);
body.CreateFixture(fixtureDef);
}
}
}Runtime error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Box2D.Dynamics::b2Fixture/http://www.box2d.org/ns/b2internal::CreateProxy()[C:\Documents\...\src\Box2D\Dynamics\b2Fixture.as:316]
at Box2D.Dynamics::b2Body/CreateFixture()[C:\Documents\...\src\Box2D\Dynamics\b2Body.as:129]
at MainEdgeShape/createEdge()[C:\Documents\...\src\MainEdgeShape.as:32]
at MainEdgeShape()[C:\Documents\...\src\MainEdgeShape.as:16]
Line 316 of b2Fixture.as is:
Code: Select all
m_shape.ComputeAABB(m_aabb, xf);Am I missing something?