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

2017/4/22

How to put a actor in front of a other??

Timon Timon

2017/4/22

#
I want that the "Mans.class" is in front of the "Objects.class", because ussully the "Objects.class" is before the "Mans.class" This is my Mans code. import greenfoot.*; public class Mans extends Actor { public int ySpeed; public int groundLevel=489; private boolean pressed; public void act() { boolean onGround = false; ySpeed++; setLocation(getX(), getY()+ySpeed); // at ground level if (getY() > groundLevel) { ySpeed = 0; setLocation(getX(), groundLevel); onGround = true; } // hitting box Actor object = getOneIntersectingObject(Objects.class); if (object != null) { int yDir = (int)Math.signum(ySpeed); setLocation(getX(), object.getY()-yDir*((object.getImage().getHeight()+getImage().getHeight())/2+1)); ySpeed = 0; if (yDir > 0) onGround = true; } // jumping if (onGround && Greenfoot.isKeyDown("up")) ySpeed = -15; // firing weapon if (pressed == Greenfoot.isKeyDown("space")) { pressed = !pressed; if (pressed) getWorld().addObject(new Weapons(), getX()+80, getY()-25); } //die if (this.isAtEdge()) { this.removeTouching(Objects.class); this.setImage("Death_Man.png"); this.setLocation(150, 520); Greenfoot.playSound("game-over.wav"); Greenfoot.stop(); //Here I want to put the "Mans.class" in front of the other Objects. } } }
Timon Timon

2017/4/22

#
Sorry
import greenfoot.*;
public class Mans extends Actor
{
    public int ySpeed;
    public int groundLevel=489;
    private boolean pressed;

    public void act()
    {
        boolean onGround = false;
        ySpeed++;
        setLocation(getX(), getY()+ySpeed);
        // at ground level
        if (getY() > groundLevel)
        {
            ySpeed = 0;
            setLocation(getX(), groundLevel);
            onGround = true;
        }
        // hitting box
        Actor object = getOneIntersectingObject(Objects.class);
        if (object != null)
        {
            int yDir = (int)Math.signum(ySpeed);
            setLocation(getX(), object.getY()-yDir*((object.getImage().getHeight()+getImage().getHeight())/2+1));
            ySpeed = 0;
            if (yDir > 0) onGround = true;
        }
        // jumping
        if (onGround && Greenfoot.isKeyDown("up")) ySpeed = -15; 
        // firing weapon       
        if (pressed == Greenfoot.isKeyDown("space"))
        {
            pressed = !pressed;
            if (pressed) getWorld().addObject(new Weapons(), getX()+80, getY()-25); 
        } 
        //die
        if (this.isAtEdge())
        {
            this.removeTouching(Objects.class);
            this.setImage("Death_Man.png");
            this.setLocation(150, 520);
            Greenfoot.playSound("game-over.wav");
            Greenfoot.stop();
            //Here I want to put the "Mans.class" in front of the other Objects.
        }

    }
}
Timon Timon

2017/4/22

#
So it is better.
Super_Hippo Super_Hippo

2017/4/22

#
Try to use the world's 'setPaintOrder' method. By the way, you can edit your last post instead of writing a new one.
Timon Timon

2017/4/22

#
What is the 'setPaintOrder' method?
Super_Hippo Super_Hippo

2017/4/22

#
Timon Timon

2017/4/22

#
Thanks.
You need to login to post a reply.