8-direction Figure Animation with Arrow Keys - actionscript-3

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.

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,

Related

AS3 Wheel of Fortune spinning

I'm working on wheel of fortune project but i'm currently struggling with the code.
I have attached the design of the wheel. I'm not a coder, i'm a designer and I need to do all the animation and the effects but I want to do it professional and that part is very important.
What I want to do is when you click on the spin button the wheel to rotate for 4-5 seconds with ease in/out effect and to stop each time on different random sector. Ill do different animations for each sector in separate movie clip and when it stops on a sector I want the movie clip related with that sector to start playing.
My idea is to make the wheel as a movie clip and each sector animation movie clips to be nested in it so when it stops that specific movie clip starts. Maybe I need to make each position of the wheel on key frame and to place the animations on these frames, but not sure if that is the right way.
One of the thing is that these movie clips with the effects should be easy for re position. I need to move them on the stage if needed and that's why i don't want them to be triggered with code.
If you can guide me step by step how to do that part I will appreciate your help. wheel design
Ok guys. There is a thread already for that and its something what I'm looking for. I like the example of the last answer in that thread, but I think that the first code will be more useful for my needs after that.
Can someone help me to make the code working, because I couldn't. All I need at the moment is to make the wheel spinning for 4-5 seconds on button pressed with ease in/out and it stops on random sector. Here is the link of the thread.
Spinning Wheel in flash AS3
I suggest you not to use keyframes at all. Use only one single frame, and in code, using a main class, instantiate all elements you need. To spin the wheel, you can consider using Greensock TweenMax or embedded tweening classes from Adobe. Also, spinning the entire wheel with all movieclips with nested animations inside, in spite animations are not running, forces to render all nested movieclips at each frame with a very heavy calculation load. I would suggest to either use 2 different clips, and add the animated one only when you need it, or at least to cache tentire wheel as a bitmap, and then uncache it when some animation is running inside.

AS3 Can you make a sidescroller camera?

I've seen in flash sidescrollers they mostly use sidescroller by making the background move.
But if I had a background and I wanted the player to move and the camera to follow, how would I do it?
There are several ways to accomplish this. The first is to put all of the background objects into a container MovieClip and move that instead of the player. This also makes other aspects of having a camera, such as zoom and rotation, relatively simple, since you can just scale and rotate the container MovieClip.
Another method is putting all background objects into an array. Every time there is movement, you loop through the array and move the objects. This requires more math and separate x/ y variables for each object, so it's not as convenient.
One thing to note is that if you're going to rotate the camera, you might experience vibration issues as your camera gets further away from the origin. To prevent this, you'll have to shift all of the objects in your container MovieClip closer to the origin when they get too far away.
If you want the camera to ease towards the player's position, you just move 1/10 (or some other fraction) of the distance to the camera's target position each frame.

AS3 - What are the different methods of rendering animation on the screen?

I'm a beginner to AS3 and programming in general, but have learned enough that I want to now start learning how to render animations on the screen. These are the methods that I know of from two days of "researching" on google.
I'm not in a situation where I could afford to take courses from an educational institution, so my only means of learning are through online sources.
Update an objects x or y positions in a loop on every frame. Very basic. Of course any kind of advanced animation (say, showing a character running) is not possible with this method alone.
Using Flash and creating animation on a movie clip's timeline and, combined with moving the position of the object we can achieve some proper animation this way. However I cannot afford Flash, so this is not an option available to me. It also doesn't seem to be a popular option among more experienced programmers either (I think, due to having poor performance when lots of objects animating on the screen?)
Using a sprite sheet and then blitting the relevant image from the sprite sheet onto the screen.
Is there any other way to put an image from a sprite sheet onto the screen other than blitting?
And what other methods of rendering animation are available?
Some online websites claim that blitting is all I'll ever need, but I want to know all the options available so I could choose the most appropriate one for any given situation.
Any help would be appreciated :)
Another option for blitting is Stage3D. Take a look at Starling for 2D animations.
Blitting would be my best opinion. The only other thing I can think of is manually taking the images from the sprite sheet and putting it into each frame of an animation.
To render animation, you can create a frame in a MovieClip and convert it into a MovieClip and name the frame 'running'. Then you need to create an Enter Frame event where the MovieClip's instance name is 'Guy' and in the code on the function write 'Guy.x += 5;' to make your MovieClip go 5 pixels to the right every frame and also in the function write "Guy.gotoAndStop('running');"
Use TweenMax engine for better animation purposes. Easy coding, more Animation!!

How to structure code/frames in Flash

I'm working on a Flash game where there are scenes that display a few stages of animation; the animation is controlled by user-clickable buttons (1 through 4) and a progress bar which increases by some amount with a timer.
Right now I have each stage of the animation on a different frame, but I'm not sure how to share the Actionscript and state (e.g. value of the progress var) across the frames.
Should I consolidate these frames into one and let each piece (the buttons, progress bar, and animation) all be three separate movie clips that are controlled by the actionscript of that frame? Or is there another way to do this properly?
What you said is probably the best solution in this case: put everything on one frame and control with ActionScript. The buttons can be their own MovieClips (or Buttons), the progress bar and animation as well. You can then have each stage of the animation on a different frame within the MovieClip, and control which frame appears when using gotoAndStop().
Generally I only use the base frames (i.e. those at the root of an SWF) as animation frames if the SWF is purely animation with no or minimal ActionScript involved. In any other case (games, applications, etc) it's always better to have animations in their own MovieClips, so that you can control and manipulate them easily.

Settings screen in Cocos2D game

How are settings screens created in Cocos2D games?
I've considered using a UIViewController subclass however pushing it in Cocos2D seems hacky. I've also considered using a CCLayer with buttons etc as child nodes. Then I could animate this layer in/out when appropriate. Is this the common way?
If you are using Cocos2D for your game, you should probably get in the habit of building your settings screens as Cocos2D scenes or layers, which offers the benefit of easily animating them into and out of the frame during your game. Adding a view controller is not necessary and actually complicates things when it is so easy to just create a CCScene or CCLayer.
I prefer the CCLayer approach, then I can animate the layer swooshing into the frame when a user presses a Settings button. The underlying game play is not erased since it is the same scene.
Another approach is to pop a settings scene onto the current scene.