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

2016/5/12

Is it possible to have multiple gifs on a single actor?

Laurence Laurence

2016/5/12

#
I've been animating and gathering sounds for a fightable boss I have been planning very deeply. One thing has left me questioning and that is, can I have multiple gifs attached to one actor? So the boss will activate Boss_Smash01.gif then at another point will activate Boss_Combo02.gif? I do know how to set up gifs, it's just if I can set up multiple on a single actor. Thanks.
danpost danpost

2016/5/12

#
Laurence wrote...
can I have multiple gifs attached to one actor? So the boss will activate Boss_Smash01.gif then at another point will activate Boss_Combo02.gif? I do know how to set up gifs, it's just if I can set up multiple on a single actor.
I am quite sure it is possible to assign different gifs to an actor at different times. That is, the actor can retain multiple gifs and use any one of them at whatever time suits it. I cannot speak for the GifImage class, whether the gif is interchangeable or not; I do not think it is -- so you would have to create multiple GifImage objects, one for each animation the actor would use. If you already have the images separate (not in gif form), you could use my Animation class which is demonstrated and is downloadable. It supports multiple sets of animation images (this is also demonstrated). The scenario is called (what else) Animation Suport Class.
Laurence Laurence

2016/5/13

#
Could you give me an example code to implement multiple gifs on a single actor / object? I am currently using the gifimage class so I'm guessing my current plans are near-impossible with it so far.
danpost danpost

2016/5/13

#
First, you would list the set of images:
// class array
static GifImage[] animations = 
{
    new GifImage("standing.gif"),
    new GifImage("walking-right.gif"),
    new GifImage("walking-left.gif"),
    new GifImage("jumping.gif"),
    new GifImage("slash.gif"),
    new GifImage("lunge.gif")
    // etc. - whatever
};
You could (optional) add class fields to make referencing the animations more readable:
// class constant int fields
static final int STAND = 0, RIGHT = 1, LEFT = 2, JUMP = 3, SLASH = 4, LUNGE = 5;
Then, add an instance field to hold what GifImage object is currently being used:
// instance field
private GifImage activeGif;
and a method to assign an active animation:
private void setAnimation(int animationNum)
{
    activeGif = animations(animationNum);
}
Finally, you would have to control (this could get complicated) which animation set is being used depending on the different condition of the actor. Like, if a SLASH was being performed, you would not want another set to take over in the middle of the action. Maybe do something like once an animation that runs once (like SLASH or LUNGE) has completed, then set the animation set back to StAND immediately. Only let the first three animations set become active if the active animation is one of those three. You can use:
if (activeGif != SLASH && activeGif != LUNGE)
or this:
if (activeGif < 3)
for example to place a condition on setting one of the first three sets of animations active. Anyway, I believe the set-up as described above should do the trick.
Laurence Laurence

2016/5/13

#
I thank you immensely for helping me out with this. I do have a 'stand' animation at the end of all of the gifs that lasts 1.5 seconds to assure that transition from one motion to the next is different.
xerod xerod

2016/12/3

#
danpost wrote...
private void setAnimation(int animationNum)
{
    activeGif = animations(animationNum);
}
Finally, you would have to control (this could get complicated) which animation set is being used depending on the different condition of the actor. Like, if a SLASH was being performed, you would not want another set to take over in the middle of the action. Maybe do something like once an animation that runs once (like SLASH or LUNGE) has completed, then set the animation set back to StAND immediately. Only let the first three animations set become active if the active animation is one of those three. You can use:
if (activeGif != SLASH && activeGif != LUNGE)
or this:
if (activeGif < 3)
for example to place a condition on setting one of the first three sets of animations active. Anyway, I believe the set-up as described above should do the trick.
I'm still don't understand this code, do you mean:
private void setAnimation(int animationNum)
{
    activeGif = animations[animationNum];
}
because i got some error saying "Cannot find symbol" if using bracket instead of square bracket.
danpost danpost

2016/12/3

#
xerod wrote...
do you mean:
private void setAnimation(int animationNum)
{
    activeGif = animations[animationNum];
}
Yes -- sorry.
You need to login to post a reply.