SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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)
 

Was ist angesagt? (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遊戲
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Jussi Pohjolainen

Mehr von 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
 

Kürzlich hochgeladen

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
[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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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)
 
[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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

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