SlideShare a Scribd company logo
1 of 12
Download to read offline
libGDX: 
Simple 
Anima0on 
Jussi 
Pohjolainen 
Tampere 
University 
of 
Applied 
Sciences
FRAMERATE 
INDEPENDENCE
Framerate 
Indepence 
• Games 
run 
at 
same 
speed 
no 
ma6er 
the 
framerate 
• In 
slow 
computers; 
30 
fps, 
fast 
computers 
60 
fps 
– No 
need 
to 
go 
over 
60 
fps.. 
• Example 
– Fast 
computer, 
60 
fps, 
move 
object 
1 
px 
at 
a 
=me 
– Slow 
computer, 
30 
fps, 
move 
object 
2 
px 
at 
a 
=me 
– => 
constant 
speed 
no 
maNer 
the 
framerate! 
• The 
key 
to 
framerate 
indepence 
is 
delta-­‐'me 
– Time 
in 
seconds 
since 
the 
last 
0ck 
(last 
render() 
call) 
• 100 
fps 
=> 
1/100 
=> 
0.01 
dt
Moving 
Object 
• At 
30 
fps 
vs 
60 
fps 
this 
object 
will 
move 
at 
different 
speeds 
– int speedX = 1; 
– batch.draw(texture, x += speedX, 0); 
• This 
will 
move 
the 
object 
at 
constant 
speed 
regardless 
of 
fps 
– int speedX = 60; 
– batch.draw(texture, x += speedX * deltaTime, 0); 
• If 
fps 
60, 
deltaTime 
60/1 
= 
0.0166 
secs 
– x += 60 * 0.016666, x += 1 
• If 
fps 
30, 
deltaTime 
30/1 
= 
0.0333 
secs 
– x += 60 * 0.033333, x += 2
libGDX, 
delta 
and 
fps 
• Querying 
FPS 
– Gdx.graphics.getFramesPerSecond() 
• Querying 
Delta 
– Gdx.graphics.getDeltaTime()
Anima0on 
• Use 
Anima0on 
class 
– Animation walkAnimation = new 
Animation(frameDuration, frames); 
• Frame 
dura0on? 
1 
/ 
60 
fps 
• Frames? 
– TextureRegion 
array 
• TextureRegion? 
– Part 
of 
texture
TextureRegion
Split 
.png 
into 
TextureRegions 
walkSheet = new Texture(Gdx.files.internal(”image.png")); 
TextureRegion[][] tmp = TextureRegion.split( 
walkSheet, 
walkSheet.getWidth() / FRAME_COLS, 
walkSheet.getHeight() / FRAME_ROWS );
2D 
array 
-­‐> 
1D 
private TextureRegion[] transformTo1D(TextureRegion[][] tmp) { 
TextureRegion [] walkFrames 
= new TextureRegion[FRAME_COLS * FRAME_ROWS]; 
int index = 0; 
for (int i = 0; i < FRAME_ROWS; i++) { 
for (int j = 0; j < FRAME_COLS; j++) { 
walkFrames[index++] = tmp[i][j]; 
} 
} 
return walkFrames; 
}
Rendering 
public void render() { 
// stateTime was initialized to 0.0f 
stateTime += Gdx.graphics.getDeltaTime(); 
// stateTime is used to calculate the next frame 
// frameDuration! 
currentFrame = walkAnimation.getKeyFrame(stateTime, true); 
spriteBatch.begin(); 
spriteBatch.draw(currentFrame, 150, 150); 
spriteBatch.end(); 
}
TIPS
Extend 
Sprites 
• For 
each 
Sprite 
in 
screen, 
create 
own 
class 
– class 
Monster 
extends 
Sprite 
• Add 
Monster 
aNributes 
like 
– speedX, 
speedY, 
sounds, 
… 
• If 
using 
anima0on 
(previous 
slides) 
you 
could 
create 
animate() 
method 
which 
is 
called 
from 
the 
game 
on 
every 
frame 
• When 
crea0ng 
the 
Sprite, 
remember 
to 
call 
also 
setRegion 
to 
set 
the 
ini0al 
region 
for 
the 
sprite

More Related Content

What's hot

Unity遊戲程式設計(15) 實作Space shooter遊戲
Unity遊戲程式設計(15) 實作Space shooter遊戲Unity遊戲程式設計(15) 實作Space shooter遊戲
Unity遊戲程式設計(15) 實作Space shooter遊戲吳錫修 (ShyiShiou Wu)
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming TutorialRichard Jones
 
Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019Unity Technologies
 
The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 36 of 84The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 36 of 84Mahmoud Samir Fayed
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
Breathing the life into the canvas
Breathing the life into the canvasBreathing the life into the canvas
Breathing the life into the canvasTomislav Homan
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88Mahmoud Samir Fayed
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Gameslivedoor
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded GraphicsAdil Jafri
 
Students to Business Day 2012: Rob Miles
Students to Business Day 2012: Rob MilesStudents to Business Day 2012: Rob Miles
Students to Business Day 2012: Rob MilesFrederik De Bruyne
 
Optimizing Games for Mobiles
Optimizing Games for MobilesOptimizing Games for Mobiles
Optimizing Games for MobilesSt1X
 
Chapter ii(coding)
Chapter ii(coding)Chapter ii(coding)
Chapter ii(coding)Chhom Karath
 
Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲吳錫修 (ShyiShiou Wu)
 

What's hot (20)

Unity programming 1
Unity programming 1Unity programming 1
Unity programming 1
 
Unity遊戲程式設計(15) 實作Space shooter遊戲
Unity遊戲程式設計(15) 實作Space shooter遊戲Unity遊戲程式設計(15) 實作Space shooter遊戲
Unity遊戲程式設計(15) 實作Space shooter遊戲
 
Python book
Python bookPython book
Python book
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
Real life XNA
Real life XNAReal life XNA
Real life XNA
 
Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019
 
The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 36 of 84The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.2 book - Part 36 of 84
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
Breathing the life into the canvas
Breathing the life into the canvasBreathing the life into the canvas
Breathing the life into the canvas
 
Developing games for Series 40 full-touch UI
Developing games for Series 40 full-touch UIDeveloping games for Series 40 full-touch UI
Developing games for Series 40 full-touch UI
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
 
Students to Business Day 2012: Rob Miles
Students to Business Day 2012: Rob MilesStudents to Business Day 2012: Rob Miles
Students to Business Day 2012: Rob Miles
 
Optimizing Games for Mobiles
Optimizing Games for MobilesOptimizing Games for Mobiles
Optimizing Games for Mobiles
 
Chapter ii(coding)
Chapter ii(coding)Chapter ii(coding)
Chapter ii(coding)
 
Qt Animation
Qt AnimationQt Animation
Qt Animation
 
Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲Unity遊戲程式設計 - 2D Platformer遊戲
Unity遊戲程式設計 - 2D Platformer遊戲
 

Viewers also liked

Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overheadCass Everitt
 
McKonly & Asbury Webinar - Maximizing Community Impact Through EITC
McKonly & Asbury Webinar - Maximizing Community Impact Through EITCMcKonly & Asbury Webinar - Maximizing Community Impact Through EITC
McKonly & Asbury Webinar - Maximizing Community Impact Through EITCMcKonly & Asbury, LLP
 
How to Spot and Cope with Emerging Transitions in Complex Systems for Organiz...
How to Spot and Cope with Emerging Transitions in Complex Systems for Organiz...How to Spot and Cope with Emerging Transitions in Complex Systems for Organiz...
How to Spot and Cope with Emerging Transitions in Complex Systems for Organiz...Eric Garland
 
わかる英文法 Grammar in Use Unit 16 haveとhave got
わかる英文法 Grammar in Use Unit 16 haveとhave gotわかる英文法 Grammar in Use Unit 16 haveとhave got
わかる英文法 Grammar in Use Unit 16 haveとhave gotiacer
 
What to see in Hua Hin.
What to see in Hua Hin. What to see in Hua Hin.
What to see in Hua Hin. Buddhi Dayan
 
2013 PAR Partner conference - Marketing 101
2013 PAR Partner conference - Marketing 1012013 PAR Partner conference - Marketing 101
2013 PAR Partner conference - Marketing 101Emily Massaglia
 
Fotografia matemàtica
Fotografia matemàticaFotografia matemàtica
Fotografia matemàticaa8027973
 
輕囊方能致遠
輕囊方能致遠輕囊方能致遠
輕囊方能致遠Hk Ddm
 
Proyecto de marketing vergara, vargas, bautista
Proyecto de marketing vergara, vargas, bautistaProyecto de marketing vergara, vargas, bautista
Proyecto de marketing vergara, vargas, bautistaJuan Luciano Bauver
 
Limit Strength Prediction of Light Gauge Steel I Section by Finite Element Me...
Limit Strength Prediction of Light Gauge Steel I Section by Finite Element Me...Limit Strength Prediction of Light Gauge Steel I Section by Finite Element Me...
Limit Strength Prediction of Light Gauge Steel I Section by Finite Element Me...IJERA Editor
 
A Decision tree and Conditional Median Filter Based Denoising for impulse noi...
A Decision tree and Conditional Median Filter Based Denoising for impulse noi...A Decision tree and Conditional Median Filter Based Denoising for impulse noi...
A Decision tree and Conditional Median Filter Based Denoising for impulse noi...IJERA Editor
 
¡Felices fiestas, San José! Por unas fiestas libres, alegres y seguras. NO ES NO
¡Felices fiestas, San José! Por unas fiestas libres, alegres y seguras. NO ES NO¡Felices fiestas, San José! Por unas fiestas libres, alegres y seguras. NO ES NO
¡Felices fiestas, San José! Por unas fiestas libres, alegres y seguras. NO ES NOAVVSANJOSE
 
The 2015 Global Women Entrepreneur Leaders Scorecard: Focus on LATAM and the ...
The 2015 Global Women Entrepreneur Leaders Scorecard: Focus on LATAM and the ...The 2015 Global Women Entrepreneur Leaders Scorecard: Focus on LATAM and the ...
The 2015 Global Women Entrepreneur Leaders Scorecard: Focus on LATAM and the ...Ruta Aidis
 
Cestujeme po čr jirásková
Cestujeme po čr jiráskováCestujeme po čr jirásková
Cestujeme po čr jiráskovájiraskova
 
La gestione del processo fotografico
La gestione del processo fotograficoLa gestione del processo fotografico
La gestione del processo fotograficoEnrico Agatoli
 

Viewers also liked (20)

Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overhead
 
McKonly & Asbury Webinar - Maximizing Community Impact Through EITC
McKonly & Asbury Webinar - Maximizing Community Impact Through EITCMcKonly & Asbury Webinar - Maximizing Community Impact Through EITC
McKonly & Asbury Webinar - Maximizing Community Impact Through EITC
 
10 3 мalta_2014_25_03_2014
10 3 мalta_2014_25_03_201410 3 мalta_2014_25_03_2014
10 3 мalta_2014_25_03_2014
 
How to Spot and Cope with Emerging Transitions in Complex Systems for Organiz...
How to Spot and Cope with Emerging Transitions in Complex Systems for Organiz...How to Spot and Cope with Emerging Transitions in Complex Systems for Organiz...
How to Spot and Cope with Emerging Transitions in Complex Systems for Organiz...
 
Channel Power Game
Channel Power GameChannel Power Game
Channel Power Game
 
Habitat El Salvador 08 09 Annual Report
Habitat El Salvador 08 09 Annual ReportHabitat El Salvador 08 09 Annual Report
Habitat El Salvador 08 09 Annual Report
 
Dennis Crowley - Foursquare
Dennis Crowley - FoursquareDennis Crowley - Foursquare
Dennis Crowley - Foursquare
 
わかる英文法 Grammar in Use Unit 16 haveとhave got
わかる英文法 Grammar in Use Unit 16 haveとhave gotわかる英文法 Grammar in Use Unit 16 haveとhave got
わかる英文法 Grammar in Use Unit 16 haveとhave got
 
What to see in Hua Hin.
What to see in Hua Hin. What to see in Hua Hin.
What to see in Hua Hin.
 
2013 PAR Partner conference - Marketing 101
2013 PAR Partner conference - Marketing 1012013 PAR Partner conference - Marketing 101
2013 PAR Partner conference - Marketing 101
 
Fotografia matemàtica
Fotografia matemàticaFotografia matemàtica
Fotografia matemàtica
 
輕囊方能致遠
輕囊方能致遠輕囊方能致遠
輕囊方能致遠
 
Proyecto de marketing vergara, vargas, bautista
Proyecto de marketing vergara, vargas, bautistaProyecto de marketing vergara, vargas, bautista
Proyecto de marketing vergara, vargas, bautista
 
Limit Strength Prediction of Light Gauge Steel I Section by Finite Element Me...
Limit Strength Prediction of Light Gauge Steel I Section by Finite Element Me...Limit Strength Prediction of Light Gauge Steel I Section by Finite Element Me...
Limit Strength Prediction of Light Gauge Steel I Section by Finite Element Me...
 
A Decision tree and Conditional Median Filter Based Denoising for impulse noi...
A Decision tree and Conditional Median Filter Based Denoising for impulse noi...A Decision tree and Conditional Median Filter Based Denoising for impulse noi...
A Decision tree and Conditional Median Filter Based Denoising for impulse noi...
 
¡Felices fiestas, San José! Por unas fiestas libres, alegres y seguras. NO ES NO
¡Felices fiestas, San José! Por unas fiestas libres, alegres y seguras. NO ES NO¡Felices fiestas, San José! Por unas fiestas libres, alegres y seguras. NO ES NO
¡Felices fiestas, San José! Por unas fiestas libres, alegres y seguras. NO ES NO
 
The 2015 Global Women Entrepreneur Leaders Scorecard: Focus on LATAM and the ...
The 2015 Global Women Entrepreneur Leaders Scorecard: Focus on LATAM and the ...The 2015 Global Women Entrepreneur Leaders Scorecard: Focus on LATAM and the ...
The 2015 Global Women Entrepreneur Leaders Scorecard: Focus on LATAM and the ...
 
Cestujeme po čr jirásková
Cestujeme po čr jiráskováCestujeme po čr jirásková
Cestujeme po čr jirásková
 
Sample 1
Sample 1Sample 1
Sample 1
 
La gestione del processo fotografico
La gestione del processo fotograficoLa gestione del processo fotografico
La gestione del processo fotografico
 

Similar to libGDX: Simple Frame Animation

Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014Jarosław Pleskot
 
Computer Animation.pptx
Computer Animation.pptxComputer Animation.pptx
Computer Animation.pptxRAJESH S
 
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
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture MappingMark Kilgard
 
PlayStation: Cutting Edge Techniques
PlayStation: Cutting Edge TechniquesPlayStation: Cutting Edge Techniques
PlayStation: Cutting Edge TechniquesSlide_N
 
Simple, fast, and scalable torch7 tutorial
Simple, fast, and scalable torch7 tutorialSimple, fast, and scalable torch7 tutorial
Simple, fast, and scalable torch7 tutorialJin-Hwa Kim
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupdreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupbernice-chan
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for SpeedYung-Yu Chen
 
Benoit fouletier guillaume martin unity day- modern 2 d techniques-gce2014
Benoit fouletier guillaume martin   unity day- modern 2 d techniques-gce2014Benoit fouletier guillaume martin   unity day- modern 2 d techniques-gce2014
Benoit fouletier guillaume martin unity day- modern 2 d techniques-gce2014Mary Chan
 
Monogame and xna
Monogame and xnaMonogame and xna
Monogame and xnaLee Stott
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.jsjeresig
 
Structure Unstructured Data
Structure Unstructured DataStructure Unstructured Data
Structure Unstructured DataCarmine Paolino
 

Similar to libGDX: Simple Frame Animation (20)

Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick components
 
Scmad Chapter07
Scmad Chapter07Scmad Chapter07
Scmad Chapter07
 
Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014
 
Computer Animation.pptx
Computer Animation.pptxComputer Animation.pptx
Computer Animation.pptx
 
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
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture Mapping
 
PlayStation: Cutting Edge Techniques
PlayStation: Cutting Edge TechniquesPlayStation: Cutting Edge Techniques
PlayStation: Cutting Edge Techniques
 
14709302.ppt
14709302.ppt14709302.ppt
14709302.ppt
 
Simple, fast, and scalable torch7 tutorial
Simple, fast, and scalable torch7 tutorialSimple, fast, and scalable torch7 tutorial
Simple, fast, and scalable torch7 tutorial
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
Benoit fouletier guillaume martin unity day- modern 2 d techniques-gce2014
Benoit fouletier guillaume martin   unity day- modern 2 d techniques-gce2014Benoit fouletier guillaume martin   unity day- modern 2 d techniques-gce2014
Benoit fouletier guillaume martin unity day- modern 2 d techniques-gce2014
 
Monogame and xna
Monogame and xnaMonogame and xna
Monogame and xna
 
MIDP: Game API
MIDP: Game APIMIDP: Game API
MIDP: Game API
 
Intro to Canva
Intro to CanvaIntro to Canva
Intro to Canva
 
Processing and Processing.js
Processing and Processing.jsProcessing and Processing.js
Processing and Processing.js
 
XNA L05–Texturing
XNA L05–TexturingXNA L05–Texturing
XNA L05–Texturing
 
Structure Unstructured Data
Structure Unstructured DataStructure Unstructured Data
Structure Unstructured Data
 

More from Jussi Pohjolainen

More from 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
 
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
 
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
 
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
 
CSS
CSSCSS
CSS
 

Recently uploaded

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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 

Recently uploaded (20)

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...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 

libGDX: Simple Frame Animation

  • 1. libGDX: Simple Anima0on Jussi Pohjolainen Tampere University of Applied Sciences
  • 3. Framerate Indepence • Games run at same speed no ma6er the framerate • In slow computers; 30 fps, fast computers 60 fps – No need to go over 60 fps.. • Example – Fast computer, 60 fps, move object 1 px at a =me – Slow computer, 30 fps, move object 2 px at a =me – => constant speed no maNer the framerate! • The key to framerate indepence is delta-­‐'me – Time in seconds since the last 0ck (last render() call) • 100 fps => 1/100 => 0.01 dt
  • 4. Moving Object • At 30 fps vs 60 fps this object will move at different speeds – int speedX = 1; – batch.draw(texture, x += speedX, 0); • This will move the object at constant speed regardless of fps – int speedX = 60; – batch.draw(texture, x += speedX * deltaTime, 0); • If fps 60, deltaTime 60/1 = 0.0166 secs – x += 60 * 0.016666, x += 1 • If fps 30, deltaTime 30/1 = 0.0333 secs – x += 60 * 0.033333, x += 2
  • 5. libGDX, delta and fps • Querying FPS – Gdx.graphics.getFramesPerSecond() • Querying Delta – Gdx.graphics.getDeltaTime()
  • 6. Anima0on • Use Anima0on class – Animation walkAnimation = new Animation(frameDuration, frames); • Frame dura0on? 1 / 60 fps • Frames? – TextureRegion array • TextureRegion? – Part of texture
  • 8. Split .png into TextureRegions walkSheet = new Texture(Gdx.files.internal(”image.png")); TextureRegion[][] tmp = TextureRegion.split( walkSheet, walkSheet.getWidth() / FRAME_COLS, walkSheet.getHeight() / FRAME_ROWS );
  • 9. 2D array -­‐> 1D private TextureRegion[] transformTo1D(TextureRegion[][] tmp) { TextureRegion [] walkFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS]; int index = 0; for (int i = 0; i < FRAME_ROWS; i++) { for (int j = 0; j < FRAME_COLS; j++) { walkFrames[index++] = tmp[i][j]; } } return walkFrames; }
  • 10. Rendering public void render() { // stateTime was initialized to 0.0f stateTime += Gdx.graphics.getDeltaTime(); // stateTime is used to calculate the next frame // frameDuration! currentFrame = walkAnimation.getKeyFrame(stateTime, true); spriteBatch.begin(); spriteBatch.draw(currentFrame, 150, 150); spriteBatch.end(); }
  • 11. TIPS
  • 12. Extend Sprites • For each Sprite in screen, create own class – class Monster extends Sprite • Add Monster aNributes like – speedX, speedY, sounds, … • If using anima0on (previous slides) you could create animate() method which is called from the game on every frame • When crea0ng the Sprite, remember to call also setRegion to set the ini0al region for the sprite