libgdx API

com.badlogic.gdx.scenes.scene2d.actors
Class Button

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.actors.Button
All Implemented Interfaces:
Layout

public class Button
extends Actor
implements Layout

A simple Button Actor, useful for simple UIs

Author:
mzechner

Nested Class Summary
static interface Button.ClickListener
           
 
Field Summary
 Button.ClickListener clickListener
           
protected  int pointer
           
 boolean pressed
           
 TextureRegion pressedRegion
           
 TextureRegion unpressedRegion
           
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, touchable, width, x, y
 
Constructor Summary
Button(java.lang.String name)
          Creates a new Button instance with the given name.
Button(java.lang.String name, Texture texture)
          Creates a new Button instance with the given name, using the complete supplied texture for displaying the pressed and unpressed state of the button.
Button(java.lang.String name, TextureRegion region)
           
Button(java.lang.String name, TextureRegion unpressedRegion, TextureRegion pressedRegion)
           
 
Method Summary
protected  void draw(SpriteBatch batch, float parentAlpha)
          Draws the Actor.
 float getPrefHeight()
           
 float getPrefWidth()
           
 Actor hit(float x, float y)
           
 void invalidate()
           
 void layout()
           
protected  boolean touchDown(float x, float y, int pointer)
           
protected  boolean touchDragged(float x, float y, int pointer)
           
protected  boolean touchUp(float x, float y, int pointer)
           
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, isMarkedToRemove, keyDown, keyTyped, keyUp, markToRemove, remove, scrolled, toLocalCoordinates, toString, touchMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pressedRegion

public TextureRegion pressedRegion

unpressedRegion

public TextureRegion unpressedRegion

clickListener

public Button.ClickListener clickListener

pressed

public boolean pressed

pointer

protected int pointer
Constructor Detail

Button

public Button(java.lang.String name)
Creates a new Button instance with the given name.

Parameters:
name - the name

Button

public Button(java.lang.String name,
              Texture texture)
Creates a new Button instance with the given name, using the complete supplied texture for displaying the pressed and unpressed state of the button.

Parameters:
name - the name
texture - the Texture

Button

public Button(java.lang.String name,
              TextureRegion region)

Button

public Button(java.lang.String name,
              TextureRegion unpressedRegion,
              TextureRegion pressedRegion)
Method Detail

draw

protected void draw(SpriteBatch batch,
                    float parentAlpha)
Description copied from class: Actor
Draws the Actor. The spriteBatch is configured so that the Actor can draw in its parents coordinate system. The parent's alpha is passed to the method in order for the Actor to multiply it with its own alpha. This will allow FadeIn and other Actions to have an effect even if they are only set on the parent of the Actor.

Specified by:
draw in class Actor
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

touchDown

protected boolean touchDown(float x,
                            float y,
                            int pointer)
Specified by:
touchDown in class Actor

touchUp

protected boolean touchUp(float x,
                          float y,
                          int pointer)
Specified by:
touchUp in class Actor

touchDragged

protected boolean touchDragged(float x,
                               float y,
                               int pointer)
Specified by:
touchDragged in class Actor

hit

public Actor hit(float x,
                 float y)
Specified by:
hit in class Actor

layout

public void layout()
Specified by:
layout in interface Layout

invalidate

public void invalidate()
Specified by:
invalidate in interface Layout

getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)