8-direction Figure Animation with Arrow Keys

倖福魔咒の 提交于 2019-12-12 19:52:32

问题


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:


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)

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,

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:

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.

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



来源:https://stackoverflow.com/questions/40824902/8-direction-figure-animation-with-arrow-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!