how to make Moving Character correspond to the user key
Hi all,
Need some guilds so hopefully can get help. Well i have eight bitmap each show the character i draw out. i want to ask how the actionscript will be like in order to make the character correspond to the key, like when i press up it will show the character moving like up and change to left side which i had drawn when i press left key. I am new to flash so need more details. sorry for the trouble. Thanks for reading and really wish you guys can give some advise.
---
i press up it will show the character moving like up
---
1) put your bitmap within a movie clip - the movie clip is an object that you can control with ActionScript, a bitmap graphic symbol cannot be controlled by actionscript.
2) change a position on screen by setting new values to the _x (left right), _y (up down) movie clip properties.
on(keyPress "<Up>"){
cur_y = getProperty("target path to mc",_y); // get current y coordinate
offset = 5; // number of pixels to shift movie clip
new_y = cur_y - offset // new y coordinate, make smaller to go up
setProperty("target path to your movie clip",_y,new_y) // change _y property
}
on(keyPress "<Down>"){
cur_y = getProperty("target path to mc",_y);
offset = 5;
new_y = cur_y + offset // make larger to push down
setProperty("target path to your movie clip",_y,new_y)
}
3) you can use the _rotation property to rotate the mc. Flash rotates the mc around its registration point. This might also be useuful in your game.
---
change to left side which i had drawn when i press left key
---
4) you might try creating a mc with 8 frames, one for each bitmap (each bitmap in its own frame and at the same x,y position). Add a stop action in frame 1 to prevent the playhead from automatically playing through all 8 frames. Then on each user event, you can change the "face" of your character by moving the playhead to a specified frame. Give each frame a descriptive label in the properties inspector. Use gotoAndStop("label") to change the position of the playhead. It will play only the frame you specify and not move to any other frame.
on(keyPress "<Left>"){
// show bitmap in frame labeled "left side"
tellTarget("target path to movie clip"){gotoAndStop("left side");}
}
Thanks for your guides Hp3. But I still dont quite understand when i try it out the same problem will occur. I attach the file with my bitmaps on it, can you help me out? My code are used so that the character would be station within the screen and move to the next map. I am unsure if it is right or wrong, could you check it out for me?