PDA

View Full Version : A modest question or two..



talon50
July 23rd, 2009, 07:07 PM
Hello, I'm just needing an answer or two for a few questions of mine. I'd appreciate any help you folks can throw my way. I'm using AS2 by the way.

Enemy AI.

I'm looking for some pretty simple AI, just enemy get after the player. (that is player directed with keys, not mouse). I came across the freeactionscript site but all they offered was, enemy approach mouse.

Animation.

I'm needing animations to change depending on what direction my player is facing, also animations for attacking or jumping..I understand to simply put the animations on the individual MC, but I'm having trouble with more than one animation. After hacking through a good few tutorials, is it possible to compress an entire animation to a single frame?

As I understand at the moment..If xkey is down then...goto specific MCs (framenumber). But unless I can stick an entire animation on a single frame I'm not really understanding how to preform this..

Also, this is pretty simple I'm sure but for some reason I havn't come across the answer yet. What would be the code on having a layer appear or vanish upon an event, say key press? something .visible I'm guessing?

Thanks in advance,
~Tally

flyingmonkey456
July 23rd, 2009, 07:15 PM
enemy ai:
you'll have to be more specific on this, are you using a tilebased engine? do they need to find their way around things?

animation:
is your game top down, or looking down at kind of an angle?
as for compressing an animation to a single frame, look into bitmapdata. i'm still learning it, but i know the basic idea. you would simply choose an area of the sprite sheet to draw onto the stage. you'll have to ask someone who know's it well about how to do that, though. TOdorus know's it very well, he'll probably find this thread in a few hours.

EDIT: i just reread your post, and i misread your question about compressing animations to a single frame. one way would be to have 8 frames, 1 for walking in each direction and 1 for standing facing each direction. on the frames for walking, you would have a movie clip that has the animation in it. you basically have an entire timeline within a single frame. alternatively, you can separate your timeline into 4 parts. each part would have the animation cycle for walking in a particular direction and on the last frame of that section, you would tell it to go back to the first. on the first frame, where the frame should appear to be standing, you would have code that determines whether the character is walking or not. then play if he is and stop if he isn't.

talon50
July 23rd, 2009, 07:23 PM
uh, simple over head view. No to going around things, just right at the player. Not tile based, heh if I wanted to limit myself to a grid I'd be on rpg maker. :P

flyingmonkey456
July 23rd, 2009, 07:27 PM
uh, simple over head view. No to going around things, just right at the player. Not tile based, heh if I wanted to limit myself to a grid I'd be on rpg maker. :P

okay, if it's overhead view you can completely ignore all of the bitmapdata and multiple frames stuff. have a walking animation in one direction in the characters frames. at the end tell it to loop back to the beginning, at the beginning have it find out if the character is walking or not. then change the rotation to change the character's direction. as for pathfinding, this one is very simple. just have the enemies constantly face the player and walk toward him if he is within their sight range. if you don't know atan, look at the tutorial linked at the bottom of this post. it shows how to point a gun at the mouse. the same code can be applied to make an enemy face the player.

http://www.flashninjaclan.com/tutorialpage.php?ID=47

and by the way, grids don't limit you as much as you would think. they actually open up a whole new world of possibilities. pathfinding, for one, can become incredibly easy. and if you use very small tiles, it's almost like it isn't even tilebased.

talon50
July 23rd, 2009, 07:37 PM
Thank you the link seems very helpful, I'm looking through it now.

Though I would also like to know a bit more about platform style, as this I am also working on. You mentioned dropping a movie clip on an individual mcs own timeline, How do I do that? I'm sure its something simple I'm over looking..

flyingmonkey456
July 23rd, 2009, 07:43 PM
Thank you the link seems very helpful, I'm looking through it now.

Though I would also like to know a bit more about platform style, as this I am also working on. You mentioned dropping a movie clip on an individual mcs own timeline, How do I do that? I'm sure its something simple I'm over looking..

just make an mc, double click it, select everything in it, and convert that to an mc. viola, an mc within an mc. then just go from frame to frame doing this until you're done :)

EDIT: btw, you can double click the inner mc to edit it's frames and add the animation in case you didn't figure that out ;)
you can also paste an mc inside of another mc.

talon50
July 23rd, 2009, 08:07 PM
ah! *facepalm duh..

we'll thanks ^^

TOdorus
July 25th, 2009, 10:50 PM
Enemy AI.

I'm looking for some pretty simple AI, just enemy get after the player. (that is player directed with keys, not mouse). I came across the freeactionscript site but all they offered was, enemy approach mouse.

You mean enemy approach point? The mouse basicly is a point with an x and a y position as is the enemy position. This means that you can use trig to calculate the new direction for the enemy. The same applies to the player: it can also be seen as a point.



var dX:Number = targetX - currentX
var dY:Number = targetY - currentY
var newHeading:Number = Math.atan2(dY,dX)


EDIT: tiles rock.

Marshmellow (http://home.planet.nl/~bogaa096/Marshmellow/TileTest.html)

arrows to move and space to jump.

c: fire
x: incendiary grenade
z: frag grenade