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

2017/4/7

Moving Plattforms

1
2
Fifilein Fifilein

2017/4/7

#
Hi! I am working on a Jump and Run game now. And I want to have moving plattforms. I already tried something and works , but just the half. I tried this Code : ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public class MovingGround extends Ground {     /**      * Act - do whatever the MovingGround wants to do. This method is called whenever      * the 'Act' or 'Run' button gets pressed in the environment.      */     public void act()     {         // Add your action code here.         BewegendePlattform(700, 200);         if(getX() <= minimumX) direction = 1;         if(getX() >= maximumX) direction = -1;        setLocation(getX() + direction, getY());     }     public void BewegendePlattform(int Xa, int Xb)     {      minimumX = Xa;      maximumX = Xb;      direction = 1;     } } Now it works like this: the Plattform is moving towards left and when it reached x = 200 it does not move anymore. Can you help me to fix it please? Thanks, Fifilein
Nosson1459 Nosson1459

2017/4/7

#
Can you show the full class code with code-tags. It can't be that you're showing the full class code now since I see no imports and no variables being initialized.
danpost danpost

2017/4/7

#
You have your maximum and minimum values reversed. Try:
BewegendePlattform(200, 700);
Fifilein Fifilein

2017/4/7

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MovingGround here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MovingGround extends Ground
{
    /**
     * Act - do whatever the MovingGround wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        BewegendePlattform(700, 200);
        if(getX() <= minimumX) direction = 1;
        if(getX() >= maximumX) direction = -1;
       setLocation(getX() + direction, getY());
    } 
    public void BewegendePlattform(int Xa, int Xb)
    {
     minimumX = Xa;
     maximumX = Xb;
     direction = 1;
    }
}
Nosson1459 Nosson1459

2017/4/7

#
What happened when you tried:
danpost wrote...
You have your maximum and minimum values reversed. Try:
BewegendePlattform(200, 700);
Fifilein Fifilein

2017/4/7

#
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.
Nosson1459 Nosson1459

2017/4/7

#
That's because the world is bounded. In your World subclass add in ', false' on the first line in the constructor (by super(..).
super(600, 400, 1, false);
Fifilein Fifilein

2017/4/7

#
You mean that?
super(800, 400, 1, false);
danpost danpost

2017/4/7

#
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.
Remove said like and replace your BewegendePlattform method with the following:
public BewegendePlattform()
{
    minimumX = 200;
    maximumX = 700;
    direction = 1;
}
Nosson1459 Nosson1459

2017/4/7

#
Fifilein wrote...
You mean that?
super(800, 400, 1, false);
No. That can't work, look at the World constructors World there isn't any for: public World(int worldWidth, int worldHeight, boolean bounded)
danpost danpost

2017/4/7

#
Nosson1459 wrote...
That's because the world is bounded.
This has nothing to do with the issue at hand.
Nosson1459 Nosson1459

2017/4/7

#
danpost wrote...
Nosson1459 wrote...
That's because the world is bounded.
This has nothing to do with the issue at hand.
If you say so but by me when actors stop by themselves at edges of worlds it's because of that.
danpost danpost

2017/4/7

#
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?
Fifilein Fifilein

2017/4/7

#
danpost wrote...
Remove said like and replace your BewegendePlattform method with the following:
public BewegendePlattform()
{
    minimumX = 200;
    maximumX = 700;
    direction = 1;
}
It still does the same.
danpost danpost

2017/4/7

#
danpost wrote...
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.
Remove said like and replace your BewegendePlattform method with the following:
public BewegendePlattform()
{
    minimumX = 200;
    maximumX = 700;
    direction = 1;
}
The bolded text should be 'line'.
There are more replies on the next page.
1
2