Using NAPE right

hi all,

as you can see, NAPE is what im looking to use. i had a look at the api, and like the look of it, looks a lot more understandable than box2d. whilst box2d is lovely, its too much for me. but NAPE is a nice option.
the only problem. is that i am just unable to get examples running. constant errors and anything that leads to me nearly getting it to work, it just doesnt.

does anyone have a basic example of nape written in openfl in action? just simple things really
i did also look at these links here, but even those are proving hard to get working as well. which is strange

many thanks

The examples on this page were really helpful for me:

First you have to set up a space:

var gravity = Vec2.weak(0, 600);
var space = new Space(gravity);

Then you create objects and assign them to the space:

var ball = new Body(BodyType.DYNAMIC);
ball.shapes.add(new Circle(50));
ball.position.setxy(50, h / 2);
ball.angularVel = 10; = space;

And in your game routine (EnterFrame handler or whatever) you need to update the space:

space.step(1 / stage.frameRate);

Then you need to keep track of the Body (in this example the ball) and set the ball’s graphic position to the ball’s Body position.

1 Like

aye i did try those samples first time round. but have never been able to get them working. i guess if its got all the other cack i dont need, then im bownd to get errors

ill have a poke again. just weird really :wink:


right. so i quickly worked on a, errr, quick example from what @iconic_stefan had said plus just tried to cut on just what i wanted, which is to work.
but trying it, it comes up with a starnge error message when running. it feel like its about to run, but just doesnt

the error that pops up is Uncaught exception - [email protected]_read
and i have no idea what that is but has popped up a few times in other physics based tests

so here is a quickie example. as basic as i could think of. but since im not getting a clear message as to what is wrong. say what line, i dont know what to do


import openfl.display.Sprite;

import nape.geom.Vec2;
import nape.phys.Body;
import nape.shape.Circle;
import nape.phys.BodyType;

class Main extends Sprite {
	var space:Space;
	public function new () {
		super ();
		addEventListener(Event.ADDED_TO_STAGE, init);

	public function init(event:Event):Void {
		removeEventListener(Event.ADDED_TO_STAGE, init);
		stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);

		var gravity = Vec2.weak(0,600);
		space = new Space(gravity);
	public function setupThings():Void {
		var ball = new Body(BodyType.DYNAMIC);
		ball.shapes.add(new Circle(60));
		ball.position.setxy(50, 50);
		ball.angularVel = 10; = space;

	public function onEnterFrame(event:Event):Void {
		space.step(1 / stage.frameRate);

Which target are you exporting to?

its to neko. but there seems to be a problem with nape talking, or it may be openfl. either way. it doesnt work with neko. which is damn annoying since its nice for quick project building. guess wait and see

Yes nape and neko don’t get along. Apparently neko has a class length limit, and nape has one class that its bigger, at least that what I heard.

aye, thats what i found after some minor digging. though said this was to be fxed, but that was back in march 2014.
urgh, i hope it gets fixed. actually i may just put in an issue request for it to be looked at. would prefer to use nape :wink:


WELL. thanks to @Gama11 and with his input on it gave me some really nice pointers and a resolve too it. so may as well post it here for future peeps :wink:

in your project.xml, plop these 2 lines in

<haxedef name="no-inline" />
<haxedef name="dce=full" />

that has seemed to of made things work on my end, and happily as well :wink:

thanks again :wink:

<haxedef name="no-inline" if="neko"/>

And when you want to benachmark or release, do

<haxedef name="NAPE_RELEASE_BUILD" if="release" />

(I’m not sure if the if=“release” is right, but I think)

AH HA HA HA HAAAA. i did not know that. very good to know.

many thanks :wink: