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

2017/12/8

platform problem

razenoid razenoid

2017/12/8

#
i am trying to make a bunch of horizontal moving platforms that will have different turning points for each one the problem is the method i am using which is getX() + OR - 50 for the turn-points t but it keeps calling it so the turn-points are shifting constantly so they never reach them i know i cant put them in constants so i am confused on what to do
Yehuda Yehuda

2017/12/8

#
If you make your turning point a set distance from the Platform's current location, then the point moves with the Platform causing the Platform to either always or never be on the point. You have to make the point relative to the World not the Actor. P. S. I don't know what "getX() + OR - 50" is.
razenoid razenoid

2017/12/8

#
well i have a scrolling background meaning that things can actually go off the viewing screen and i used the + or - 50 is for my two locations of the turning points those being 50 to the left and right and making it relative to the world how would i do that since i will have a couple in the world so i am confused on what to do
razenoid razenoid

2017/12/8

#
public class GroundSideToSide extends Platform
{
    private int speed = 4;
    private int leftTurn;
    private int rightTurn;
    
   public void act() 
    {
        scroll();
        leftTurn = getX()-50;
        rightTurn = getX()+50;
        
        setLocation(getX()+speed,getY());
        if( atTurningPoint()) 
        {
            speed = -speed;
            move(speed);
        }
    }    

    public int getSpeed()
    {
        return speed;
    }

    public boolean atTurningPoint()
    {
        return (getX() <= leftTurn || getX() >= rightTurn);
    }
razenoid razenoid

2017/12/8

#
could you please explain that with a example or in simpler terms because that kinda confused me more than helping me
danpost danpost

2017/12/8

#
This will be a bit complicated, especially since there is scrolling involved. The turn around points need to be fields, not just local variables, so that their values are retained from one act step to the next. Then, they will need to be adjusted anytime horizontal scrolling is implemented. Finally, after moving, the location and direction need checked for each turn-around point to determine if the actor is to turn around.
You need to login to post a reply.