Hopefully this helps:
To get the time passed for this tick, use
ar dt = this.runtime.getDt(this.inst);
dt is the time, in seconds, that the physics simulation should advance. That should keep the speed steady no matter the framerate.
To get a callback when an instance is destroyed:
I just remembered there's already a function for this, because other parts of the runtime need it. Call
untime.addDestroyCallback(function(inst) { alert(inst.toString()); });
and it will alert the instance ID whenever something is destroyed.
To get a callback when an instance is moved or rotated:
There's nothing for this right now, but for the next build I've added a method for instances:
nstance.add_bbox_changed_callback(function(inst) { alert(inst.toString()); });
This will alert the instance ID whenever its bounding box is changed (x, y, width, height or angle is changed). Try to only add one callback and only for instances that really need it, because otherwise it'll add unnecessary overhead.
Hope that helps, let me know if there's anything else you need!
Thanks!
Yep, I already have that code. See the problem is, at least as far as I can see (it might be my logic, who knows) is that currently construct does logic inside the same thread as rendering. So this is what happens:
1. Engine renders the frame.
2. The instance triggers the behavior's tick (which at the moment is a bit hacky, I forgot to mention this, is there a way to have a behavior .tick callback rather than an instance .tick callback?) and every instance increments the behaviors ticking count. When the ticking count is equal to the amount of instances with the behavior, the box2d world steps.
3. As the gap between frames starts to get bigger, the delta between frames increases. Because I'm stepping the box2d world by this amount, it's stepping further in the physics world because the delta is larger.
You should add an onDestroy callback sometime as well. It'd be a lot more easier. But thanks for that anyway.
I'll be adding the callback to any instance with the rigidbody behavior. This is so I can move the body in the box2d world whenever you move the sprite's position by events, or rotate, etc.