SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
libGDX: 
User 
Input 
Jussi 
Pohjolainen 
Tampere 
University 
of 
Applied 
Sciences
TOUCH 
+ 
KEYBOARD
Event 
vs 
Polling 
• Polling 
– Do 
something 
on 
each 
frame, 
really 
fast 
– Was 
mouse 
clicked? 
Was 
mouse 
clicked? 
Was 
mouse 
clicked? 
– Good 
for 
arcade 
games 
• Event 
– Do 
something 
when 
event 
handles 
– NoIfy 
when 
mouse 
was 
clicked 
– UI 
elements 
such 
as 
buJons 
• Mouse 
/ 
touch 
/ 
keyboard 
can 
be 
received 
either 
polling 
or 
event 
handling
public class MyInputProcessor implements InputProcessor { 
@Override 
public boolean keyDown (int keycode) { 
return false; 
} 
@Override 
public boolean keyUp (int keycode) { 
return false; 
} 
@Override 
public boolean keyTyped (char character) { 
return false; 
} 
@Override 
public boolean touchDown (int x, int y, int pointer, int button) { 
return false; 
} 
@Override 
public boolean touchUp (int x, int y, int pointer, int button) { 
return false; 
} 
@Override 
public boolean touchDragged (int x, int y, int pointer) { 
return false; 
} 
@Override 
public boolean mouseMoved (int x, int y) { 
return false; 
} 
@Override 
public boolean scrolled (int amount) { 
return false; 
} 
} 
MyInputProcessor inputProcessor = new MyInputProcessor(); 
Gdx.input.setInputProcessor(inputProcessor);
Polling 
Touch 
/ 
Keyboard 
• For 
most 
arcade 
games, 
polling 
is 
good 
• MulItouch 
is 
supported! 
– boolean firstFingerTouching = Gdx.input.isTouched(0); 
– boolean secondFingerTouching = Gdx.input.isTouched(1); 
– int firstX = Gdx.input.getX(); 
– int firstY = Gdx.input.getY(); 
– int secondX = Gdx.input.getX(1); 
– int secondY = Gdx.input.getY(1); 
• Keyboard 
– boolean isAPressed = Gdx.input.isKeyPressed(Keys.A);
ACCELEROMETER
Accelerometer 
• An 
accelerometer 
measures 
the 
acceleraIon 
of 
a 
device 
on 
three 
axes 
• From 
this 
acceleraIon 
one 
can 
derive 
the 
Ilt 
or 
orientaIon 
of 
the 
device. 
– Phones: 
portrait 
default 
– Tablet: 
landscape 
default 
• LibGDX 
shows 
accelerometer 
readings 
always 
as 
in 
the 
image
Accelerometer 
y 
(0,0) 
Accelerometer 
x 
y 
increments 
x 
increments
Accelerometer 
Readings 
• Accelerometer 
readings 
can 
be 
accessed 
– float accelX = Gdx.input.getAccelerometerX(); 
– float accelY = Gdx.input.getAccelerometerY(); 
– float accelZ = Gdx.input.getAccelerometerZ(); 
• When 
moving 
and 
if 
in 
landscape 
mode 
in 
android, 
noIce 
X 
vs 
Y! 
– speedX += Gdx.input.getAccelerometerY();
GESTURES
GestureDetector 
• TouchDown 
• LongPress 
• Tap 
• Pan 
– Useful 
for 
camera 
panning 
in 
2D 
• PanStop 
• Fling 
• Zoom 
– Camera 
zooming 
• Pinch 
– Camera 
zooming 
+ 
rotaIon
StarIng 
to 
Listen 
to 
Gestures 
• Really 
easy 
– Gdx.input.setInputProcessor(new 
GestureDetector(new MyGestureListener())); 
• MyGestureListener 
is 
some 
class 
that 
implements 
GestureListener
public class MyGestureListener implements GestureListener { 
@Override 
public boolean touchDown(float x, float y, int pointer, int button) {} 
@Override 
public boolean tap(float x, float y, int count, int button) {} 
@Override 
public boolean longPress(float x, float y) {} 
@Override 
public boolean fling(float velocityX, float velocityY, int button) {} 
@Override 
public boolean pan(float x, float y, float deltaX, float deltaY) {} 
@Override 
public boolean panStop(float x, float y, int pointer, int button) {} 
@Override 
public boolean zoom (float originalDistance, float currentDistance){} 
@Override 
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, 
Vector2 firstPointer, Vector2 secondPointer){} 
}
SIMPLE 
TEXT 
INPUT
User 
input 
• Desktop 
– Swing 
dialog 
• Android 
– Android 
dialog 
• Use 
TextInputListener 
– MyTextInputListener listener = new MyTextInputListener(); 
– Gdx.input.getTextInput(listener, "Dialog Title", "Initial 
Textfield Value")
public class MyTextInputListener implements TextInputListener { 
@Override 
public void input (String text) { 
} 
@Override 
public void canceled () { 
} 
}
MISC
• Vibra 
– Gdx.input.vibrate(2000); 
– Remember 
to 
add 
permissions 
• Compass 
– float azimuth = Gdx.input.getAzimuth(); 
– float pitch = Gdx.input.getPitch(); 
– float roll = Gdx.input.getRoll();

Más contenido relacionado

La actualidad más candente

Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Unity Technologies
 
Game Development using SDL and the PDK
Game Development using SDL and the PDK Game Development using SDL and the PDK
Game Development using SDL and the PDK ardiri
 
Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲吳錫修 (ShyiShiou Wu)
 
Game Development with SDL and Perl
Game Development with SDL and PerlGame Development with SDL and Perl
Game Development with SDL and Perlgarux
 
Technical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemTechnical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemUnity Technologies
 
Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0Leszek Godlewski
 
SDL2 Game Development VT Code Camp 2013
SDL2 Game Development VT Code Camp 2013SDL2 Game Development VT Code Camp 2013
SDL2 Game Development VT Code Camp 2013Eric Basile
 
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle GamesWe Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle GamesUnity Technologies
 
Unity遊戲程式設計(15) 實作Space shooter遊戲
Unity遊戲程式設計(15) 實作Space shooter遊戲Unity遊戲程式設計(15) 實作Space shooter遊戲
Unity遊戲程式設計(15) 實作Space shooter遊戲吳錫修 (ShyiShiou Wu)
 
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019Unity Technologies
 
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...gamifi.cc
 
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Pujana Paliyawan
 
HoloLens Programming Tutorial: AirTap & Spatial Mapping
HoloLens Programming Tutorial: AirTap & Spatial MappingHoloLens Programming Tutorial: AirTap & Spatial Mapping
HoloLens Programming Tutorial: AirTap & Spatial MappingTakashi Yoshinaga
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming TutorialRichard Jones
 

La actualidad más candente (20)

Input and Interaction
Input and InteractionInput and Interaction
Input and Interaction
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
7java Events
7java Events7java Events
7java Events
 
Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019Cross-scene references: A shock to the system - Unite Copenhagen 2019
Cross-scene references: A shock to the system - Unite Copenhagen 2019
 
Game Development using SDL and the PDK
Game Development using SDL and the PDK Game Development using SDL and the PDK
Game Development using SDL and the PDK
 
Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲
 
Game Development with SDL and Perl
Game Development with SDL and PerlGame Development with SDL and Perl
Game Development with SDL and Perl
 
Technical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemTechnical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab System
 
Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0
 
SDL2 Game Development VT Code Camp 2013
SDL2 Game Development VT Code Camp 2013SDL2 Game Development VT Code Camp 2013
SDL2 Game Development VT Code Camp 2013
 
Unity 13 space shooter game
Unity 13 space shooter gameUnity 13 space shooter game
Unity 13 space shooter game
 
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle GamesWe Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
 
Unity遊戲程式設計(15) 實作Space shooter遊戲
Unity遊戲程式設計(15) 實作Space shooter遊戲Unity遊戲程式設計(15) 實作Space shooter遊戲
Unity遊戲程式設計(15) 實作Space shooter遊戲
 
Soc research
Soc researchSoc research
Soc research
 
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019
Unity asset workflows for Film and Animation pipelines - Unite Copenhagen 2019
 
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
 
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
 
HoloLens Programming Tutorial: AirTap & Spatial Mapping
HoloLens Programming Tutorial: AirTap & Spatial MappingHoloLens Programming Tutorial: AirTap & Spatial Mapping
HoloLens Programming Tutorial: AirTap & Spatial Mapping
 
Sequence diagrams
Sequence diagramsSequence diagrams
Sequence diagrams
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 

Similar a libGDX: User Input

Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward
 
Chapter 03 game input
Chapter 03 game inputChapter 03 game input
Chapter 03 game inputboybuon205
 
Scientific calculator in c
Scientific calculator in cScientific calculator in c
Scientific calculator in cUpendra Sengar
 
Multi Touch presentation
Multi Touch presentationMulti Touch presentation
Multi Touch presentationsenthil0809
 
Tech day ngobrol santai tensorflow
Tech day ngobrol santai tensorflowTech day ngobrol santai tensorflow
Tech day ngobrol santai tensorflowRamdhan Rizki
 
Game Development for Nokia Asha Devices with Java ME #2
Game Development for Nokia Asha Devices with Java ME #2Game Development for Nokia Asha Devices with Java ME #2
Game Development for Nokia Asha Devices with Java ME #2Marlon Luz
 
Various input devices showing their features
Various input devices showing their featuresVarious input devices showing their features
Various input devices showing their featuresLavan1997
 
Android application - Tic Tac Toe
Android application - Tic Tac ToeAndroid application - Tic Tac Toe
Android application - Tic Tac ToeSarthak Srivastava
 

Similar a libGDX: User Input (20)

Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
 
Y Tiles
Y TilesY Tiles
Y Tiles
 
Chapter 03 game input
Chapter 03 game inputChapter 03 game input
Chapter 03 game input
 
Scientific calculator in c
Scientific calculator in cScientific calculator in c
Scientific calculator in c
 
Mobile Application Development class 005
Mobile Application Development class 005Mobile Application Development class 005
Mobile Application Development class 005
 
Working with Callbacks
Working with CallbacksWorking with Callbacks
Working with Callbacks
 
Unix signals
Unix signalsUnix signals
Unix signals
 
662305 LAB12
662305 LAB12662305 LAB12
662305 LAB12
 
Multi Touch presentation
Multi Touch presentationMulti Touch presentation
Multi Touch presentation
 
Md2010 jl-wp7-sl-game-dev
Md2010 jl-wp7-sl-game-devMd2010 jl-wp7-sl-game-dev
Md2010 jl-wp7-sl-game-dev
 
efy-articles
efy-articlesefy-articles
efy-articles
 
Tech day ngobrol santai tensorflow
Tech day ngobrol santai tensorflowTech day ngobrol santai tensorflow
Tech day ngobrol santai tensorflow
 
grahics
grahicsgrahics
grahics
 
Game Development for Nokia Asha Devices with Java ME #2
Game Development for Nokia Asha Devices with Java ME #2Game Development for Nokia Asha Devices with Java ME #2
Game Development for Nokia Asha Devices with Java ME #2
 
Real life XNA
Real life XNAReal life XNA
Real life XNA
 
Of class2
Of class2Of class2
Of class2
 
BingoConsoleApp
BingoConsoleAppBingoConsoleApp
BingoConsoleApp
 
Day 5
Day 5Day 5
Day 5
 
Various input devices showing their features
Various input devices showing their featuresVarious input devices showing their features
Various input devices showing their features
 
Android application - Tic Tac Toe
Android application - Tic Tac ToeAndroid application - Tic Tac Toe
Android application - Tic Tac Toe
 

Más de Jussi Pohjolainen

Más de Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Quick Intro to JQuery and JQuery Mobile
Quick Intro to JQuery and JQuery MobileQuick Intro to JQuery and JQuery Mobile
Quick Intro to JQuery and JQuery Mobile
 
JavaScript Inheritance
JavaScript InheritanceJavaScript Inheritance
JavaScript Inheritance
 
JS OO and Closures
JS OO and ClosuresJS OO and Closures
JS OO and Closures
 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
 
XAMPP
XAMPPXAMPP
XAMPP
 
Building Web Services
Building Web ServicesBuilding Web Services
Building Web Services
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

libGDX: User Input

  • 1. libGDX: User Input Jussi Pohjolainen Tampere University of Applied Sciences
  • 3. Event vs Polling • Polling – Do something on each frame, really fast – Was mouse clicked? Was mouse clicked? Was mouse clicked? – Good for arcade games • Event – Do something when event handles – NoIfy when mouse was clicked – UI elements such as buJons • Mouse / touch / keyboard can be received either polling or event handling
  • 4. public class MyInputProcessor implements InputProcessor { @Override public boolean keyDown (int keycode) { return false; } @Override public boolean keyUp (int keycode) { return false; } @Override public boolean keyTyped (char character) { return false; } @Override public boolean touchDown (int x, int y, int pointer, int button) { return false; } @Override public boolean touchUp (int x, int y, int pointer, int button) { return false; } @Override public boolean touchDragged (int x, int y, int pointer) { return false; } @Override public boolean mouseMoved (int x, int y) { return false; } @Override public boolean scrolled (int amount) { return false; } } MyInputProcessor inputProcessor = new MyInputProcessor(); Gdx.input.setInputProcessor(inputProcessor);
  • 5. Polling Touch / Keyboard • For most arcade games, polling is good • MulItouch is supported! – boolean firstFingerTouching = Gdx.input.isTouched(0); – boolean secondFingerTouching = Gdx.input.isTouched(1); – int firstX = Gdx.input.getX(); – int firstY = Gdx.input.getY(); – int secondX = Gdx.input.getX(1); – int secondY = Gdx.input.getY(1); • Keyboard – boolean isAPressed = Gdx.input.isKeyPressed(Keys.A);
  • 7. Accelerometer • An accelerometer measures the acceleraIon of a device on three axes • From this acceleraIon one can derive the Ilt or orientaIon of the device. – Phones: portrait default – Tablet: landscape default • LibGDX shows accelerometer readings always as in the image
  • 8. Accelerometer y (0,0) Accelerometer x y increments x increments
  • 9. Accelerometer Readings • Accelerometer readings can be accessed – float accelX = Gdx.input.getAccelerometerX(); – float accelY = Gdx.input.getAccelerometerY(); – float accelZ = Gdx.input.getAccelerometerZ(); • When moving and if in landscape mode in android, noIce X vs Y! – speedX += Gdx.input.getAccelerometerY();
  • 11. GestureDetector • TouchDown • LongPress • Tap • Pan – Useful for camera panning in 2D • PanStop • Fling • Zoom – Camera zooming • Pinch – Camera zooming + rotaIon
  • 12. StarIng to Listen to Gestures • Really easy – Gdx.input.setInputProcessor(new GestureDetector(new MyGestureListener())); • MyGestureListener is some class that implements GestureListener
  • 13. public class MyGestureListener implements GestureListener { @Override public boolean touchDown(float x, float y, int pointer, int button) {} @Override public boolean tap(float x, float y, int count, int button) {} @Override public boolean longPress(float x, float y) {} @Override public boolean fling(float velocityX, float velocityY, int button) {} @Override public boolean pan(float x, float y, float deltaX, float deltaY) {} @Override public boolean panStop(float x, float y, int pointer, int button) {} @Override public boolean zoom (float originalDistance, float currentDistance){} @Override public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer){} }
  • 15. User input • Desktop – Swing dialog • Android – Android dialog • Use TextInputListener – MyTextInputListener listener = new MyTextInputListener(); – Gdx.input.getTextInput(listener, "Dialog Title", "Initial Textfield Value")
  • 16. public class MyTextInputListener implements TextInputListener { @Override public void input (String text) { } @Override public void canceled () { } }
  • 17. MISC
  • 18. • Vibra – Gdx.input.vibrate(2000); – Remember to add permissions • Compass – float azimuth = Gdx.input.getAzimuth(); – float pitch = Gdx.input.getPitch(); – float roll = Gdx.input.getRoll();