PDA

View Full Version : Hiya! Very Simple Help Needed For Actionscripting! (It's holding me back! =>_<=)



Drexegar
October 13th, 2004, 01:14 PM
Hiya Im making a game in flash. I produce a lot games in the past but never messed with a java-like script in flash. My problem is Im making my character walk but the problem is when he runs while your press the arrow key I don't know how to change the animation sequence when your not pressing the arrow key. So what im asking is I need to find a negate script (something that tells flash when this is not happenning is to do this) so I cant have my character go back to his netrual animation while he is not moving.

Here's my code:

onClipEvent(load){
moveSpeed=10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;this.gotoAndStop(3);
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;this.gotoAndStop(4);
}
}

first the character is a movie clip inside this movie clip are 4 frames one with a movie clip in each some the first two frames are netruel position and the next 2 frames are running positions so ok just look at the code in red. I put when key is down "right", Make character move and go to frame 3. the problem is now I dont have an script to negat the action so for flash to check when key is not pressed to go back to frame one.

This should be very easy to answer if anybody can help me to solve this all i can do is animation im not a very good proggammer but pretty much know how to make a game though. Thanx for your time for reading.

lostinbeta
October 13th, 2004, 01:26 PM
add on an else statement.

if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;this.gotoAndStop(3);
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;this.gotoAndStop(4);
} else {
this.gotoAndStop(1);
}


That says if neither the left or right keys are pressed, it will gotoAndStop at frame 1 (which I assume is your neutral state).

Drexegar
October 13th, 2004, 01:55 PM
OMG! thank you so much! but this is for both now so umm.. I need to know I want to make him flip so he runs the other way but i think if I put the action to scale x it would keep doign it and then hell strecth do ya have a script that when you press left to scale chacater like -100 then he'll face the other way but once? Heres the new script:

onClipEvent (enterFrame) {

if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;this.gotoAndStop(2);
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;this.gotoAndStop(2);
}else {
this.gotoAndStop(1);
}
}

Frame 1 is nbow netrual and frmae 2 is running yeah thanx alot man I glad to see my character running now I just need him to flip i did before but that was months ago >_< i forgot everthing!

lostinbeta
October 13th, 2004, 02:00 PM
The best solution I could think of here... is to make a copy of your frame 2 (which i am assuming contains a movieclip symbol of your character with a running animation) and take the movieclip symbol in the frame and flip that manually. So frame 1 would be default, frame 2 would be movieclip symbol with running right animation, and frame 3 would be movieclip symbol that is the same as in frame 2, but flipped the other way.

Then adjust your script as necessary.

Drexegar
October 13th, 2004, 02:07 PM
yeah thats what i did in the first place but then umm where can i put that little script you gave me so it wont work on both of them so i can use it twice? Im trying to figure it out but i keep getting syntax errors >_< But thanx for your help I will need to talk to you again to add your name in the "credits" section of my game and you cna see soem animations on my dev account!

http://drexegar.deviantart.com/

lostinbeta
October 13th, 2004, 02:28 PM
You would have one shell clip of the character.

On this clip you will right click and open the actions panel and have these actions
onClipEvent (load) {
stop();
moveSpeed = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
this.gotoAndStop(2);
} else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
this.gotoAndStop(3);
} else {
this.gotoAndStop(1);
}
}
Inside this clip you will have 3 frames. Frame 1 will contain the normal stance position. Frame 2 will contain the movieclip symbol with the running right animation. And frame 3 will be a duplicate of frame 2 (you can right click on frame 3 and choose 'insert keyframe' to make a direct copy of frame 2) with the character flipped around.

That is all that needs to be done, it should work fine from there.

Drexegar
October 13th, 2004, 06:52 PM
yes it does thanx a lot but the problem is that i would have to do a reverse frame for every animation then the file size will be to big later with other characters what i came up with i used a movie clip outside the character as a ghost to control the scaling or my character so now he flips and keep the animation the same thanx alot i will glady put ya on my credits list when the game is done. =^_^=

Dr Warm
October 14th, 2004, 04:03 AM
instead of doing the frame with the opposite movement, what i prefer (and many others) is to use _xscale *= -1; this makes it flip around in the x axis, you'll need to experiment with this a bit urself until u'll get it right. or alternatively have :
if(goingRight){
this._xscale = 100;
}
if(!goingRight){
this._xscale = -100;
}

Drexegar
October 14th, 2004, 09:07 AM
0_0 whoa thats cool too I will have to use that code for the AI probaly thanx so much =^_^=

Dr Warm
October 14th, 2004, 09:15 AM
well the idea is probably that u'll use it for both, if it'll cut down ur file size

Drexegar
October 14th, 2004, 09:24 AM
yeah but i already went to far on the ghost icons and yeha they did add a extra kb or 2 and now its just to complex >_< to go back and break it down plus my computer crahses every once and a while cause my friend switch the ram on a crappy e machine so I cnat take the chances but im very thankful for the code =^o^= though each peice gets me closer and closer to creating this game =^_^=