Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Old 08-21-2008, 05:41 AM   #1
whitebabylon
Registered User
 
Join Date: Aug 2008
Posts: 13
Default [AS3] move a direction +picture change

Hi, I'm new here, and to flash/actionscript itself, and I was just wondering, when I use the Key.isdown to move my 'character' on the screen, how can I change pictures so that when I go Right my guys 'Symbol' changes to him facing that direction, so he's not always facing towards me, if I have other bitmaps of him facing other directions.
So far [CS3]:

onClipEvent(enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x--;
}
if (Key.isDown(Key.RIGHT)) {
_x++;
}
if (Key.isDown(Key.UP)) {
_y--;
}
if (Key.isDown(Key.DOWN)) {
_y++;
}
}



And any suggestions on a book that could teach me how to do 'everything' per-se, maybe not the easiest or best solutions, but the basics, you know?
whitebabylon is offline   Reply With Quote
Old 08-21-2008, 06:09 AM   #2
rawmantick
Pipty rupees only!
 
rawmantick's Avatar
 
Join Date: Jul 2007
Location: Родина Мать
Posts: 1,730
Default

Essential ActionScript 3.0
Avoid puting code in frames. Use code only in classes. It is a good practise.
__________________
Bang!
rawmantick is offline   Reply With Quote
Old 08-21-2008, 08:46 AM   #3
Jawnee
Registered User
 
Join Date: Aug 2008
Posts: 39
Default

I'm still a newbie myself but from my understanding one way to do this is to have your "character" be a movieclip with a series of labeled animation sections. For example in your character movieclip frame one is an image of the character facing left and you label that frame "faceLeft", frame two is an image of him facing right with a frame label of "faceRight", etc etc. You can even have a series of frames that denote certain animations and label the series as well.

Then on your main stage you would do something like this:

ActionScript Code:
onClipEvent(enterFrame) { if (Key.isDown(Key.LEFT)) { characterInstance.gotoAndPlay("faceLeft"); _x--; } if (Key.isDown(Key.RIGHT)) { _x++; characterInstance.gotoAndPlay("faceRight"); } if (Key.isDown(Key.UP)) { characterInstance.gotoAndPlay("faceUp"); _y--; } if (Key.isDown(Key.DOWN)) { characterInstance.gotoAndPlay("faceDown"); _y++; } }

That's the basic idea and I'm no expert on this yet but I'll try to find an example of this for you to look over if I get some time within the next day or so. Right now I'm buried in my own AS3.0 issues

Quote:
Originally Posted by romantique View Post
Essential ActionScript 3.0
Avoid puting code in frames. Use code only in classes. It is a good practise.
You can put code in frames BUT if you do ONLY put code in a single frame of a specific layer named "actionscript, action, or script" This way all of your code in the FLA is easily accessible and you don't have to sift through your entire project to find it. romantique is correct though, try to put as much of your code as you can into logical classes. This also helps organize your code into easily digestible / reusable chunks.

Last edited by Jawnee; 08-21-2008 at 08:48 AM.
Jawnee is offline   Reply With Quote
Old 08-21-2008, 08:28 PM   #4
whitebabylon
Registered User
 
Join Date: Aug 2008
Posts: 13
Default

I'm so confused. I have a layer named 'Guy' and in this layer is a frame of my guy at default position, when I click on the picture of my guy in the box where he is at, I choose action and place the code, is this the wrong spot? Now what happens is he moves when I press arrow keys, but when I add another keyframe, in the layer Guy, of his 2nd picture of animation for when you press down, I click test movie,a nd all it does is play the 2 frammed animation and nothing else happens?
I want to make him stand still when you launch the app, and when you press a key, for him to move and also play the 'takeing a step in that direction animation' and to change position graphics. I fail. Do i put all his positions in one layer? different frames? are they key frames? do I combine objects? are they suppose to all be movie clips or just one? and how should I name them, beucase if I name one frame FrameRight, but I want two frames in his right animation what do I name the 2nd frame? 'cuz when I name them both the same thing I get duplicate entry, should I be combing objects? :[
whitebabylon is offline   Reply With Quote
Old 08-21-2008, 09:06 PM   #5
Jawnee
Registered User
 
Join Date: Aug 2008
Posts: 39
Default

I'll try to do a better job of explaining what I mean.

EDIT: In rereading your last post whitebabylon I know this solution doesn't get you exactly where you need to be. I know you want to have a "moving left" animation (as well as other animations for the other directions) For now I just wanted to get you to the point where your "guy" at least faces the way he is moving. Then I can help you take the next step.

Ok let's go to frame 1 of your main timeline in the Guy layer:

Ok so your character or "guy" as you call him. Is he a movie clip? If he isn't select him and hit F8 to convert him into one. Call the movieclip guy. Ok so now on the stage on the Guy layer you have an instance of the guy movieclip. Click this movieclip once and go to the properties panel. Set the instance name to myCharacter.

You can now reference this character as a movieclip in actionscript (which we will need to do). He isn't ready yet though! Ok now look in your library, you should see a movieclip called guy which you just created. Double click the icon next to guy to open up the movie clip in the symbol editor. (this looks exactly the same as the editor for the main timeline) The way you'll know that you are editing a symbol can be seen in this screenshot of my current project. See where the cursor is and how it says Scene1 -> ButtonTravelLog. In this screenshot I am editing a movieclip symbol named ButtonTravelLog. Each movieclip you create in your library can have it's own timeline and animations independent of the main timeline... but to avoid confusing you and to keep it simple just know that to edit a movie clip you double click it's icon in the library and to get back to the main stage click Scene 1 (as show in the screenshot)



So in your case when you double click the movieclip named guy in the library your flash screen should say Scene 1 -> guy where the cursor is in my screenshot. Take a look at the screenshot again, see how I have an actions layer and notice how in the timeline there are the tiny words "in" and "out". These are frame labels. They allow you to reference specific animations within your movieclip from actionscript. So what you could do is have two layers. One called actions, one called guyAnimations. See this screenshot:



What you would do is create 4 keyframes for the actions layer and 4 keyframes for the guyAnimations layer. Once you have done that, in the actions layer click each new keyframe you created and then, as shown in the screenshot give each frame a meaningful label in the properties panel. I labeled the first one right, the second left, the third up, and the fourth down. Then in the guyAnimations layer you'll place a copy of the image that represents that direction. (Frame 1 = image of the guy facing right, Frame 2 = image of the guy facing left, etc) Once you've done that, save your project and click Scene 1 to go back to the main stage. Open up your actions panel where you have placed your actionscript code and do the following:

ActionScript Code:
onClipEvent(enterFrame) { if (Key.isDown(Key.LEFT)) {     _x--;     myCharacter.gotoAndStop("left"); } if (Key.isDown(Key.RIGHT)) {     _x++;     myCharacter.gotoAndStop("right"); } if (Key.isDown(Key.UP)) {     _y--;     myCharacter.gotoAndStop("up"); } if (Key.isDown(Key.DOWN)) {     _y++;     myCharacter.gotoAndStop("down"); } }

What this says is, when I press the left key, take the instance of my guy class on the stage which is called myCharacter and within that movieclip go to the frame labeled "left" and play JUST that frame. Since the guyAnimations layer within that movieclip AT that location shows the character facing left, that is the image that will be displayed. Does that make more sense?

NOTE: There is no actionscript code inside your guy movieclip just frame labels!
NOTE: In your main timeline for your fla be sure to ONLY put actionscript code in the first frame of a specific layer named actions, scripts, or something of that nature. Otherwise finding your code will be a real pain later!

Last edited by Jawnee; 08-21-2008 at 09:45 PM.
Jawnee is offline   Reply With Quote
Old 08-22-2008, 07:46 AM   #6
whitebabylon
Registered User
 
Join Date: Aug 2008
Posts: 13
Default

first off I'd just like to say, thanks man I really do appreciate you taking the time to help me, I'm about to go buy flash/actionscript for dummies, and see what I can do



basic run down:
in scene 1 I have layers animation, script, and Guy.
Guy contains the movieclip guy which is a picture of my 'guy', turned into a movie clip.
now the instance name is myCharacter in the properties tag. So i go over to movie clip guy, and I open the window you told me, where I placed 2 layers, guyAnimation and actions, inside guyAnimation I placed all images of my guy, and under each 'actions' I labled the instance name in the properties tag 'up down left right'. Then I placed the code
in your post, into the Scene 1, layer script, frame 1, which is the frame where my guy is, just in layer Guy. the animations layer is .. just there, i dont know why I made it yet. And I get the following error msg

1087: Syntax error: extra characters found after end of program.

my guy is shown, and it plays all the left up down right frames, I press to move a direction, it moves it but then resets his position after .5 seconds
But I dont know..
all images are GIFs imputed through the 'Bitmap - import thing.'
any ideas?
maybe I could email you the fla, or if you know what the problem is
whitebabylon is offline   Reply With Quote
Old 08-22-2008, 07:55 AM   #7
Jawnee
Registered User
 
Join Date: Aug 2008
Posts: 39
Default

Yeah zip up your .fla file and post the zip file as an attachment here in this thread. I'll gladly download it and take a look!
Jawnee is offline   Reply With Quote
Old 08-22-2008, 08:21 AM   #8
whitebabylon
Registered User
 
Join Date: Aug 2008
Posts: 13
Default

here he is
Attached Files
File Type: zip fighter.zip (8.5 KB, 210 views)
whitebabylon is offline   Reply With Quote
Old 08-22-2008, 11:19 AM   #9
Jawnee
Registered User
 
Join Date: Aug 2008
Posts: 39
Default

Quick question for clarity, you want to do this in actionscript 3.0 right? I'll have to get the updated code posted tomorrow but I'm working on it
Jawnee is offline   Reply With Quote
Old 08-22-2008, 10:18 PM   #10
whitebabylon
Registered User
 
Join Date: Aug 2008
Posts: 13
Default

yes actionscript 3.0 please
whitebabylon is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Zoom in, out and change x,y. porle Animation and Effects 7 10-26-2004 11:08 PM
Actionscript movement help needed! St. Nick ActionScript 1.0 (and below) 11 08-18-2003 04:37 PM
change direction on slashes flashdudette Server-Side Scripting 0 04-30-2003 03:51 PM
change direction via script sandman9 Simple Stuff (Newbies) 12 03-17-2003 08:42 PM
mc direction change defrex ActionScript 1.0 (and below) 2 07-15-2001 09:37 PM


All times are GMT. The time now is 09:20 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.