8-direction Figure Animation with Arrow Keys

2019-07-13 00:25发布

I've been charged with designing a demo for an isometric video game in ActionScript 3. I have the bitmap spritesheets that show the avatar I'm using standing and walking in each direction. The walking animation is made up of three frames.

My problem, though, is that I need to figure out how to make use of them. I'm not familiar with animation in Flash, and I need input on how to gotoAndPlay() the walking frames for the right direction. I don't think isolating the necessary DIRECTION is going to be a challenge, so much as starting it and keeping it going while the arrow keys are down.

My current code is basically comprised of keyboard handlers for KEY_UP and KEY_DOWN, each containing a switch-case statement that changes the Avatar.currentDirection property. The handler continues to fire while the keys are down, but I need to add animation to the game.

I've seen some examples where they simply embed the animations into an SWF, propagate an array of the various walking stages, and alternate between them using an EnterFrame event handler, but this seems really clunky. I guess in the end I'm trying to make use of Adobe Animate, but I don't know how you're supposed to do that.

1条回答
聊天终结者
2楼-- · 2019-07-13 01:03

Ops, fortunately i'm working with sprites (atlas animations) right now!.

if i'm right, you just needs to use them for playing some animation with functionality.

if you have a well sized sprite which is tiled with isometric slots like it: (9 frames sized 64x128)

enter image description here

your work is very easy, only create new movieclip from library, inside it, create a borderless rectangle (which is our mask) in a layer (named mask) then import image to the project, and its better to disabling smooth ability from image properties,

enter image description here

now, inside your movieclip, you have to create new layer (under the mask layer) and add your sprite image for each frame, and change its position:

enter image description here enter image description here

at last, enable masking for mask layer, then its time of coding,

name your animation queries (like image 3) and for loopable animations, insert gotoAndPlay('anim_name') inside last frame. i hope you are familiar with controling movieclip animations which is basic consept of any flash project.

enter image description here

now to extend it for 8 directions support, you just need to play and switch between dirctions according single and multi keypreses,

查看更多
登录 后发表回答