Hey–
Sorry if I'm spam posting–I've just had a lot of free time so I've been able to get a bit of work done, but I also run into a lot of things I'm not sure how to fix.
So I am going to create an object, ProjectileBall, which extends Sphere. I need it to have a behavior such that when it has contacted another object 5 times, it removes itself from the scene graph. How should I write that behavior?
Also, I notice that objects that collide tend to lose a lot of energy (moreso than realistically, I think, but perhaps not). I was wondering if there's a way to override the physics engine on that and have objects never lose energy when they collide with something?
You can apply a very "bouncy" material.
Regarding that contact-triggered action have a look at the physics tutorials or in the interactive tests, there are examples of using the collision events (using InputHandlers).
There are many tests–do you recall any exactly?
http://code.google.com/p/jmephysics/source/browse/trunk/tutorial/com/jmetest/physicstut/Lesson8.java
Look for SyntheticButton.
One collision will produce many events tho (one event per physics step, as long as two objects intersect), so after playing a sound you need to set some kind of timeout. Or do something else to ensure you're not playing the same sound over and over again.
I think I'll just have them remove themselves after 5 seconds–that way if they escape the level (which they should not) they will be gone after 5 seconds.
Is removeFromParent(); sufficient to get rid of the object entirely, or will it be in memory still?
I added it in like this: newNode.attachChild(new Dodgeball(x, x, x, x));
ugh, i wonder why i talk about playing sounds … :?
sorry i'm tired need … sleeep …
i think its: physicsnode.setActive(false);
but I don't want to keep it around in memory, I want it gone for good.
i love that topic … sorry ://
dhdd said:
i love that topic ... sorry ://
Huh?! :|
Trussell said:
dhdd said:
i love that topic ... sorry ://
Huh?! :|
nevermind ;)
Trussell said:
but I don't want to keep it around in memory, I want it gone for good.
It'll be garbage collected if everything goes well (and if you remove it from the scene graph).
Okay. At this point, I have a Sphere connected to a DynamicPhysicsNode connected to my rootNode. When they need to be removed I decouple them completely (i.e. I remove the dynamic physics node from it's parent and also the sphere from it's parent) and just leave them–hopefully you're right and they go away. I haven't had any crashes because of it, so I guess we'll find out later in beta when I can sit down and play it for an hour or so.
Have a look at the garbage collections and you know now