Author Topic: Glowfilter on a Sprite  (Read 411 times)

Lordtakahiro

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Glowfilter on a Sprite
« on: Sat, Nov 12, 2016 »
So I've been trying to add a hover over glow filter to a sprite of mine and all the stuff I find online is out off date. I tried using FlxSpriteFilter but that doesn't exist anymore and I really don't know how to go about setting a glow filter to this sprite to be able to turn it on and off when hovered over and out.

This is the code I have so far for this class.

Code: [Select]
class InvSlot extends FlxSprite {

static inline var SIZE_INCREASE:Int = 10;

    private var _sprOver:FlxSprite;
    private var _sprDown:FlxSprite;
private var _filter:GlowFilter;
private var _sprFilter:FlxFilterFrames;

public function new(X:Int, Y:Int, OffsetX:Int, OffsetY:Int, Index:Int) {
super(X + OffsetX * Index, Y + OffsetY * Index);

// Load the image
loadGraphic(AssetPaths.invSlot__png);

// Glowfilter
_filter = new GlowFilter();
_filter.color = 0xFFFFFF;
_filter.alpha = 1;
_filter.blurX = 25;
_filter.blurY = 25;
_filter.quality = BitmapFilterQuality.MEDIUM;

// Set the size of the image
setGraphicSize(32, 32);

// Setup the mouse events
FlxMouseEventManager.add(this, onDown, null, onOver, onOut);

}

private function onDown(Sprite:FlxSprite) {

}

private function onOver(Sprite:FlxSprite) {
_sprFilter = createFilterFrames(this, _filter);
  updateFilter(this, _sprFilter);
}

private function onOut(Sprite:FlxSprite) {
_sprFilter.removeFilter(_filter);
}

function createFilterFrames(sprite:FlxSprite, filter:BitmapFilter) {
 
var filterFrames = FlxFilterFrames.fromFrames(
sprite.frames, SIZE_INCREASE, SIZE_INCREASE, [filter]);
  return filterFrames;
  }

function updateFilter(spr:FlxSprite, sprFilter:FlxFilterFrames)
  {
  sprFilter.applyToSprite(spr, false, true);
  }



}
« Last Edit: Mon, Nov 14, 2016 by Lordtakahiro »