Destroy Physics Joint

For developers using the Construct 2 Javascript SDK

Post » Tue May 29, 2012 5:05 am

I modified the Physics plugin to add an action that destroys all Physics Joints. All is well until I get this error in the console, then it can't register any more joints as well as other weird behaviors.
Uncaught TypeError: Cannot read property 'm_collideConnected' of undefined
        Physics_behavior.js:6523
    Box2D.Dynamics.b2World.DestroyJoint
        Physics_behavior.js:6523
    behinstProto.destroyMyJoints
        Physics_behavior.js:12158
    acts.destroyMyJoints
        Physics_behavior.js:12685
    actionProto.run_object
        eveng.js:1020
    eventblockProto.run_actions_and_subevents
        eveng.js:502
    eventblockProto.run_orblocktrigger
        eveng.js:490
    runtimeProto.triggerOnSheetForTypeName
        eveng.js:1963
    runtimeProto.triggerOnSheet
        eveng.js:1857
    runtimeProto.trigger
        eveng.js:1821
    instanceProto.onKeyDown
        Keyboard_plugin.js:88
    (anonymous function)
        Keyboard_plugin.js:54
    f.event.dispatch
        jquery-1.7.1.min.js:3
    f.event.add.h.handle.i
        jquery-1.7.1.min.js:3


I added this code to edittime.js
AddAction(901, af_none, "Break joints", "Joints", "Break all {my} joints", "Break all physics joints on this object.", "destroyMyJoints");

And this code to runtime.js
acts.destroyMyJoints = function () {
     this.destroyMyJoints();
};


Here is the capx for the game the error occurred in.
http://dl.dropbox.com/u/52788071/frisbee.capx

The frisbee will "stick" to a pole when it hits it and spins around it until you either right-click or press space bar. You can control the frisbee while it's on a pole in any of three ways:
  • Click on the frisbee to push it.
  • Use the arrow keys to move it.
  • Hold down the left mouse button anywhere but the frisbee. A white ball will appear. Move the mouse to hit the frisbee with the ball. When you let go the ball will disappear.
Zephlon2012-05-29 05:11:39
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Tue May 29, 2012 1:39 pm

You're probably not breaking other instance's references to that object's joints. I'll see if I can add that action officially anyway so you don't need to hack the behavior yourself.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,590

Post » Tue May 29, 2012 3:54 pm

Hey @Ashley, would be possible to incorporate tags to joints when you create them to allow to selectively destroy them later?
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Tue May 29, 2012 4:27 pm

Yeah, that would allow finer control... I'll see what I can do...
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,590

Post » Tue May 29, 2012 5:09 pm

Thank you, @Ashely
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Sat May 24, 2014 9:36 pm

Sorry to necropost this suuuuuuuper old topoic :cry: . @ashley Do you think it's feasible to be able add tagging joints so we can destroy specific ones like mentioned above?

If not I can use the workaround mentioned in the physics manual page. Thanks!

[I saw this post when I was searching to see if this was possible. Which is why I necro'd rather than posting a new one]
B
37
S
9
G
7
Posts: 143
Reputation: 6,017


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests