FlxSprite moving strangely

  • I am using a Bullet class that inherits from FlxSprite. (It is the same Bullet class from the MinimalistTD example, with minor changes.) The Bullet objects are supposed to move toward their target as long as their target is alive, and despawn when they either hit their target or fly offscreen. However, they are instead moving slowly and jiggling a lot, and I'm not sure why this is happening. It was working fine before, but I loaded an image with loadGraphic() and changed the size and it stopped working.

    My Bullet object calls FlxVelocity.moveTowardsObject() every update, but it is not moving in the way I would expect from that. I set the solid property to false and the allowCollisions property to NONE, so it shouldn't be colliding with anything either.

    Can anyone tell me what might be causing this? Thanks.

  • Can you show the code? Are you calling update() twice somewhere?

  • Sure. Here's the relevant functions from my Bullet class:

    public function new()
        makeGraphic(3, 3);
        solid = false;
        allowCollisions = FlxObject.NONE;
    public function init(X:Float, Y:Float, Target:Enemy, Damage:Float)
        reset(X, Y);
        _target = Target;
        _damage = Damage;
    override public function update(elapsed:Float):Void
    	{ // This bullet missed its target and flew off-screen; no reason to keep it around.
    	else if(_target.alive)
    	{ // Move toward the target that was assigned in init().
    		FlxVelocity.moveTowardsObject(this, _target, 200);
            if (overlaps(_target))
            // kill();

    Here's the bullet creation code from my tower class:

        var bulletFiring:Bullet = new Bullet();
        bulletFiring.init(x, y, target, _damage*_integrity);
        bulletFiring.setGraphicSize(10, 10);

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.