Class

io.scalajs.dom.html.phaser

Button

Related Doc: package phaser

Permalink

class Button extends phaser.Phaser.Image

Create a new Button object. A Button is a special type of Sprite that is set-up to handle Pointer events automatically.

The four states a Button responds to are:

'Over' - when the Pointer moves over the Button. This is also commonly known as 'hover'. 'Out' - when the Pointer that was previously over the Button moves out of it. 'Down' - when the Pointer is pressed down on the Button. I.e. touched on a touch enabled device or clicked with the mouse. 'Up' - when the Pointer that was pressed down on the Button is released again. A different texture/frame and activation sound can be specified for any of the states.

Frames can be specified as either an integer (the frame ID) or a string (the frame name); the same values that can be used with a Sprite constructor.

Annotations
@RawJSType() @native() @JSName( "Phaser.Button" )
Linear Supertypes
Image, Smoothed, ScaleMinMax, Reset, Overlap, LoadTexture, LifeSpan, InputEnabled, FixedToCamera, Destroy, Crop, BringToTop, Bounds, AutoCull, component.Animation, Angle, Core, pixijs.Sprite, Container, DisplayObject, Object, Any, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Button
  2. Image
  3. Smoothed
  4. ScaleMinMax
  5. Reset
  6. Overlap
  7. LoadTexture
  8. LifeSpan
  9. InputEnabled
  10. FixedToCamera
  11. Destroy
  12. Crop
  13. BringToTop
  14. Bounds
  15. AutoCull
  16. Animation
  17. Angle
  18. Core
  19. Sprite
  20. Container
  21. DisplayObject
  22. Object
  23. Any
  24. AnyRef
  25. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Button(game: Phaser.Game, x: Double, y: Double, key: String, callback: Function, callbackContext: RawOptions, overFrame: |[String, JsNumber], outFrame: |[String, JsNumber], downFrame: |[String, JsNumber], upFrame: |[String, JsNumber])

    Permalink

    game

    Current game instance.

    x

    X position of the Button.

    y

    Y position of the Button.

    key

    The image key (in the Game.Cache) to use as the texture for this Button.

    callback

    The function to call when this Button is pressed.

    callbackContext

    The context in which the callback will be called (usually 'this').

    overFrame

    The frame / frameName when the button is in the Over state.

    outFrame

    The frame / frameName when the button is in the Out state.

    downFrame

    The frame / frameName when the button is in the Down state.

    upFrame

    The frame / frameName when the button is in the Up state.

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def addChild(child: DisplayObject): DisplayObject

    Permalink
    Definition Classes
    Container
  5. def addChildAt(child: DisplayObject, index: Int): DisplayObject

    Permalink
    Definition Classes
    Container
  6. def alignIn(container: |[|[|[|[|[|[|[Phaser.Rectangle, Phaser.Sprite], Phaser.Image], Phaser.Text], Phaser.BitmapText], Phaser.Button], Phaser.Graphics], Phaser.TileSprite], position: Int = js.native, offsetX: Double = js.native, offsetY: Double = js.native): Object

    Permalink

    Aligns this Game Object to the side of another Game Object, or Rectangle, known as the 'parent', in one of 11 possible positions.

    Aligns this Game Object to the side of another Game Object, or Rectangle, known as the 'parent', in one of 11 possible positions. The parent must be a Game Object, or Phaser.Rectangle object. This can include properties such as World.bounds or Camera.view, for aligning Game Objects within the world and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, TileSprites or Buttons. Please note that aligning a Sprite to another Game Object does not make it a child of the parent. It simply modifies its position coordinates so it aligns with it.

    container

    The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as World.bounds or Camera.view

    position

    The position constant. One of Phaser.TOP_LEFT (default), Phaser.TOP_CENTER, Phaser.TOP_RIGHT, Phaser.LEFT_CENTER, Phaser.CENTER, Phaser.RIGHT_CENTER, Phaser.BOTTOM_LEFT, Phaser.BOTTOM_CENTER or Phaser.BOTTOM_RIGHT

    offsetX

    A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.

    offsetY

    A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.

    returns

    This Game Object.

    Definition Classes
    Bounds
  7. var alive: Boolean

    Permalink

    A useful flag to control if the Game Object is alive or dead.

    A useful flag to control if the Game Object is alive or dead.

    This is set automatically by the Health components damage method should the object run out of health. Or you can toggle it via your game code.

    This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates. However you can use Group.getFirstAlive in conjunction with this property for fast object pooling and recycling.

    Definition Classes
    LifeSpan
    See also

    Phaser.Component.LifeSpan#alive

  8. var alpha: Alpha

    Permalink
    Definition Classes
    DisplayObject
  9. var alphanumber: Double

    Permalink
    Definition Classes
    Container
  10. var anchor: pixijs.Point

    Permalink
    Definition Classes
    DisplayObject
  11. var angle: Double

    Permalink

    The angle property is the rotation of the Game Object in degrees from its original orientation.

    The angle property is the rotation of the Game Object in degrees from its original orientation.

    Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.

    Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.

    If you wish to work in radians instead of degrees you can use the property rotation instead. Working in radians is slightly faster as it doesn't have to perform any calculations.

    Definition Classes
    ImageAngle → DisplayObject
  12. var animations: Phaser.AnimationManager

    Permalink

    If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance.

    If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance. Through it you can create, play, pause and stop animations.

    Definition Classes
    Core
  13. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  14. def autoCull: Boolean

    Permalink

    A Game Object with autoCull set to true will check its bounds against the World Camera every frame.

    A Game Object with autoCull set to true will check its bounds against the World Camera every frame. If it is not intersecting the Camera bounds at any point then it has its renderable property set to false. This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely. * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, or you have tested performance and find it acceptable.

    Definition Classes
    AutoCull
  15. var bottom: Double

    Permalink

    The sum of the y and height properties.

    The sum of the y and height properties. This is the same as y + height - offsetY.

    Definition Classes
    Bounds
  16. var cacheAsBitmap: Boolean

    Permalink
    Definition Classes
    DisplayObject
  17. var callback: Function

    Permalink

    The function to call when this Button is pressed.

  18. var callbackContext: RawOptions

    Permalink

    The context in which the callback will be called (usually 'this').

  19. var centerX: Double

    Permalink

    The center x coordinate of the Game Object.

    The center x coordinate of the Game Object. This is the same as (x - offsetX) + (width / 2).

    Definition Classes
    Bounds
  20. var centerY: Double

    Permalink

    The center y coordinate of the Game Object.

    The center y coordinate of the Game Object. This is the same as (y - offsetY) + (height / 2).

    Definition Classes
    Bounds
  21. def children: Array[DisplayObject]

    Permalink
    Definition Classes
    Container
  22. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. var data: Object

    Permalink

    An empty Object that belongs to this Game Object.

    An empty Object that belongs to this Game Object. This value isn't ever used internally by Phaser, but may be used by your own code, or by Phaser Plugins, to store data that needs to be associated with the Game Object, without polluting the Game Object directly.

    Definition Classes
    Core
  24. var debug: Boolean

    Permalink

    A debug flag designed for use with Game.enableStep.

    A debug flag designed for use with Game.enableStep.

    Definition Classes
    Core
  25. def destroy(destroyChildren: Boolean): Unit

    Permalink

    Base destroy method for generic display objects.

    Base destroy method for generic display objects.

    Definition Classes
    ImageDestroy → Container
  26. def destroy(): Unit

    Permalink

    Base destroy method for generic display objects.

    Base destroy method for generic display objects.

    Definition Classes
    ImageDestroy → DisplayObject
  27. def destroy(destroyChildren: Boolean, destroyTexture: Boolean): Unit

    Permalink

    Destroys the Game Object.

    Destroys the Game Object. This removes it from its parent group, destroys the input, event and animation handlers if present and nulls its reference to game, freeing it up for garbage collection.

    If this Game Object has the Events component it will also dispatch the onDestroy event. You can optionally also destroy the BaseTexture this Game Object is using. Be careful if you've more than one Game Object sharing the same BaseTexture.

    destroyChildren

    Should every child of this object have its destroy method called as well?

    destroyTexture

    Destroy the BaseTexture this Game Object is using? Note that if another Game Object is sharing the same BaseTexture it will invalidate it.

    Definition Classes
    Destroy
  28. def destroyPhase: Boolean

    Permalink

    As a Game Object runs through its destroy method this flag is set to true, and can be checked in any sub-systems or plugins it is being destr

    As a Game Object runs through its destroy method this flag is set to true, and can be checked in any sub-systems or plugins it is being destr

    Definition Classes
    Destroy
  29. var downFrame: |[String, JsNumber]

    Permalink

    The frame / frameName when the button is in the Down state.

  30. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  31. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  32. var events: Phaser.Events

    Permalink
    Definition Classes
    Core
  33. var filterArea: pixijs.Rectangle

    Permalink
    Definition Classes
    Container
  34. var filters: Array[AbstractFilter]

    Permalink
    Definition Classes
    Container
  35. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  36. var forceOut: |[Boolean, Phaser.PointerMode]

    Permalink

    When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up".

    When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up". This can also accept a pointer mode bitmask for more refined control.

  37. var frame: |[String, JsNumber]

    Permalink

    If this Image is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.

    If this Image is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.

    Definition Classes
    Image
  38. var freezeFrames: Boolean

    Permalink

    When true the the texture frame will not be automatically switched on up/down/over/out events.

  39. var game: Phaser.Game

    Permalink

    A reference to the currently running game.

    A reference to the currently running game.

    Definition Classes
    Image
  40. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  41. def hasOwnProperty(v: String): Boolean

    Permalink
    Definition Classes
    Object
  42. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  43. var height: Double

    Permalink
    Definition Classes
    Container
  44. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  45. def isPrototypeOf(v: Object): Boolean

    Permalink
    Definition Classes
    Object
  46. var justReleasedPreventsOver: Phaser.PointerMode

    Permalink

    Suppress the over event if a pointer was just released and it matches the given pointer mode bitmask.

    Suppress the over event if a pointer was just released and it matches the given pointer mode bitmask. This behavior was introduced in Phaser 2.3.1; this property is a soft-revert of the change.

  47. var key: |[|[|[String, Phaser.RenderTexture], Phaser.BitmapData], pixijs.Texture]

    Permalink

    The texture used by the Image during rendering.

    The texture used by the Image during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.

    Definition Classes
    Image
  48. def kill(): DisplayObject

    Permalink
    Definition Classes
    LifeSpan
  49. var left: Double

    Permalink

    The left coordinate of the Game Object.

    The left coordinate of the Game Object. This is the same as x - offsetX.

    Definition Classes
    Bounds
  50. var mask: |[pixijs.Graphics, pixijs.Sprite]

    Permalink
    Definition Classes
    Container
  51. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  52. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  53. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  54. def offsetX: Double

    Permalink

    The amount the Game Object is visually offset from its x coordinate.

    The amount the Game Object is visually offset from its x coordinate. This is the same as width * anchor.x. It will only be > 0 if anchor.x is not equal to zero.

    Definition Classes
    Bounds
  55. def offsetY: Double

    Permalink

    The amount the Game Object is visually offset from its y coordinate.

    The amount the Game Object is visually offset from its y coordinate. This is the same as height * anchor.y. It will only be > 0 if anchor.y is not equal to zero.

    Definition Classes
    Bounds
  56. def onDownSoundMarker: String

    Permalink

    The Sound Marker used in conjunction with the onDownSound.

  57. var onInputDown: Phaser.Signal

    Permalink

    The Signal (or event) dispatched when this Button is in an Down state.

  58. var onInputOut: Phaser.Signal

    Permalink

    The Signal (or event) dispatched when this Button is in an Out state.

  59. var onInputOver: Phaser.Signal

    Permalink

    The Signal (or event) dispatched when this Button is in an Over state.

  60. var onInputUp: Phaser.Signal

    Permalink

    The Signal (or event) dispatched when this Button is in an Up state.

  61. var onOutSound: |[Phaser.Sound, Phaser.AudioSprite]

    Permalink

    The Sound to be played when this Buttons Out state is activated.

  62. def onOutSoundMarker: String

    Permalink

    The Sound Marker used in conjunction with the onOutSound.

  63. var onOverMouseOnly: Boolean

    Permalink

    If true then onOver events (such as onOverSound) will only be triggered if the Pointer object causing them was the Mouse Pointer.

    If true then onOver events (such as onOverSound) will only be triggered if the Pointer object causing them was the Mouse Pointer. The frame will still be changed as applicable.

  64. def onOverSound: |[Phaser.Sound, Phaser.AudioSprite]

    Permalink

    The Sound to be played when this Buttons Over state is activated.

  65. def onOverSoundMarker: String

    Permalink

    The Sound Marker used in conjunction with the onOverSound.

  66. def onUpSound: |[Phaser.Sound, Phaser.AudioSprite]

    Permalink

    The Sound to be played when this Buttons Up state is activated.

  67. def onUpSoundMarker: String

    Permalink

    The Sound Marker used in conjunction with the onUpSound.

  68. var outFrame: |[String, JsNumber]

    Permalink

    The frame / frameName when the button is in the Out state.

  69. var overFrame: |[String, JsNumber]

    Permalink

    The frame / frameName when the button is in the Over state.

  70. def parent: Container

    Permalink
    Definition Classes
    Container
  71. var pendingDestroy: Boolean

    Permalink

    A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update.

    A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update. You can set it directly to allow you to flag an object to be destroyed on its next update.

    This is extremely useful if you wish to destroy an object from within one of its own callbacks such as with Buttons or other Input events.

  72. def physicsType: Int

    Permalink

    The const physics body type of this object.

  73. var pivot: pixijs.Point

    Permalink
    Definition Classes
    Container
  74. def play(key: String, frameRate: Double = 60, loop: Boolean = false, killOnComplete: Boolean = false): component.Animation

    Permalink
    Definition Classes
    Animation
  75. var position: pixijs.Point

    Permalink
    Definition Classes
    Container
  76. def previousPosition: Phaser.Point

    Permalink

    The position the Game Object was located in the previous frame.

  77. def previousRotation: Int

    Permalink

    The rotation the Game Object was in set to in the previous frame.

    The rotation the Game Object was in set to in the previous frame. Value is in radians.

  78. def propertyIsEnumerable(v: String): Boolean

    Permalink
    Definition Classes
    Object
  79. def renderOrderID: Int

    Permalink

    The render order ID is used internally by the renderer and Input Manager and should not be modified.

    The render order ID is used internally by the renderer and Input Manager and should not be modified. This property is mostly used internally by the renderers, but is exposed for the use of plugins.

  80. var renderable: Boolean

    Permalink
    Definition Classes
    Container
  81. def reset(x: Double, y: Double, health: Double = 1): DisplayObject

    Permalink
    Definition Classes
    Reset
  82. def revive(health: Double = 1): DisplayObject

    Permalink
    Definition Classes
    LifeSpan
  83. var right: Double

    Permalink

    The right coordinate of the Game Object.

    The right coordinate of the Game Object. This is the same as x + width - offsetX.

    Definition Classes
    Bounds
  84. var rotation: Double

    Permalink
    Definition Classes
    Container
  85. var scale: pixijs.Point

    Permalink
    Definition Classes
    Container
  86. var scaleMax: Phaser.Point

    Permalink

    The maximum scale this Game Object will scale up to.

    The maximum scale this Game Object will scale up to.

    It allows you to prevent a parent from scaling this Game Object higher than the given value.

    Set it to null to remove the limit.

    Definition Classes
    ScaleMinMax
  87. var scaleMin: Phaser.Point

    Permalink

    The minimum scale this Game Object will scale down to.

    The minimum scale this Game Object will scale down to.

    It allows you to prevent a parent from scaling this Game Object lower than the given value.

    Set it to null to remove the limit.

    Definition Classes
    ScaleMinMax
  88. def setParent(container: Container): Container

    Permalink
    Definition Classes
    DisplayObject
  89. def setScaleMinMax(minX: Double = js.native, minY: Double = js.native, maxX: Double = js.native, maxY: Double = js.native): Unit

    Permalink

    Sets the scaleMin and scaleMax values.

    Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent. For example if this Game Object has a minScale value of 1 and its parent has a scale value of 0.5, the 0.5 will be ignored and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to. By setting these values you can carefully control how Game Objects deal with responsive scaling. If only one parameter is given then that value will be used for both scaleMin and scaleMax: setScaleMinMax(1) = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1 If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y: setScaleMinMax(0.5, 2) = scaleMin.x and y = 0.5 and scaleMax.x and y = 2 If you wish to set scaleMin with different values for x and y then either modify Game Object.scaleMin directly, or pass null for the maxX and maxY parameters. Call setScaleMinMax(null) to clear all previously set values.

    minX

    The minimum horizontal scale value this Game Object can scale down to.

    minY

    The minimum vertical scale value this Game Object can scale down to.

    maxX

    The maximum horizontal scale value this Game Object can scale up to.

    maxY

    The maximum vertical scale value this Game Object can scale up to.

    Definition Classes
    ScaleMinMax
  90. var smoothed: Boolean

    Permalink

    Enable or disable texture smoothing for this Game Object.

    Enable or disable texture smoothing for this Game Object. It only takes effect if the Game Object is using an image based texture. Smoothing is enabled by default.

    Definition Classes
    Smoothed
  91. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  92. def toGlobal(position: pixijs.Point): pixijs.Point

    Permalink
    Definition Classes
    DisplayObject
  93. def toLocal(position: pixijs.Point, from: DisplayObject): pixijs.Point

    Permalink
    Definition Classes
    DisplayObject
  94. def toLocaleString(): String

    Permalink
    Definition Classes
    Object
  95. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  96. var top: Double

    Permalink

    The y coordinate of the Game Object.

    The y coordinate of the Game Object. This is the same as y - offsetY.

    Definition Classes
    Bounds
  97. var transformCallback: Function

    Permalink

    The callback that will apply any scale limiting to the worldTransform.

    The callback that will apply any scale limiting to the worldTransform.

    Definition Classes
    ScaleMinMax
  98. var transformCallbackContext: Object

    Permalink

    The context under which transformCallback is called.

    The context under which transformCallback is called.

    Definition Classes
    ScaleMinMax
  99. def type: Int

    Permalink

    The const type of this object.

    The const type of this object.

    Definition Classes
    Image
  100. var upFrame: |[String, JsNumber]

    Permalink

    The frame / frameName when the button is in the Up state.

  101. def valueOf(): Any

    Permalink
    Definition Classes
    Object
  102. var visible: Boolean

    Permalink
    Definition Classes
    DisplayObject
  103. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  104. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  105. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  106. var width: Double

    Permalink
    Definition Classes
    Container
  107. var world: Phaser.Point

    Permalink

    The world coordinates of this Game Object in pixels.

    The world coordinates of this Game Object in pixels. Depending on where in the display list this Game Object is placed this value can differ from position, which contains the x/y coordinates relative to the Game Objects parent.

    Definition Classes
    Core
  108. def worldAlpha: Alpha

    Permalink
    Definition Classes
    Container
  109. def worldTransform: Matrix

    Permalink
    Definition Classes
    DisplayObject
  110. def worldVisible: Boolean

    Permalink
    Definition Classes
    DisplayObject
  111. var x: Double

    Permalink

    The x coordinate of the Image.

    The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in.

    Definition Classes
    Image → DisplayObject
  112. var y: Double

    Permalink

    The y coordinate of the Image.

    The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in.

    Definition Classes
    Image → DisplayObject
  113. var z: Double

    Permalink

    The z depth of this Game Object within its parent Group.

    The z depth of this Game Object within its parent Group. No two objects in a Group can have the same z value. This value is adjusted automatically whenever the Group hierarchy changes. If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop.

    Definition Classes
    Core

Inherited from Image

Inherited from Smoothed

Inherited from ScaleMinMax

Inherited from Reset

Inherited from Overlap

Inherited from LoadTexture

Inherited from LifeSpan

Inherited from InputEnabled

Inherited from FixedToCamera

Inherited from Destroy

Inherited from Crop

Inherited from BringToTop

Inherited from Bounds

Inherited from AutoCull

Inherited from component.Animation

Inherited from Angle

Inherited from Core

Inherited from pixijs.Sprite

Inherited from Container

Inherited from DisplayObject

Inherited from Object

Inherited from Any

Inherited from AnyRef

Inherited from Any

Ungrouped