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

2018/3/20

Im trying to make my actor change when he turns:

Kushaal Kushaal

2018/3/20

#
I am making a maze game. I have 4 different actor classes of the same actor looking in different directions. I want to make it so that, when I hold the left arrow key, the actor would change to actor that is looking towards the left. And when I hold right, I essentially need the actor to change to the actor that looks to the right. Only one of the actors have been added to the world, the other three, that looks to the left, right and back are not added yet. Please tell me how to display another actor when I turn into the different directions... Let me know if you need to see any of my codes.
Vercility Vercility

2018/3/20

#
danpost danpost

2018/3/20

#
My suggestion is to use only one class for the actor and change the image depending on the arrow key pressed. Vercility, in a cryptic way, was suggesting this (by showing you the setImage method of the Actor class).
Vercility Vercility

2018/3/20

#
danpost wrote...
My suggestion is to use only one class for the actor and change the image depending on the arrow key pressed. Vercility, in a cryptic way, was suggesting this (by showing you the setImage method of the Actor class).
Uhhh, i assumed the question was how to make the actor look different, rather than adding a different actor tbh. My bad
Kushaal Kushaal

2018/3/21

#
Thanks guys... To clarify, I'm not supposed to add the other images as an actor? Using setImage will still let me display the other images when an arrow is pressed?
Kushaal Kushaal

2018/3/21

#
I used this code and it worked but, I need to change the size of the uploaded image Any ideas on how I can do this?
   if (Greenfoot.isKeyDown("left"))
       {
        GreenfootImage left = new GreenfootImage("mycharacterleft.png");setImage(left);
}
danpost danpost

2018/3/21

#
Kushaal wrote...
I used this code and it worked but, I need to change the size of the uploaded image Any ideas on how I can do this? << Code Omitted >>
int scalePerccent = 75; // 75% original size
left.scale(left.getWidth()*scalePercent/100, left.getHeight()*scalePercent/100);
Kushaal Kushaal

2018/3/21

#
Thanks a lot, the problem is solved... I just used this code and it worked out:
 GreenfootImage left = new GreenfootImage("mycharacterleft.png");setImage(left);
move(-4);
GreenfootImage image = getImage();  
image.scale(40, 50);
setImage(image);
You need to login to post a reply.