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

2020/8/13

How to get the currently running world

RcCookie RcCookie

2020/8/13

#
So I know Actor has a function getWorld() to get the world the actor is currently in, but is there a way to get the world that is currently being shown? There always has to be exactly one world shown, and I'm sure somewhere in the greenfoot framework there is a reference to it, but is there a way to get that?
danpost danpost

2020/8/13

#
RcCookie wrote...
is there a way to get the world that is currently being shown?
In general, the world whose act method, or whose actor's act methods, are being executed would be the active, or currently shown, world. If this is just a general question, then fine. If not, then more context is needed here -- explain exactly, in detail, what your issue is. And as usual, show some attempted codes with general scope to further illustrate what you are trying to do.
RcCookie RcCookie

2020/8/13

#
This is more of a general question, but I'm working on a raycast class. All its methods are static, but right now you somehow got to input the world in which to make the raycast in, for example by entering it directly or by inputing an actor and his world is being used. It would be very helpful to just enter a x and y coordinate and the raycast is done in the world that is currently running.
RcCookie RcCookie

2020/8/13

#
I thought of something like "Greenfoot.getActiveWorld()" --> return: World
danpost danpost

2020/8/13

#
This will work:
World w = (greenfoot.core.WorldHandler.getInstance()).getWorld();
Kostya20052011 Kostya20052011

2020/8/13

#
I don't quite understand the question, but if you need to pass some data to some world you can do it like this: World w=new World(); w.x=x; w.y=y; ...
RcCookie RcCookie

2020/8/13

#
danpost wrote...
This will work:
World w = (greenfoot.core.WorldHandler.getInstance()).getWorld();
Thanks that’s great!
RcCookie RcCookie

2020/8/13

#
Kostya20052011 wrote...
I don't quite understand the question, but if you need to pass some data to some world you can do it like this: World w=new World(); w.x=x; w.y=y; ...
That’s not quite what I was trying to achieve, I wanted to get the world that is currently being shown
Kostya20052011 Kostya20052011

2020/8/13

#
Again, I don't quite understand, but I think you've already found the answer ;)
You need to login to post a reply.