Last active
June 25, 2016 18:04
-
-
Save Ohmnivore/de91d3a855780ac4a296e3df83382a33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import flixel.FlxG; | |
import flixel.FlxSprite; | |
import flixel.input.mouse.FlxMouseEventManager; | |
import flixel.math.FlxPoint; | |
import flixel.tweens.FlxTween; | |
/** | |
* ... | |
* @author Nightlyside | |
*/ | |
class MenuIcon extends FlxSprite | |
{ | |
private var initPos:FlxPoint; | |
private var curTween:FlxTween; | |
public function new(id:Int, H:Float, W:Float, hParent:Float, yParent:Float, graphics:String) | |
{ | |
super(); | |
loadGraphic(graphics); | |
setGraphicSize(Std.int(H), Std.int(W)); | |
height = H; | |
width = W; | |
updateHitbox(); | |
setPosition(getSlotPos(id) - Std.int(W / 2), Std.int(yParent + hParent / 2 - H / 2)); | |
initPos = new FlxPoint(x, y); | |
FlxMouseEventManager.add(this, null, null, onMouseOver, onMouseOut); | |
} | |
public function getSlotPos(id:Int) | |
{ | |
var posX:Int; | |
posX = Std.int(FlxG.width / 6) * (id + 1); | |
return posX; | |
} | |
public function onMouseOver(spr:FlxSprite) | |
{ | |
if (curTween != null) | |
curTween.cancel(); | |
curTween = FlxTween.tween(this, { x: initPos.x + 5, y: initPos.y-10 }, 0.2, { }); | |
} | |
private function onMouseOut(spr:FlxSprite) | |
{ | |
if (curTween != null) | |
curTween.cancel(); | |
curTween = FlxTween.tween(this, {x: initPos.x, y: initPos.y}, 0.2, { }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment