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

2020/12/4

How do I make it so that my actor is different sizes in certain worlds?

Ekrem64 Ekrem64

2020/12/4

#
public BossLevel() { super(525, 470, 1); addObject(new Main(), 470, 250); } I'm trying to make the main smaller in this world compared to other worlds where I want him normal sized
danpost danpost

2020/12/4

#
Use the addedToWorld method in the Main class and the instanceof operator to determine the type of world it is being placed in.
Ekrem64 Ekrem64

2020/12/4

#
Can you give me an example of how to write that?
danpost danpost

2020/12/4

#
Ekrem64 wrote...
Can you give me an example of how to write that?
protected void addedToWorld(World world)
{
    if (world instanceof BossLevel)
    {
        GreenfootImage img = getImage();
        img.scale(img.getWidth()/2, img.getHeight()/2);
        setImage(img);   
    }
}
Ekrem64 Ekrem64

2020/12/4

#
if (Greenfoot.isKeyDown("up")) { setLocation(getX() , getY() - 3); direction = 'u'; if(t.millisElapsed() > 100 && getImage() != two) { setImage(two); t.mark(); } else if (t.millisElapsed() > 100 && getImage() != one) { setImage(one); t.mark(); } } //To Move the Character right and change the image each time it takes //a step if (Greenfoot.isKeyDown("right")) { setLocation(getX() + 3, getY()); direction = 'r'; if(t.millisElapsed() > 100 && getImage() != six) { setImage(six); t.mark(); } else if (t.millisElapsed() > 100 && getImage() != five) { setImage(five); t.mark(); } } //To Move the Character left and change the image each time it takes //a step if (Greenfoot.isKeyDown("left")) { setLocation(getX() - 3, getY()); direction = 'l'; if(t.millisElapsed() > 100 && getImage() != eight) { setImage(eight); t.mark(); } else if (t.millisElapsed() > 100 && getImage() != seven) { setImage(seven); t.mark(); } } //To Move the Character Down and change the image each time it takes //a step if (Greenfoot.isKeyDown("down")) { setLocation(getX() , getY() + 3); direction = 'd'; if(t.millisElapsed() > 100 && getImage() != three) { setImage(three); t.mark(); } else if (t.millisElapsed() > 100 && getImage() != four) { setImage(four); t.mark(); } } It worked but I want to make it so that whenever he moves he's the same size. Now he's only small when he's looking down and not moving.
danpost danpost

2020/12/4

#
Scale all images in the addedToWorld method.
You need to login to post a reply.