FlxSprite graphic angular vibration

35 views
Skip to first unread message

puggsoy

unread,
Jul 8, 2015, 6:09:39 AM7/8/15
to haxef...@googlegroups.com
Hey, anyone know a way to edit a FlxSprite's graphic's angle? In particular I want to make it vibrate, but I can't use the FlxSprite's angle property itself because I'm using that to determine movement and such. I just want the graphic to vibrate as a purely cosmetic effect.

Is there a way to do this? I didn't find an angle property on FlxSprite.graphic. I'm using the dev branch on GitHub, by the way.

SruloArt

unread,
Jul 8, 2015, 6:48:45 AM7/8/15
to haxef...@googlegroups.com
Try "FlxFrameAngle"...

Gama11

unread,
Jul 8, 2015, 7:01:06 AM7/8/15
to haxef...@googlegroups.com, pug...@gmail.com
I don't see any reason why you couldn't FlxSprite#angle for both.

puggsoy

unread,
Jul 8, 2015, 9:02:50 AM7/8/15
to haxef...@googlegroups.com, pug...@gmail.com
As I said, the movement is dependant on the angle. I only want the sprite to vibrate visually, I don't want it to move back and forth along with it.

I tried FlxSprite.frame.angle, but that's a FlxFrameAngle as opposed to a Float or something. I'm unsure how to create or modify it. This is how the type is defined:

@:enum
abstract FlxFrameAngle(Int) from Int to Int
{
   
var ANGLE_0            = 0;
   
var ANGLE_90        = 90;
   
var ANGLE_NEG_90    = -90;
   
var ANGLE_270        = -90;
}

I'm unfamiliar with abstracts but it looks like a sort of enum, which isn't much help.

Gama11

unread,
Jul 8, 2015, 9:30:26 AM7/8/15
to haxef...@googlegroups.com, pug...@gmail.com
I'm not sure what exactly you're going for. If you change the angle of the graphic, it's obviously going to move.

puggsoy

unread,
Jul 8, 2015, 10:07:02 AM7/8/15
to haxef...@googlegroups.com, pug...@gmail.com
What I mean is, in update() I modify the sprite's x and y depending on its angle property. This is fine, since I change the angle in-game using the mouse or whatever.

However, in addition I want to give the graphic a little vibration. However I don't want this vibration to affect the x and y values. I can't use FlxSprite.angle since that's what I use for determining how to move the x and y.

Gama11

unread,
Jul 8, 2015, 10:25:18 AM7/8/15
to haxef...@googlegroups.com, pug...@gmail.com
Just keep a backup of the "real" angle and add some noise on top of that?

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
using flixel.util.FlxSpriteUtil;

class PlayState extends FlxState
{
var realAngle = 0;
var sprite:FlxSprite;
override public function create():Void
{
sprite = new FlxSprite();
sprite.makeGraphic(100, 100);
sprite.screenCenter();
add(sprite);
}
override public function update():Void 
{
super.update();
realAngle += Std.int(100 * FlxG.elapsed);
sprite.angle = realAngle + Math.sin(FlxG.game.ticks) * 4;
}
}

puggsoy

unread,
Jul 8, 2015, 10:40:32 AM7/8/15
to haxef...@googlegroups.com, pug...@gmail.com
Hmm, good idea. Not exactly sure why I didn't think of that myself. Thanks!

Also, the ticks is a good way to add noise, I actually wasn't aware of that.
Reply all
Reply to author
Forward
0 new messages