FlixelTouchManager
View sourceclass
org.flixelgdx.input.touch.FlixelTouchManager
Multitouch input manager backed by libGDX's InputProcessor callbacks.
Access via Flixel.touches after the framework is initialized. The manager tracks up to FlixelTouchManager.getMaxPointers() simultaneous fingers in the FlixelTouchManager.list array. Each slot is a reused FlixelTouch instance; slot 0 always corresponds to pointer index 0 (the first finger), slot 1 to index 1, and so on.
// Check the first finger each frame.
if (Flixel.touches.list[0].isJustPressed()) {
spawnEffect(Flixel.touches.list[0].worldX, Flixel.touches.list[0].worldY);
}
// React to any active touch.
if (Flixel.touches.anyTouched()) {
player.move(Flixel.touches.list[0].worldX, Flixel.touches.list[0].worldY);
}
// Detect a tap on a sprite using world coordinates.
if (Flixel.touches.justTouchedWorld(
mySprite.getX(), mySprite.getY(),
mySprite.getWidth(), mySprite.getHeight())) {
onButtonTapped();
}
// Track whether a finger is currently held inside a screen region.
if (Flixel.touches.touchingScreen(0, 0, halfWidth, screenHeight)) {
moveLeft();
}
Coordinate systems
Each FlixelTouch carries both screen and world coordinates. Screen coordinates use libGDX's top-left origin (Y increases downward). World coordinates are unprojected via the manager's active camera and use the standard bottom-left origin (Y increases upward), matching the rest of the scene. Set a custom camera with FlixelTouchManager.setWorldCamera(FlixelCamera); otherwise the first camera in Flixel.cameras is used.
Frame contract
The InputProcessor is the authoritative source for justPressed, justReleased, and justCancelled flags; they are set inside the callbacks and cleared by FlixelTouchManager.endFrame(). FlixelTouchManager.update() refreshes screen and world coordinates each frame for all active pointers.
Max pointer count
The default limit is 10, which covers the maximum simultaneous touches supported by virtually all Android hardware. Call FlixelTouchManager.setMaxPointers(int) to raise or lower the limit; existing live touch state is preserved for pointers that fall within the new size.
Constructors
FlixelTouchManager()
FlixelTouchManager(int)
Fields
DEFAULT_MAX_POINTERS
Default maximum number of simultaneous touch pointers tracked.
list
Per-pointer state array. Read FlixelTouch instances directly for zero-overhead access. Do not reassign this field from outside the manager; use FlixelTouchManager.setMaxPointers(int) instead.
Every slot is always a non-null FlixelTouch. Check FlixelTouch.pressed() to determine whether a slot represents an active finger.
enabled
When false, all queries return inactive state.
Note that this is typically false by default, although mobile backends will automatically enable the touch manager when a game is compiled for mobile platforms.
Methods
setMaxPointers(int)
Resizes the pointer limit and reallocates FlixelTouchManager.list. Existing FlixelTouch objects are preserved for indices that fall within the new size; new slots beyond the old size receive fresh instances. Reducing the limit discards state for pointers above the new ceiling.
Parameters:
| Name | Description |
|---|---|
n | New maximum pointer count (must be positive). |
getMaxPointers()
Returns the current maximum number of tracked pointers.
getInputProcessor()
Returns the stable InputProcessor that must be registered on the InputMultiplexer for the lifetime of the game session. Registered automatically by FlixelGame.create().
update()
Refreshes screen and world coordinates for all active pointers. Called once per frame by FlixelGame.update() before game logic runs.
endFrame()
Clears per-frame edge flags (FlixelTouch.justPressed(), FlixelTouch.justReleased(), FlixelTouch.justCancelled()) for all pointers. Called once per frame by FlixelGame.render() after game logic and drawing finish.
reset()
Resets all pointer state to inactive without changing the pointer limit or camera.
setWorldCamera(FlixelCamera)
Sets the camera used to unproject screen coordinates to world coordinates in FlixelTouchManager.update(). Pass null to fall back to the first camera in Flixel.cameras.
Parameters:
| Name | Description |
|---|---|
camera | Camera to use for unprojection, or null for the default. |
getWorldCamera()
Returns the camera used for world coordinate unprojection, or null if using default.
pressed(int)
Returns true while the given pointer index is currently in contact with the screen.
Parameters:
| Name | Description |
|---|---|
pointer | Zero-based pointer index. |
Returns: true if the pointer is pressed and input is enabled.
justPressed(int)
Returns true on the single frame the given pointer first touched the screen.
Parameters:
| Name | Description |
|---|---|
pointer | Zero-based pointer index. |
Returns: true if the pointer was just pressed and input is enabled.
justReleased(int)
Returns true on the single frame the given pointer lifted off the screen.
Parameters:
| Name | Description |
|---|---|
pointer | Zero-based pointer index. |
Returns: true if the pointer was just released and input is enabled.
anyPressed()
Returns true if any tracked pointer is currently in contact with the screen.
Returns: true if at least one pointer is pressed and input is enabled.
anyJustPressed()
Returns true on the single frame any pointer first touched the screen.
Equivalent to checking FlixelTouch.justPressed() across every slot. Useful when you do not need to know which finger triggered the press.
if (Flixel.touches.anyJustPressed()) {
Flixel.haptics.vibrate(30);
}
Returns: true if at least one pointer was just pressed this frame and input is enabled.
anyJustReleased()
Returns true on the single frame any pointer lifted off the screen.
Equivalent to checking FlixelTouch.justReleased() across every slot. Useful when you only care that some finger was released, not which one.
if (Flixel.touches.anyJustReleased()) {
releaseButtonHighlight();
}
Returns: true if at least one pointer was just released this frame and input is enabled.
count()
Returns the number of pointers currently in contact with the screen.
Returns: Active pointer count, or 0 when input is disabled.
touchingWorld(float, float, float, float)
Returns true while any active pointer is inside the given world-space rectangle.
Coordinates use the bottom-left origin (Y increases upward), matching the game world. Use this to track a finger held inside an area. For detecting the moment a finger lands, use FlixelTouchManager.justTouchedWorld(...) instead.
if (Flixel.touches.touchingWorld(button.getX(), button.getY(),
button.getWidth(), button.getHeight())) {
button.setHighlighted(true);
}
Parameters:
| Name | Description |
|---|---|
x | Left edge of the rectangle in world units. |
y | Bottom edge of the rectangle in world units. |
width | Width of the rectangle in world units. |
height | Height of the rectangle in world units. |
Returns: true if at least one pressed pointer is inside the rectangle.
touchingScreen(float, float, float, float)
Returns true while any active pointer is inside the given screen-space rectangle.
Coordinates use the top-left origin (Y increases downward), matching libGDX screen space. Use this to track a finger held inside an area. For detecting the moment a finger lands, use FlixelTouchManager.justTouchedScreen(...) instead.
float half = Gdx.graphics.getWidth() / 2f;
if (Flixel.touches.touchingScreen(half, 0, half, Gdx.graphics.getHeight())) {
moveRight();
}
Parameters:
| Name | Description |
|---|---|
x | Left edge of the rectangle in screen pixels. |
y | Top edge of the rectangle in screen pixels. |
width | Width of the rectangle in screen pixels. |
height | Height of the rectangle in screen pixels. |
Returns: true if at least one pressed pointer is inside the rectangle.
justTouchedWorld(float, float, float, float)
Returns true on the single frame any pointer first touches the given world-space rectangle.
Coordinates use the bottom-left origin (Y increases upward), matching the game world. Clears to false after the frame ends, matching the timing of FlixelTouch.justPressed().
if (Flixel.touches.justTouchedWorld(button.getX(), button.getY(),
button.getWidth(), button.getHeight())) {
onButtonTapped();
}
Parameters:
| Name | Description |
|---|---|
x | Left edge of the rectangle in world units. |
y | Bottom edge of the rectangle in world units. |
width | Width of the rectangle in world units. |
height | Height of the rectangle in world units. |
Returns: true if any pointer was just pressed inside the rectangle this frame.
justTouchedScreen(float, float, float, float)
Returns true on the single frame any pointer first touches the given screen-space rectangle.
Coordinates use the top-left origin (Y increases downward), matching libGDX screen space. Clears to false after the frame ends, matching the timing of FlixelTouch.justPressed().
if (Flixel.touches.justTouchedScreen(0, 0, Gdx.graphics.getWidth() / 2f,
Gdx.graphics.getHeight())) {
onLeftSideTapped();
}
Parameters:
| Name | Description |
|---|---|
x | Left edge of the rectangle in screen pixels. |
y | Top edge of the rectangle in screen pixels. |
width | Width of the rectangle in screen pixels. |
height | Height of the rectangle in screen pixels. |
Returns: true if any pointer was just pressed inside the rectangle this frame.