Talk:Mouse-Aim Tutorial (Flixel)

Animations
Wouldn't it be more effective to just create the FlxSprite from the graphic and then set its frame property? Currently, the tutorial tells you to create an animation for each angle, and each of those animations has only 1 frame. This is redundant, since setting the FlxSprite.frame property will display that frame and pause any playing animations, so it'll save you a lot of work. -- ChevyRay


 * I hadn't even considered using that, partly due to inexperience (it wasn't the solution to come to mind), but also because the concept behind using animations was to allow actual animated sprites that changed as they rotated. Thus it was created with the end-user in mind to enable easier changing of the image, adding the correct frames, and animating as desired. In fact, if you read the section below, you'll notice I had to make a change to Flixel to create smooth transitions between the animations. I haven't uploaded the update because it would be incompatible with "normal" Flixel, but I'll post it here if you'd like. It does use multi-frame animations though.


 * Your suggestion, however, definitely has merit. It has the advantage of being able to do more than just rotate a sprite, without the heavy initial setup if not doing actual animations.


 * It'll be something to add to the tutorial. If you see a good spot, feel fee to edit. If not, I'll look at making the change myself when I have time to sit and edit. Thanks for the input! Hectate 06:21, 11 July 2010 (UTC)


 * Here's the code in the unreleased animated version.



addAnimation("0", [0, 16, 32, 48, 64, 80, 96, 112, 96, 80, 64, 48, 32, 16], 30, true); addAnimation("1", [1, 17, 33, 49, 65, 81, 97, 113, 97, 81, 65, 49, 33, 17], 30, true); addAnimation("2", [2, 18, 34, 50, 66, 82, 98, 114, 98, 82, 66, 50, 34, 18], 30, true); addAnimation("3", [3, 19, 35, 51, 67, 83, 99, 115, 99, 83, 67, 51, 35, 19], 30, true); addAnimation("4", [4, 20, 36, 52, 68, 84, 100, 116, 100, 84, 68, 52, 36, 20], 30, true); addAnimation("5", [5, 21, 37, 53, 69, 85, 101, 117, 101, 85, 69, 53, 37, 21], 30, true); addAnimation("6", [6, 22, 38, 54, 70, 86, 102, 118, 102, 86, 70, 54, 38, 22], 30, true); addAnimation("7", [7, 23, 39, 55, 71, 87, 103, 119, 103, 87, 71, 55, 39, 23], 30, true); addAnimation("8", [8, 24, 40, 56, 72, 88, 104, 120, 104, 88, 72, 56, 40, 24], 30, true); addAnimation("9", [9, 25, 41, 57, 73, 89, 105, 121, 105, 89, 73, 57, 41, 25], 30, true); addAnimation("10", [10, 26, 42, 58, 74, 90, 106, 122, 106, 90, 74, 58, 42, 26], 30, true); addAnimation("11", [11, 27, 43, 59, 75, 91, 107, 123, 107, 91, 75, 59, 43, 27], 30, true); addAnimation("12", [12, 28, 44, 60, 76, 92, 108, 124, 108, 92, 76, 60, 44, 28], 30, true); addAnimation("13", [13, 29, 45, 61, 77, 93, 109, 125, 109, 93, 77, 61, 45, 29], 30, true); addAnimation("14", [14, 30, 46, 62, 78, 94, 110, 126, 110, 94, 78, 62, 46, 30], 30, true); addAnimation("15", [15, 31, 47, 63, 79, 95, 111, 127, 111, 95, 79, 63, 47, 31], 30, true);

And the image itself...



Note that I used the "playFromFrame" function below to get this to work properly. I uploaded the new .swf to show how it works. http://flashgamedojo.com/u/chqkv6/ --Hectate 15:42, 11 July 2010 (UTC)

Animated Rotations Issue
Currently, all animations start playing at frame zero (0). Since the angle of rotation changes frequently throughout gameplay, the beginning frames of the animations (for the PlayerUpper) will play frequently. I've fixed this by modifying my FlxSprite class to include a new function that allows you to play an animation and start at a specific frame. Currently this is a differently-named function than the usual "play". If you would like to utilize this, add the below code to your FlxSprite class, probably somewhere right after the "play" function.

/** * Plays an existing animation (e.g. "run") and select a starting frame if desired. * If you call an animation that is already playing it will be ignored. * If the requested starting frame is greater than the available frames, it will revert to frame 0. * * @param	AnimName	The string name of the animation you want to play. * @param	Force		Whether to force the animation to restart. * @param	StartFrame	Which frame of the animation to start from if possible. */	public function playFromFrame(AnimName:String,Force:Boolean=false, StartFrame:int=0):void {	if (!Force && (_curAnim != null) && (AnimName == _curAnim.name)) return; if ( StartFrame <= _animations.length) {		_curFrame = StartFrame; }	else {		_curFrame = 0; }	_caf = 0; _frameTimer = 0; var al:uint = _animations.length; for(var i:uint = 0; i < al; i++) {		if(_animations[i].name == AnimName) {			_curAnim = _animations[i]; if(_curAnim.delay <= 0) finished = true; else finished = false; _caf = _curAnim.frames[_curFrame]; calcFrame; return; }	} }

Once you've got this, just replace the "play("number");" in the tutorial with "playFromFrame("number", false, _curFrame);" and the new animation (for the new angle) will start at the current frame number of the current animation. Of course, this requires a series of matching multi-frame animations. I'll upload an example of that later. --Hectate 12:16, 28 June 2010 (UTC)