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

2019/4/26

how can I add selected actor in another world?

1
2
Tasya16 Tasya16

2019/4/27

#
1 2 3 if (getWorld() instanceof Level1) // or
1
2
3
if (getWorld() instanceof Level1)
// or
if (Level1.class.isInstance(getWorld()))
if (Level1.class.isInstance(getWorld()))
Tasya16 Tasya16

2019/4/27

#
Is it like that to check if the world is active ?
danpost danpost

2019/4/27

#
Tasya16 wrote...
Is it like that to check if the world is active ?
Of all the lines given, line 4 is the only one that I recognize as being a valid one. It does not check if a world is active, however. It checks the world that the actor is in for it to be of a specific type, regardless of the active state of that world. I am not aware of any method that tells you if a world is active or not by returning a boolean (true/false) value. Just the fact that its act method is automatically executed is enough to say it is the active world. Maybe you are confused about when a change in worlds takes place. Using setWorld does not instantly set the new world active. The current act call must still complete its course before the new world is actually set active.
Tasya16 Tasya16

2019/4/27

#
do you think i could use UserInfo to store the date of which character the user has chosen?
Tasya16 Tasya16

2019/4/27

#
danpost wrote...
Tasya16 wrote...
Is it like that to check if the world is active ?
Of all the lines given, line 4 is the only one that I recognize as being a valid one. It does not check if a world is active, however. It checks the world that the actor is in for it to be of a specific type, regardless of the active state of that world. I am not aware of any method that tells you if a world is active or not by returning a boolean (true/false) value. Just the fact that its act method is automatically executed is enough to say it is the active world. Maybe you are confused about when a change in worlds takes place. Using setWorld does not instantly set the new world active. The current act call must still complete its course before the new world is actually set active.
oh now I get it that's why It doesnt work..
Tasya16 Tasya16

2019/4/27

#
so how can I add actor in a new active world according to the act of actor in previous world? I am still so confused about that
Tasya16 Tasya16

2019/4/27

#
Tasya16 wrote...
do you think i could use UserInfo to store the date of which character the user has chosen?
I mean data not date
danpost danpost

2019/4/27

#
Tasya16 wrote...
so how can I add actor in a new active world according to the act of actor in previous world? I am still so confused about that
Like I said, you need to break that one line up so you create the new world on one line and set that world active on another:
World mainLoc = new MainLoc();
Greenfoot.setWorld(mainLoc);
The first line assigns the new world to a local variable, so that you can reference that world and add the actor to it.
Tasya16 Tasya16

2019/4/27

#
public class Karakter1 extends Actor { public void act() { if(Greenfoot.mouseClicked(this)){addedToWorld();} } public void addedToWorld() {World mainLoc = new MainLoc(); Greenfoot.setWorld(mainLoc); getWorld().addObject(new Vera(),100,450); } }
public class Karakter1 extends Actor
{
    
    public void act() 
    {     if(Greenfoot.mouseClicked(this)){addedToWorld();}
    
    }   
    public void addedToWorld()
    {World mainLoc = new MainLoc();
        Greenfoot.setWorld(mainLoc);
        getWorld().addObject(new Vera(),100,450);
    }
}
Tasya16 Tasya16

2019/4/27

#
i wrote that one but nothing happened
Tasya16 Tasya16

2019/4/27

#
it works now!!!! thank you so much danpost
Tasya16 Tasya16

2019/4/27

#
you are AWESOME
You need to login to post a reply.
1
2