C# Class XnaFlixel.FlxButton

A simple button class that calls a function when clicked by the mouse. Supports labels, highlight states, and parallax scrolling.
Inheritance: FlxGroup
Show file Open project: jsbeckr/XnaFlixel

Protected Properties

Property Type Description
_callback FlxButtonClick
_initialized bool
_off FlxSprite
_offT FlxText
_on FlxSprite
_onT FlxText
_onToggle bool
_pressed bool
_sf Microsoft.Xna.Framework.Vector2

Public Methods

Method Description
Destroy ( ) : void

Called by the game state when state is changed (if this object belongs to the state)

FlxButton ( int x, int y, FlxButtonClick callback ) : Microsoft.Xna.Framework

Creates a new FlxButton object with a gray background and a callback function on the UI thread.

LoadGraphic ( FlxSprite image, FlxSprite imageHighlight ) : FlxButton

Set your own image as the button background.

LoadText ( FlxText text, FlxText textHighlight ) : FlxButton

Add a text label to the button.

Render ( SpriteBatch spriteBatch ) : void
Update ( ) : void

Called by the game loop automatically, handles mouseover and click detection.

Protected Methods

Method Description
visibility ( bool on ) : void

Internal function for handling the visibility of the off and on graphics.

Private Methods

Method Description
OnMouseUp ( object sender, FlxMouseEvent mouseEvent ) : void

Internal function for handling the actual callback call (for UI thread dependent calls like FlxU.openURL()).

Method Details

Destroy() public method

Called by the game state when state is changed (if this object belongs to the state)
public Destroy ( ) : void
return void

FlxButton() public method

Creates a new FlxButton object with a gray background and a callback function on the UI thread.
public FlxButton ( int x, int y, FlxButtonClick callback ) : Microsoft.Xna.Framework
x int The X position of the button.
y int The Y position of the button.
callback FlxButtonClick The function to call whenever the button is clicked.
return Microsoft.Xna.Framework

LoadGraphic() public method

Set your own image as the button background.
public LoadGraphic ( FlxSprite image, FlxSprite imageHighlight ) : FlxButton
image FlxSprite A FlxSprite object to use for the button background.
imageHighlight FlxSprite A FlxSprite object to use for the button background when highlighted (optional).
return FlxButton

LoadText() public method

Add a text label to the button.
public LoadText ( FlxText text, FlxText textHighlight ) : FlxButton
text FlxText A FlxText object to use to display text on this button (optional).
textHighlight FlxText A FlxText object that is used when the button is highlighted (optional).
return FlxButton

Render() public method

public Render ( SpriteBatch spriteBatch ) : void
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch
return void

Update() public method

Called by the game loop automatically, handles mouseover and click detection.
public Update ( ) : void
return void

visibility() protected method

Internal function for handling the visibility of the off and on graphics.
protected visibility ( bool on ) : void
on bool Whether the button should be on or off.
return void

Property Details

_callback protected property

This function is called when the button is clicked.
protected FlxButtonClick _callback
return FlxButtonClick

_initialized protected property

Whether or not the button has initialized itself yet.
protected bool _initialized
return bool

_off protected property

Stores the 'off' or normal button state graphic.
protected FlxSprite _off
return FlxSprite

_offT protected property

Stores the 'off' or normal button state label.
protected FlxText _offT
return FlxText

_on protected property

Stores the 'on' or highlighted button state graphic.
protected FlxSprite _on
return FlxSprite

_onT protected property

Stores the 'on' or highlighted button state label.
protected FlxText _onT
return FlxText

_onToggle protected property

Used for checkbox-style behavior.
protected bool _onToggle
return bool

_pressed protected property

Tracks whether or not the button is currently pressed.
protected bool _pressed
return bool

_sf protected property

Helper variable for correcting its members' scrollFactor objects.
protected Vector2,Microsoft.Xna.Framework _sf
return Microsoft.Xna.Framework.Vector2