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

2019/10/28

Variable containing classes

JamesR JamesR

2019/10/28

#
I am looking for a way to make a variable contain multiple classes such as platforms or enemies. Like how a String can contain many sounds.
danpost danpost

2019/10/28

#
JamesR wrote...
I am looking for a way to make a variable contain multiple classes such as platforms or enemies. Like how a String can contain many sounds.
Please give an example of how a String can contain many sounds and be more specific on exactly what you want your variable to contain. "multiple classes such as platforms or enemies" is dubious. Is it the classes themselves or instances of those classes that are to be contained in the variable?
JamesR JamesR

2019/10/28

#
Actor GrassBlock =getOneObjectAtOffset(0,getImage().getHeight()/2, 
GrassBlock.class);
I want it so I can have 2 or more classes there if that helps explain it.
danpost danpost

2019/10/28

#
JamesR wrote...
<< Code Omitted >> I want it so I can have 2 or more classes there if that helps explain it.
So, you want:
java.util.List actors = getObjectsAtOffset(0, getImage().getHeight()/2, GrassBlock.class);
Btw, it is not "2 or more classes" -- it is "2 or more actors (or instances of a class)" .
You need to login to post a reply.