PDA

View Full Version : Character animation problem



Hangyoo
July 28th, 2009, 07:55 AM
He everybody,
this is my first threat in Kirupa forum so say hale-luja:)Anyway i am just learning actionscript 3,but thinked of making a flash game like Another World.I am sure everyon knows that.
The only thing what is problem for me that i made a Standing animation where the character just breathing ,and made another movieclip where the chaarcter is walking,and after i will make several other animations to but first i explain the problem.

So:
1 MovieClip - inside the movieClip there are two other.In separate frame.
standing
walking

I made Keyboard event for rightbutton.When keyboard is down ,it should gotoAndStop(2)
on frame 2. in the mothermovieClip where the two other is.But when i press the right button,it allways gotoAndStop(2).So the animation actualy doesnt start.Just Start from frame 1,and start again and again,you see that the caracter doesnt do anything just stand.

So my Question what is the best way to do a script wich is suitable for my problem.I know my english is not so good.But i fed up with boring caracters like ball or cube,where a movement dont have actualy animation,i want every movement to have separate animation.

And here is where you can help me.!!I hope my writing explained the situation .
I am looking forward to read your ideas about that.

:b:

SparK_BR
July 28th, 2009, 08:48 AM
well... there's a patter in the OO development called state machine (in portuguese at least):

the idea is simple, you hold your current state, each state have other states that it can change to in a list.
then you get the object and change the state when you need. BUT a state can't change to it-self.
you only change the animation when CHANGING states.
so you can control you animations
but they must be in the main movieclip not inside it. And then you put labels in the frames to make a goto without hard-coding the frame numbers.

got it? :)

(you can pm me if you want, but i only speak english and portuguese, and i can understand very little of spanish)

Hangyoo
July 28th, 2009, 09:17 AM
I write just a very basic thing .No x movement or other thing just an animation "start " "stop " control ,if you think about it.

var rightbutton:Boolean=false
var canwalk:Boolean=false

//lets call it box,in the box movieclip ther are to moveiclip on stand wich is on the first frame and a walk on the secon frame
box.

box.addEventListener(Event.ENTER_FRAME,movement)
function movement(e:Event){
if(rightbutton && canwalk){box.gotoAndStop(2)}}

//So here if you press rightbutton it goes to frame 2 but here on frame to the animation doesnt start.


stage.addEventListener(KeyboardEvent.KEY_DOWN,push )
function push(event:KeyboardEvent):void{
if(event.keyCode==39 || event.keyCode==68){
rightbutton=true;canwalk=true;
}
}

stage.addEventListener(KeyboardEvent.KEY_UP,releas e)
function release(event:KeyboardEvent):void{
if(event.keyCode==39 || event.keyCode==68){
rightbutton=false,canwalk=false,box.gotoAndStop(1)
}

}

Its not working here.

Hangyoo
July 28th, 2009, 01:37 PM
I am sure others have met this thing before.

Hangyoo
July 28th, 2009, 04:29 PM
http://www.mkworkshop.comuf.com/project_1.fla

Here it is.Only a character.The ideal would be if the character,would animate continously if i press the right button on the keyboard.But as you se its does nothing,when pushed continiously,if i release its start anymate.Sily girl:D

TOdorus
July 28th, 2009, 08:18 PM
The best way to go about this would be to use a movieClip inside a movieClip. You have two animations: "standing" and "walking". Create a movieClip with the standing animation and a movieClip with the walking animation. Then create a Walker movieClip, with the standing animation on frame 1 and the walking animation on frame 2. Now if you would use Walker.gotoAndStop(2) then it would move to the second frame, where the movieClip with the walking animation is located. The movieClip will automaticly start to run and loop (as you don't tell it to stop or do anything else).

Hangyoo
July 29th, 2009, 02:03 AM
The best way to go about this would be to use a movieClip inside a movieClip. You have two animations: "standing" and "walking". Create a movieClip with the standing animation and a movieClip with the walking animation. Then create a Walker movieClip, with the standing animation on frame 1 and the walking animation on frame 2. Now if you would use Walker.gotoAndStop(2) then it would move to the second frame, where the movieClip with the walking animation is located. The movieClip will automaticly start to run and loop (as you don't tell it to stop or do anything else).

Hm i will try this double movieCliping thing.I hope it will work.:)Thx the reply,
The first after Spark who actualy answer:)

Hangyoo
July 29th, 2009, 06:09 AM
Actually i tried it,doesnt work.i would greatly apreciate an example from someone....

TOdorus
July 29th, 2009, 08:51 AM
box.addEventListener(Event.ENTER_FRAME,movement)
function movement(e:Event){
var movementType:String
if(rightbutton && canwalk){
movementType = "WalkingRight"
}
if(leftbutton && canwalk){
movementType = "WalkingLeft"
}
if (box.currentFrameLabel !== movementType){
box.gotoAndStop(movementType)
}
}


Another way would be to use booleans (or an integer and constants for that matter) to define the state like Spark said. Actually, if you want to implement jumping without the player bieng able to move right or left in the air, you're probably going to need to use states. Google is your friend.

Hangyoo
July 29th, 2009, 09:23 AM
Thank you Todorus for the reply,actualy i tried to look for on the internet,but unfortunately my english is not so good,so i have some dificulty about that.I will try out what you coded here.




box.addEventListener(Event.ENTER_FRAME,movement)
function movement(e:Event){
var movementType:String
if(rightbutton && canwalk){
movementType = "WalkingRight"
}
if(leftbutton && canwalk){
movementType = "WalkingLeft"
}
if (box.currentFrameLabel !== movementType){
box.gotoAndStop(movementType)
}
}
Another way would be to use booleans (or an integer and constants for that matter) to define the state like Spark said. Actually, if you want to implement jumping without the player bieng able to move right or left in the air, you're probably going to need to use states. Google is your friend.

Hangyoo
July 29th, 2009, 09:47 AM
Check out this fla file please.

http://www.mkworkshop.comuf.com/project_1.fla

As you see if i press right -> arrow on keyboard it wants to change animation it goest its first frame("walk"),but doesnt continue,i want that if i push the -> arrow it would play the animation until i push my finger on the keyboard.

SparK_BR
July 29th, 2009, 12:57 PM
wazzup!

hmm... here i have made you something, without movieclip inside movieclip but with a animation manager code in hero's first frame ;)

and i used a megaman sprite sheet :megaman_classic: by nestea from angelfire.com

ignore my poor sliding code and the lack of jumping, i don't wanna make a whole game just to show you animation management. :to:

Hangyoo
July 29th, 2009, 02:40 PM
WAAAAAAAAAA.!!!!!!!:D:D:D THANK YOU!!!:p:p:p!!!!!!!!!!
Its great!!!!!!!I am very gratefull about that :)))
I will give back that favour once:PPP

Open a threat :D:D i ll solve you problem:D:hugegrin:




wazzup!

hmm... here i have made you something, without movieclip inside movieclip but with a animation manager code in hero's first frame ;)

and i used a megaman sprite sheet :megaman_classic: by nestea from angelfire.com

ignore my poor sliding code and the lack of jumping, i don't wanna make a whole game just to show you animation management. :to:

Hangyoo
July 29th, 2009, 05:57 PM
I will post source file if i did some advancements:)))

Hangyoo
August 5th, 2009, 09:54 AM
Here it is :)
http://www.mkworkshop.comuf.com/Life_Line.fla

With Sparks script.
I had some problem with multiple keypresses,i know its not the best solvation but later i will learn better technics i hope:)
you run with the direction and shift .jumping with direction and up arrow.
Nothing much,but it will be better:)

SparK_BR
August 5th, 2009, 11:00 AM
hmm you dont need to create a lot of "onTick" functions
simply change the "speed" when setting the animation, then each animation has it's speed
and reset the speed to default when you are standing...

flyingmonkey456
August 5th, 2009, 12:21 PM
this looks really good, but turning needs to be animated instead of instantly facing the opposite direction. if this were a small, simple sprite, what you have would be fine, but for something as big and realistic as this, it should have turning animations.

Hangyoo
August 5th, 2009, 12:47 PM
Hm.Thanks the advices guys. I will come up with something with your advices.

SparK_BR
August 5th, 2009, 12:58 PM
well... after a lot of ;;;;;;;;;;;;;;;;;; and lots and lots of refactoring and changing stuff...

here's a major bug fix of your game :thumb2:
i took the liberty to add the jump in the speed you were walking or running

PS: don't be afraid to edit my code, it's there for you to understand and change it :2c:

ps2: notice the "stand" is the second frame and not the first, it doesn't reset the values automatically, this way you can have a better control of your code and less bugs.

Hangyoo
August 5th, 2009, 01:14 PM
OO man:D!You made it really nice:)Checked what you // (commented).
Now its much more logical:)Sry for the ;-s:D:D

I will try to implement the turning animation.:)

flyingmonkey456
August 5th, 2009, 01:44 PM
another thing i noticed, if you let go of the jump button before you finish, it just stops and goes back to standing. you need to make animations finish before a new one can start :P
there's a thread on this somewhere, give me a minute to find it....

EDIT: here it is http://www.kirupa.com/forum/showthread.php?t=330454

Hangyoo
August 5th, 2009, 02:18 PM
Monkey you are right!
I will check what you linked, and try to fix this thing:)

Hangyoo
August 5th, 2009, 02:58 PM
Thinking about an inAir:Boolean .... when the up and direction booth true the inAir will be true and if its true the jump animation execute,what do you think about it?Its just by myself not about what you linked

flyingmonkey456
August 5th, 2009, 03:11 PM
that's what i always do, have a boolean for every action; running, jumping, standing, crouching, then one for each direction; left, right. before you execute any action, you check the booleans of every action to see if anything is already happening, even the same action. i use the left and right booleans because i always have my movement animation based on these booleans, but you probably don't need them.

EDIT: actually, i always use one integer and use the number to decide what action is happening (1 = standing, 2 = running, etc.) but it's the same basic principle. using an integer requires less coding and gets the same effect, but you have to remember what each number means.

Hangyoo
August 5th, 2009, 08:17 PM
Yes its ok.:)The only problem in the jumping part, that if you press direction and up arrow and release it the animation must continue ,not stop as you said.But its 1:14 now at night here in Hungary so i will care about that in the morning.

Maybe an ENTER_FRAME eventlistener with a function?
Couse its not the same as a running animation when the character stops when you release the keyboard.:)Anyway stay tuned ,i will come up with some crasy s**t today:D
For Sparks happynes too:D:D


that's what i always do, have a boolean for every action; running, jumping, standing, crouching, then one for each direction; left, right. before you execute any action, you check the booleans of every action to see if anything is already happening, even the same action. i use the left and right booleans because i always have my movement animation based on these booleans, but you probably don't need them.

EDIT: actually, i always use one integer and use the number to decide what action is happening (1 = standing, 2 = running, etc.) but it's the same basic principle. using an integer requires less coding and gets the same effect, but you have to remember what each number means.

Hangyoo
August 6th, 2009, 06:12 AM
Hahaaaa i made it Monkey:D

http://www.mkworkshop.comuf.com/Life_Line_updated.fla

Its much more better now!!:)The turning animation is still not exists but i will start it too after my driving traiing lesson:) Its 11:12 here so i still have time:)

flyingmonkey456
August 6th, 2009, 07:26 AM
the walking animation doesn't stop when you let go of the button. also, you can change directions in mid air. make sure you post the finished product here, i want to see it :P

Gnoll
August 6th, 2009, 07:39 AM
Looks great, only issues I see is the walking animation not stopping like flyingmonkey said, and if you press jump when you are stopped, and then start to walk it jumps.

Great art, :D
Gnoll

Hangyoo
August 6th, 2009, 07:56 AM
OOOO dear:D:D.....I ll make it:D

SparK_BR
August 6th, 2009, 11:22 PM
hmm... did you really made a boolean when you have the animation property???

use the animation propertie with the constraint, put all the actions in jump constrait, then when the jump finishes it will change to standing already...

all you needed to do is change
animRestrictions.jump = ["walk","crounch","run"];
to
animRestrictions.jump = ["walk","crounch","run","stand"];

edit:
forgot about the speed thing :D

put this BEFORE if(xSpeed <= 1){
so the code was like this:


if(Math.abs(xSpeed) <= 1){
xSpeed = 0;
}
and will get like this:


if(animation == "jump"){
xSpeed += (xSpeed/Math.abs(xSpeed))*this.accel;
}

if(Math.abs(xSpeed) <= 1){
xSpeed = 0;
}
then all your problems will be solved (ooohhh!)

edit2:
oops one more thing
in the jumpLeft and jumpRight there will be a line like:
this.xSpeed += accel;
and another like
this.xSpeed -= accel;
erase them... they are making double length jumps...

Hangyoo
August 8th, 2009, 06:53 AM
Good day to everybody!
Spark you advices worked perfectly:) I will integrate the turning animation and post the work here.

Hangyoo
August 9th, 2009, 03:36 PM
Hm...This turning thing is more difficult than i thought...

flyingmonkey456
August 9th, 2009, 05:53 PM
what's the problem?

SparK_BR
August 9th, 2009, 08:10 PM
hmm... make the animation to turn until hero is facing the screen, then make the animation backwards
to she looks back to the same direction
in the middle of the animation (when she's facing the screen), make the scale * -1;
and change the lines that say:
this.scaleX = Math.abs(this.scaleX);
to:


if(this.scaleX > 0){
this.animation = "turn";
return;
}


you must see if it's > 0 or < 0, just to check, if she's facing the wrong direction, turn around;
animRestrictions.turn = "walk, run, jump, stand";

in the end of the turn animation you set animation to stand
oh and btw, if jump thing and turn thing stop working and are freezing the animation or executing each other
just change the actions in the last frame from:
animation = "stand";
to


currentAnimation.frameLabel = "stand";
changeValues("stand");
gotoAndPlay(2);


and YES this is an override in the set animation method XD

HAVE FUN!

Hangyoo
August 10th, 2009, 03:55 AM
Hm.Actually what i did:
-made a complete animation about a turning. sequence in 180 degree.
-but now in the morning in the bed thinked of that why dont i do 2 separate walking animation what lets call walk other is turn_walk.When example at the start
if(right){this.animation=walk

}
if(!right){this.animation=turn_walk,}
or in the hero_mc put another keyboard listener for the key_up. and when left or right is release ,when it played the turn_walk,and released it becomes right=true,so next time if he wants to go to right,he wont get the turning animation.

But its just and idea,:D



hmm... make the animation to turn until hero is facing the screen, then make the animation backwards
to she looks back to the same direction
in the middle of the animation (when she's facing the screen), make the scale * -1;
and change the lines that say:
this.scaleX = Math.abs(this.scaleX);
to:


if(this.scaleX > 0){
this.animation = "turn";
return;
}


you must see if it's > 0 or < 0, just to check, if she's facing the wrong direction, turn around;
animRestrictions.turn = "walk, run, jump, stand";

in the end of the turn animation you set animation to stand
oh and btw, if jump thing and turn thing stop working and are freezing the animation or executing each other
just change the actions in the last frame from:
animation = "stand";
to


currentAnimation.frameLabel = "stand";
changeValues("stand");
gotoAndPlay(2);


and YES this is an override in the set animation method XD

HAVE FUN!

SparK_BR
August 11th, 2009, 03:12 AM
yeah you can use a var too, but checking the scaleX is always more accurate
cause it is what the player can see

Hangyoo
August 15th, 2009, 07:07 AM
Actualy i have some advancement.Ill link the file here.Its buggy but it wont be so much time to fix them:)Some animation problems too.

http://www.mkworkshop.comuf.com/turn.zip
Here it is!

Made a little terrain,just for start.:)I hope you like it

Hangyoo
August 15th, 2009, 01:32 PM
I am gona think out the main story line.
Thinked of making one that covers the followings:

-Earth quake catastrophy on the motorway
-Woman loses here doughter
-Doughter dessapears
-She wants to find here in the deserts

Something like that.
Thats why i made a rocky terrain.


Actualy i have some advancement.Ill link the file here.Its buggy but it wont be so much time to fix them:)Some animation problems too.

http://www.mkworkshop.comuf.com/turn.zip
Here it is!

Made a little terrain,just for start.:)I hope you like it

Hangyoo
August 16th, 2009, 04:39 PM
http://www.mkworkshop.comuf.com/turn.zip (http://www.mkworkshop.comuf.com/turn.zip)

Just made a second terrain if you go left.Is buggy,but just started.:))No gravity,etc,etc.:)
But Looks Soo Nice:)

Made a gravity for the second terrain,if you dont jump you fall into the hole.
I am gona try to make an animation that,do the following:

if you hit the side of the ground before you fall into the hole,the character would catch the ground,and try to get out of it ,trying to stand up.

If anybody has some idea,or refactorying plan,to make this thing better,please write down your ideas.

Hangyoo
August 19th, 2009, 03:32 PM
Made the jumpup movement.
I am very sad that nobody comment any of my Posts.This threat gona became a Diary or a journal:DOr a Twitter account:)))

Spark come back!:D

flyingmonkey456
August 19th, 2009, 09:43 PM
lol, i'm still here. it's looking good so far :)

SparK_BR
August 20th, 2009, 12:16 AM
I've never left
i'm just avoiding to look at your code so i can finish my zombie game XD

Hangyoo
August 20th, 2009, 11:31 AM
I am happy you like it:)
http://www.mkworkshop.comuf.com/turn.zip (http://www.mkworkshop.comuf.com/turn.zip)
Now you can climb up to the rock on the other scene on the left.
Its soo good:DMaybe my way looks so beginner,but it does the job:D

Hm Spark i wanted to show your game to my Brother,but i dont know the link for it:)
O Monkey is alive too:)))

Edit:
Corrected the problem with the Direction change.After you jumped to Left and the animation finished it went back to frame 1 where the left:Boolean was default false.So if you stoped jumped left.It became false,adn the turning animation to left started.But now its not couse put a direction() function.Wich check the ScaleX of the character.

function directions():void{
if(this.scaleX == Math.abs(this.scaleX)){right=true}
if(this.scaleX == -Math.abs(this.scaleX)){left=true}
}

Works cool i think:)

Hangyoo
August 24th, 2009, 03:23 PM
Made Some changes in the animation process.
Had a plan:
When the girl falling it plays falling animation and when it hits the ground its stands up from croutching.
It took me so much time to figure out how to do that.But made a not 100% but a great solvation.
I hope you find it ok.!

Here it is:
http://www.mkworkshop.comuf.com/turn.zip (http://www.mkworkshop.comuf.com/turn.zip)

Whats up Spark how is you zombee game going

SparK_BR
September 10th, 2009, 07:02 PM
sorry for taking so long, i was training harder this month
there will be a global parkour jam and i must be ready =D
just don't wanna look like a noob XD

http://www.2shared.com/file/7710571/f0a77c1b/ZombieHunter.html
here is the last build of the game, i hope your brother like it
(WARNING, THERE'S BLOOD ON IT!)

flyingmonkey456
September 10th, 2009, 07:46 PM
nice game, but you're using a 3d graphic effect with 2d physics. you can shoot something that is higher than you on the z axis by pointing you gun up. you should add a z range (spread). nice job on the super over powered shotgun, a zombie game wouldn't be complete without it. :P

TOdorus
September 13th, 2009, 07:36 PM
sorry for taking so long, i was training harder this month
there will be a global parkour jam and i must be ready =D
just don't wanna look like a noob XD

http://www.2shared.com/file/7710571/f0a77c1b/ZombieHunter.html
here is the last build of the game, i hope your brother like it
(WARNING, THERE'S BLOOD ON IT!)

Do you have a thread for that Spark? I'd like to give some feedback on it, without hijacking this one.

Gnoll
September 14th, 2009, 03:46 AM
Pretty nice Spark although I broke it... I used the shotgun and it looked like I killed myself! :) Then I disappeared and everything became undefined.

Gnoll

SparK_BR
September 16th, 2009, 12:39 AM
that happens from time to time when no object switches level with player, then player goes to no level...

but let's stop hijacking this thread i will repost it somewhere else