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

2012/10/10

Floating platform

Stephon231 Stephon231

2012/10/10

#
what makes this platform know when to turn
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)


 
public class Platform extends Actor
{
    private int speed = 4;
    private int leftTurn = 270;
    private int rightTurn = 480;

 
     
    public void act() 
    {
        setLocation ( getX() + speed, getY() );
        
        Actor actor = getOneIntersectingObject(null);
        if(actor != null) {
            actor.setLocation ( actor.getX() + speed, actor.getY() );
        }
        
        if (atTurningPoint()) {
            speed = -speed;
        }
    }
    
   
    public boolean atTurningPoint()
    {
        return (getX() <= leftTurn || getX() >= rightTurn);
    }
}
SPower SPower

2012/10/10

#
Well, to turn an Actor, juse the turn method. But, where should it turn and how much?
Upupzealot Upupzealot

2012/10/10

#
the problem may be the “getX()” method actually return the position of the platform, not the“actor”
You need to login to post a reply.