Flixel Forums

development => help => Topic started by: Just_gabe on Sun, Oct 11, 2015

Title: How to add a mouseEvent on FlxSprites?
Post by: Just_gabe on Sun, Oct 11, 2015
I'm doing a chess like game, but I can't figure out a practical way to make a menu become visible whenever I click a char and then make it dissapear when I click other tiles, and also make other events trigger based on the buttons (not FlxButtons) I click.

The only one that occurs to me for now is the simple:
if (FlxG.mouse.justPressed())
            {
               if (FlxG.mouse.x >= currentPlayer.x && FlxG.mouse.x < currentPlayer.x + 40 &&
                  FlxG.mouse.y >= currentPlayer.y && FlxG.mouse.y < currentPlayer.y + 40)
                  showMenu();

            }
Title: Re: How to add a mouseEvent on FlxSprites?
Post by: PRIZZA on Tue, Nov 10, 2015
If you'd like to have fine tuned control on what sprite you're clicking I'd suggest using PhotonStorm's excellent Flixel Power Tools library and then changing your "piece" class to a FlxExtendedSprite, which can easily accept mouse clicks.

You can find the library here: http://www.photonstorm.com/flixel-power-tools