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

2017/1/2

Passing an Actors location to the next World

Paswalt Paswalt

2017/1/2

#
First of all Happy new year to all of you guys! You've been helping me a lot and I would like to thank you all! However, there is this one last problem I can't really solve.... The situation is this: After a certain amount of time the game switches from the first level to the boss level. If the player is for example in the bottom left corner he gets teleported to the middle. I want him to stay where he was because I think it would look much smoother. I tried to pass a variable which saved his location to the next world but I didn't exactly know what to do.
danpost danpost

2017/1/2

#
Please show the transition code that gets the actor from the first level to the boss level as well as the boss level code.
Paswalt Paswalt

2017/1/2

#
Sadly my current transition is nothing more than a new Player() who gets created after the world changed because I have no clue seriously. I'm almost done with my school project this is the last thing that is missing :S Like: addObject(new Player(),x,y)
danpost danpost

2017/1/2

#
Paswalt wrote...
my current transition is nothing more than a new Player() who gets created after the world changed
Create your new world like so:
World world = new WorldClassName();
Actor player = (Actor)world.getObjects(Player.class).get(0);
player.setLocation(x, y);
Paswalt Paswalt

2017/1/2

#
Thank you for your answer but sorry I have to ask some things again. Maybe it's good to begin with our teacher. He wanted us to use "Frame-Based Editing"(http://www.greenfoot.org/frames/) wheryou have this cheat sheet and where you can drag and drop code for example. That's the reason I often can't help myself with your code. Sometimes I knew how I had to transfer it. I would use the normal thing like where you write everything on your own but he doesn't want it like that. If you have trouble with this Frame-Based Editing (i don't know why maybe it has some limitations?) just tell me and I will finish it without passing the actor.
danpost danpost

2017/1/2

#
Then, do not have the boss world add a player to its world. Just transfer the current player into that world:
var World world = new WorldClassName()
var int x = getX()
var int y = getY()
world.addObject(this, x, y)
Paswalt Paswalt

2017/1/8

#
The condition that changes the world is set in my first World. Do I simply need to add this to the player or do I have to put the whole setWorld thing + the code from above in my player class?
danpost danpost

2017/1/8

#
I did create the above as if the code was in the class of the player. But, if instead of 'this' on line 4, you reference your player object in the first World, you should be okay coding it in the first World.
// instance field
var Player player;

// in constructor
player = new Player();
addObject(player, << wherever >>);

// when going to boss World starting in line 2 above
var int x = player.getX();
var int y = player.getY();
world.addObject(player, x, y);
You need to login to post a reply.