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

2017/4/7

Moving Plattforms

1
2
danpost danpost

2017/4/7

#
Did you remove the following line from your code?
BewegendePlattform(200, 700);
Fifilein Fifilein

2017/4/7

#
Ops no, but when I tried it now it works like it should. Thank you! Is there a method for an actor to stay on the moving Plattform?
danpost danpost

2017/4/7

#
The code for that would need to be in the act method of the MovingGround classs (or a method that it calls). There should be a check for a player on it and that player must be considered to be on ground. If that is the case the platform should move the player in the direction it just moved by the same distance it moved.
Nosson1459 Nosson1459

2017/4/7

#
danpost wrote...
Nosson1459 wrote...
when actors stop by themselves at edges of worlds
Why did you assume this is what was happening? What lead you to think that?
Read:
Fifilein wrote...
danpost wrote...
You have your maximum and minimum values reversed. Try:
BewegendePlattform(200, 700);
When I tried it the plattform now moves right and when it is at the end of the world it just stops.
Here.
danpost danpost

2017/4/7

#
Nosson1459 wrote...
Fifilein wrote...
When I tried it the plattform now moves right and when it is at the end of the world it just stops.
I guess that was stated, sorry. However, I bet the platform was vibrating between 700 and 699 and was not actually at 799, which would be the end that particular world.
Nosson1459 Nosson1459

2017/4/7

#
So when 700 is set as the max it's so that the actor can't go past the end of the World even though it can't by default.
danpost danpost

2017/4/7

#
Nosson1459 wrote...
So when 700 is set as the max it's so that the actor can't go past the end of the World even though it can't by default.
The original code, after correcting the maximum and minimum values, had the actor moving right until 700 was reached, at which point the 'if' statement changed to direction to -1 to move left and the actor moved back to 699. The next act cycle the BewegendePlatform method was resetting the direction back to 1 and the platform would again move right to 700. This would therefore repeat 700, 699, 700, 699, etc.
Fifilein Fifilein

2017/4/8

#
danpost wrote...
There should be a check for a player on it and that player must be considered to be on ground. If that is the case the platform should move the player in the direction it just moved by the same distance it moved.
I tied this:
public void mitbewegen()
{
    minimumX = 200;
    maximumX = 700;
    direction = 1;
    if(aufBewegendePlattform())
    {
        if(getX() <= minimumX) direction = 1;
        if(getX() >= maximumX) direction = -1;
       setLocation(getX() + direction, getY());
    }
    else
    {
        Bewegen();
    }
    
}
When the platform moves right it all is working fine, but when it moves left my actor does not stay on the platform anymore? What did I do wrong?
danpost danpost

2017/4/8

#
It looks like you placed the code in the wrong class.
danpost wrote...
The code for that would need to be in the act method of the MovingGround classs (or a method that it calls).
The act method of the MovingPlatfform class should continue with a check for the actor on it, etc.
Fifilein Fifilein

2017/4/8

#
Can you give me an example ,please?
danpost danpost

2017/4/8

#
My Jump and Run Demo w/Moving Platform scenario has an example in it (run the scenario on site).
Fifilein Fifilein

2017/4/8

#
Thank you!
You need to login to post a reply.
1
2