[PLUGIN] Zack0Wack0's Construct 2 Plugins

Post your completed addons to share with the community

Post » Sat Jul 09, 2011 1:08 pm

Zack0Wack0, you are officially a god amongst men.
B
55
S
12
G
8
Posts: 339
Reputation: 9,314

Post » Sat Jul 09, 2011 1:15 pm

@Zack0Wack0

Is your avatar a picture of you dressed as a dog ?

... definitely a little wacko
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Post » Sat Jul 09, 2011 2:58 pm

@Zack0Wacko, these are awesome. I'll get those changes in to the engine for the next build.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sat Jul 09, 2011 3:04 pm

Zack, you should be able to edit posts now. The new forum set it to 30 min limit, it's off now.
Image Image
Scirra Founder
B
125
S
37
G
25
Posts: 3,945
Reputation: 44,922

Post » Sat Jul 09, 2011 3:22 pm

Hopefully this helps:

To get the time passed for this tick, use
[quote]var dt = this.runtime.getDt(this.inst);[/quote]
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
[quote]runtime.addDestroyCallback(function(inst) { alert(inst.toString()); });[/quote]
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:
[quote]instance.add_bbox_changed_callback(function(inst) { alert(inst.toString()); });[/quote]
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!Tom2011-07-09 15:27:33
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sat Jul 09, 2011 4:53 pm

You know, this community happens to kick a lot of ass. This is amazing.
"Enter The Grump Monk"
B
12
S
4
G
5
Posts: 40
Reputation: 3,934

Post » Sun Jul 10, 2011 2:36 am

[QUOTE=Ashley] Hopefully this helps:

To get the time passed for this tick, use
[quote]var dt = this.runtime.getDt(this.inst);[/quote]
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
[quote]runtime.addDestroyCallback(function(inst) { alert(inst.toString()); });[/quote]
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:
[quote]instance.add_bbox_changed_callback(function(inst) { alert(inst.toString()); });[/quote]
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![/QUOTE]

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.
B
3
S
1
G
3
Posts: 49
Reputation: 1,148

Post » Sun Jul 10, 2011 2:01 pm

[QUOTE=Zack0Wack0]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.[/quote]
That sounds like the correct way to do it - you want to step the physics world further when more time has passed since the last tick. I guess there must be a bug in the way you handle ticks.

I remember having a similar problem with the Physics behavior in Classic: the world needs to be ticked once per tick no matter how many instances there are. The solution is to keep a tick count in the behavior of the last tick number that the world was ticked. runtime.tickcount in C2 gives you the number of ticks that have passed so far, so your tick code per instance is something like:

if (this.behavior.lastTicked < this.runtime.tickcount)
{
tickTheWorld(); // whatever function to advance the physics simulation
this.behavior.lastTicked = this.runtime.tickcount;
}

This way no matter how many instances you have, the entire behavior is only advanced once per tick. I bet it speeds up when you add more instances because more than one instance is advancing the physics.

[quote]You should add an onDestroy callback sometime as well. It'd be a lot more easier. But thanks for that anyway.[/quote]
Isn't that exactly what addDestroyCallback is? Or do you need something else?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Mon Jul 11, 2011 2:05 am

I mean there's onCreate functions on the instances so it'd make sense to have an onDestroy one as well.
B
3
S
1
G
3
Posts: 49
Reputation: 1,148

Post » Mon Jul 11, 2011 11:31 am

Ah, I see, I'll try and get that added too.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 2 guests