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

2016/3/30

Movement with Animation

Agent40 Agent40

2016/3/30

#
Ok, so what i am trying to do is make it so when my Actor moves from the keybinds w, a, s, or d the animation will switch between 3 different frames. Each direction has a different 3 frame animation. The problem that i am having right now with trying to get this to work, is that when i try and set the animation to the direction it doesn't work and i keep getting variable errors. I have tried lots of different ways to try and get this working but none seem to be working. If anyone could help that would be greatly Appreciated.
Super_Hippo Super_Hippo

2016/3/30

#
Show what you tried.
Agent40 Agent40

2016/3/30

#
So Right now I have just gone back to this,
public void act() 

    {
          if (Greenfoot.isKeyDown("d")) 
        {
            move(16);
      
        }
          else if (Greenfoot.isKeyDown("a"))
        {
            move(1);
        }
          else if (Greenfoot.isKeyDown("w"))
        {
            move(1);
            turn(90);
        }
          else if (Greenfoot.isKeyDown("s"))
        {
            move(1);
        }
     }   
with this
public GirlChar()
    {  
        image1 = new GreenfootImage("right1.png");
        image2 = new GreenfootImage("right2.png");
        image3 = new GreenfootImage ("right3.png");
        setImage(image1);
    }
    int timer = 0;
    private GreenfootImage image1;
    private GreenfootImage image2;
    private GreenfootImage image3;
and i have also looked at a lot of other posts and I tried this one but couldn't get it to work http://www.greenfoot.org/topics/2505/0
Super_Hippo Super_Hippo

2016/3/30

#
I don't know what kind of game this is that the movement would make sense like this... But in any way, you don't change the image anywhere after you set it to image1.
Agent40 Agent40

2016/3/30

#
Super_Hippo wrote...
I don't know what kind of game this is that the movement would make sense like this... But in any way, you don't change the image anywhere after you set it to image1.
what game don't you know that has movement like this? Right now i can name at least 10 but i will make 5. 1. pokemon 2. Final Fantasy 3. Undertale 4. super meatboy 5. Binding of Issac and if i want to add 1 more, 6. VVVVVV What i am trying to do with make it so that each direction has its own animation made up of 3 frames.... I can't figure it out so that is why I came here ;-;
danpost danpost

2016/3/31

#
I created a support class for animation. It is included and demonstrated in my downloadable Animation Suport Class scenario. Import the Animation class into your project and apply it to any Actor or World object you wish to have animated. It even shows how you can change the frames of an Actor from one set to another.
Agent40 Agent40

2016/3/31

#
danpost wrote...
I created a support class for animation. It is included and demonstrated in my downloadable Animation Suport Class scenario. Import the Animation class into your project and apply it to any Actor or World object you wish to have animated. It even shows how you can change the frames of an Actor from one set to another.
Thanks i'll try that out :)
Super_Hippo Super_Hippo

2016/3/31

#
Okay, I don't know any of these games. For any game i played in which is actor is controlled with WASD, it was either moving back and forth with W and S and turn with A and D (usually in first- or third-person view) or it was move up with W, right with D, down with S and left with A (usually in top-down view).
Agent40 Agent40

2016/4/1

#
Super_Hippo wrote...
Okay, I don't know any of these games. For any game i played in which is actor is controlled with WASD, it was either moving back and forth with W and S and turn with A and D (usually in first- or third-person view) or it was move up with W, right with D, down with S and left with A (usually in top-down view).
if you don't know any of those games.... i feel sorry for you and your childhood
Agent40 Agent40

2016/4/1

#
danpost wrote...
I created a support class for animation. It is included and demonstrated in my downloadable Animation Suport Class scenario. Import the Animation class into your project and apply it to any Actor or World object you wish to have animated. It even shows how you can change the frames of an Actor from one set to another.
how would i make it so that the 3 frames only activate when that button is held down?
danpost danpost

2016/4/1

#
Agent40 wrote...
how would i make it so that the 3 frames only activate when that button is held down?
The 'cycleCount' field in the AActor class creates that same type of behavior in my demo.
Agent40 Agent40

2016/4/2

#
danpost wrote...
Agent40 wrote...
how would i make it so that the 3 frames only activate when that button is held down?
The 'cycleCount' field in the AActor class creates that same type of behavior in my demo.
I have had a very long look at it all and i still can't understand it. Would you be able to give me an example of how to set up the images and then put them into the cycle for further reference?
danpost danpost

2016/4/2

#
You can put your images in an array (like I did in mine). You can even place these array inside another array (make a double array):
public static final GreenfootImage[][] images =
{
    {
        new GreenfootImage("right1.png");
        new GreenfootImage("right2.png");
        new GreenfootImage("right3.png");
    },
    {
        new GreenfootImage("down1.png");
        new GreenfootImage("down2.png");
        new GreenfootImage("down3.png");
    },
    // etc.
}
Then, when a change in keys is detected (or a change in direction facing), you can set the appropriate set of frames to the animation:
animation.setFrames(images[1]); // down images
You could even use the rotation, if you wanted:
animation.setFrames(images[getRotation()/90]);
You need to login to post a reply.