TouchScreenButton
Button for touch screen devices for gameplay use.
TouchScreenButton.swift:22class TouchScreenButton
TouchScreenButton allows you to create on-screen buttons for touch devices. It’s intended for gameplay use, such as a unit you have to touch to move. Unlike Button
, TouchScreenButton supports multitouch out of the box. Several TouchScreenButtons can be pressed at the same time with touch input.
This node inherits from Node2D
. Unlike with Control
nodes, you cannot set anchors on it. If you want to create menus or user interfaces, you may want to use Button
nodes instead. To make button nodes react to touch events, you can enable the Emulate Mouse option in the Project Settings.
You can configure TouchScreenButton to be visible only on touch devices, helping you develop your game both for desktop and mobile devices.
This object emits the following signals:
Superclasses
class Node2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
Instance members
var action: String
The button’s action. Actions can be handled with
InputEventAction
.var bitmask: BitMap?
The button’s bitmask.
var passbyPress: Bool
If
true
, the [signal pressed] and [signal released] signals are emitted whenever a pressed finger goes in and out of the button, even if the pressure started outside the active area of the button.var pressed: SimpleSignal
Emitted when the button is pressed (down).
var released: SimpleSignal
Emitted when the button is released (up).
var shape: Shape2D?
The button’s shape.
var shapeCentered: Bool
If
true
, the button’s shape is centered in the provided texture. If no texture is used, this property has no effect.var shapeVisible: Bool
If
true
, the button’s shape is visible in the editor.var textureNormal: Texture2D?
The button’s texture for the normal state.
var texturePressed: Texture2D?
The button’s texture for the pressed state.
var visibilityMode: TouchScreenButton.VisibilityMode
The button’s visibility mode. See
VisibilityMode
for possible values.func isPressed(
) -> Bool Returns
true
if this button is currently pressed.