Destroy / detach object

Hello



If i create object > exemple boxes or something similar. Like in tutorial https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_physics (hello physics) => metod makeCannonBall() => i can creale a lot of balls…



My questions is:

  1. Killed enemy in games will lost after set time => Are this enemy object detached?

    1.1) This object after detached… > is he gone? (from merory) Because with makeCannonBall() metod i can crete thousand balls and i will need dispose of balls because they will soon or later fill memory to max. (if i will create another and another).
  • What i have to do for dispose of object?
  1. Can i target the created object wich collisions(ray,…)?



    thx
  1. What?

    1.1) normal java behavior, no reference means garbage. If you detach the object and remove the PhysicsObject from the PhysicsSpace (control.setEnbaled(false) or physicsSpace.remove(control)) and have no other reference to the object it will get garbage collected
  2. What?



    I suggest you do the tutorials once, they explain most of these things and how to do them.
1 Like

Sry for my english.


  1. / 2) > If i create object by makeCannonBall() => I select secound obj created by Picking => If i “destoy” this selected object > do i destoy every object created by makeCannonBall() metod? [ “1)” enemy can be created similar metod]



    thx for answer

as said, its all normal java behavior, I don’t know what you mean by “destroy”, there is no way to “destroy” an object…

THX

@stoupa said:
i can creale a lot of balls...


Words to live by

I do like that (for example you have Spatial “sp”):

[java]

// Spatial is created

Spatial sp = new Spatial(…);



//Spatial will be destroyed. But it will be destroyed if you have no reference objects.

sp.removeFromParant();

sp = null;



//if you really want to destroy

DesktopAssetManager.clearCache();



[/java]



I have no JMP right now… so some methods are not correctly written.

Also you need to remove your spatial from PhysicsSpace.

I have one more question…

I develop my first game (tetris).



What is faster/better action? >> create/remove box OR attach/detach box?

I have 2 ideas how create it. A) create matrix of boxes and show/hide them by attak/detach. B)create boxes, change them position and finally remove them after…“line of boxes”.

@mifth said:
...

THX

You can have all shapes of objects (for example 10 shapes) and then clone them.





[java]

// created shape

Spatial box = new Spatial(…);



// clone

Spatial box_001 = box.clone();

//or

Spatial box_001 = box.clone(false); //share material

[/java]

1 Like