HaxeFlixel Logo HaxeFlixel Snippets
  • About
  • Tutorials
  • Back to HaxeFlixel.com
  • Basics
    • Screen
    • Adding
  • Objects
    • Alive
    • Health
  • Sprites
    • Making Sprites
    • Loading Sprites
    • Animation
    • Alpha
    • Color
    • Facing
    • Scale
    • Baked Rotations
  • Text
    • FlxText
    • FlxBitmapText
  • Movement
    • Velocity
    • Acceleration
    • MaxVelocity
    • Gravity
    • Jumping
    • Angle
    • Angular Velocity
    • Angular Acceleration
  • Groups
    • Basic Group
    • Typed Group
    • Recycling
  • Tiling
    • Tileblock
    • Tilemap
  • Overlap
    • Simple Overlap
    • Overlap Callbacks
  • Collision
    • 1-to-1 Collision
    • Immovable
    • Tilemap Collision
    • Moving Platforms
  • Camera
    • Flash
    • Fade
    • Shake
    • Follow
  • Input
    • Basics
    • Keyboard
    • Mouse
    • Button
  • Sound
    • FlxSound

Mouse

mouse is an instance of FlxMouse used to get information about the cursor’s position, and states of the mouse butttons.

trace(FlxG.mouse.x, FlxG.mouse.y);

Demonstration

Source

source/PlayState.hx

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.util.FlxColor;

class PlayState extends FlxState
{
    var h:FlxSprite;
    var v:FlxSprite;
    var center:FlxSprite;

    override public function create()
    {
        super.create();

        h = new FlxSprite();
        h.makeGraphic(3, FlxG.height, FlxColor.BLUE);
        add(h);

        v = new FlxSprite();
        v.makeGraphic(FlxG.width, 3, FlxColor.BLUE);
        add(v);

        center = new FlxSprite();
        center.makeGraphic(5, 5, FlxColor.YELLOW);
        add(center);
    }

    override public function update(elapsed:Float)
    {
        super.update(elapsed);

        h.x = FlxG.mouse.x - 1;
        v.y = FlxG.mouse.y - 1;
        center.x = h.x - 1;
        center.y = v.y - 1;
        if (FlxG.mouse.justReleased)
            FlxG.camera.flash(FlxColor.WHITE, 0.33);
    }
}
View Source on GitHub

Tags

input keyboard mouse
  1. Home
  2. Input
  3. Mouse
Powered By HaxeFlixel Logo HaxeFlixel