This site requires JavaScript, please enable it in your browser!
Greenfoot back
FutureCoder
FutureCoder wrote ...

2017/4/13

putting an object over another

FutureCoder FutureCoder

2017/4/13

#
An object is added into a world but it is shown over the hero. is there code to display and object over another.
Super_Hippo Super_Hippo

2017/4/13

#
You can use the 'setPaintOrder' method in the world class. It takes classes as parameters and not objects though.
FutureCoder FutureCoder

2017/4/13

#
what code would i use?
Super_Hippo Super_Hippo

2017/4/13

#
1
setPaintOrder(ClassOnTop.class, ClassBelow.class);
Replace ClassOnTop with the class which should be on top of the other one.
FutureCoder FutureCoder

2017/4/13

#
thanks, but is there any code that can go in the class because in certain circumstances, i need one object to be under the other object, or over the other object
Super_Hippo Super_Hippo

2017/4/13

#
I think that if you use the following lines, the objects which executes it will be on top of the other one:
1
2
3
4
int x=getX(), y=getY();
World w = getWorld();
w.removeObject(this);
w.addObject(this, x, y);
Not sure if this works, but you could try it out.
FutureCoder FutureCoder

2017/4/13

#
thanks this works
You need to login to post a reply.