[Solved]Use an Object

hey monkey’s,

sorry that I have to ask again, but this problem isn’t solveable for me.

In my case I have some objects. With the help of the wiki and normen I know how to select them, how to animate them and how to control them and stuff like that.

For example i have some Boxes, which consists of a normale jME3.*.Box and my own property’s (i.e. life, rotatingspeed…). Now, I have for exmaple 20 of theses boxes, every box has at the begining 10 life points. When i click on one box the life should decrement (-1). In the case the box is running out of life points these should be removed or something like that. If I click another box the life should be decrement as well. When clicking on a box, which was alerdy one times clicked it should have less lifepoints.

So that is my problem and i dont know how to handle that :frowning:

My Idea was something like create an object which extends of spatial, but normen told me that this would be the wrong way. I looked in the MonkeyZone but I didn’t find usefull stuff for my situation

Hope, you are able to give me a tipp or something like that :frowning:

I think you might be looking for a custom control.

1 Like

I used custom control as well, but seems that is don’t work :frowning:

Edit: I dont know how to access the property’s may a little pseudo code example helps to understand what i mean


class player{

private int life;

public void setlife(int life){…}

public int getLife(){…}

//other stuff


class Control_Unit extends extends AbstractControl{

public void moveUnit(Vector bla){…} //works great

public decreaseLife(){

//reduce the life of my player :frowning:

// HERE IS my problem i believe




private Player test1;

private Player test2;

private Control_Unit mycontrol;

private Control_Unit mycontrol2;


//construct everything

//add control




//my acitonlistener

private ActionListener actionListener = new ActionListener() {


// fire ray and handle stuff

CollisionResult closest = result.getClosestCollision();

// clicked of an instance of player

// get Controll

mycontrol = new Control_Unit();

mycontrol = closest.getGeometry().getControl(Control_Unit.class);

if(mycontrol == null){

//get it bla bla bla


// now i want to reduce the life of these player

con.decreaseLife(); //MAY HERE IS A PROBLEM




In what way’s did it not work ? error log ? are you sure it doesn’t work, or perhaps were you just not using it properly?


Sorry, please look above there is an pseudo code example

ln:10 public decreaseLife(){

…you dont have a return type there, you need?..

public void decreaseLife(){

Thanks for help, but at the moment my decrease function is empty,

there is my problem. Of course is it void a return nothing :slight_smile:

I don’t know how to “build a connection” between the controll and the instance of the player. So that i can say reduce the life of this special unit.

May it could help if you are able to describe with few word how would you solve the problem, cause I believe it isn’t easy to understand what I want, because i wouldn’t understand my own :stuck_out_tongue:

Here a little summarize of my problem:

i have a few objects consists of various property’s for example lifepoints.

When i click on one of these objects i want to decrease these lifepoints.

Thank you for your help and your endurance :slight_smile:

You mean like this?

[java]boxSpatial.setUserData("health", 10);[/java]

when hit:

[java]boxSpatial.setUserData("health", boxSpatial.getUserData("health") - 1);

if(boxSpatial.getUserData("health") <= 0){



This is not exactly black magic…

1 Like


it’ damn easy :open_mouth: Normen has the force :smiley:

Why you don’t told me that last time, thank you :slight_smile:

Grüße von Berlin nach Bremen^^