SlideShare a Scribd company logo
libGDX:	
  Tiled	
  Maps	
  
Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
CREATING	
  TILED	
  MAPS	
  
	
  
Tiled	
  Maps	
  
Tiled	
  Editor:	
  Tiled	
  
•  EdiBng	
  tools	
  for	
  stamp,	
  fill	
  and	
  terrain	
  brushes	
  
•  Rectangle,	
  ellipse,	
  polygon	
  and	
  image	
  objects	
  
can	
  be	
  placed	
  
•  Support	
  for	
  orthogonal,	
  isometric	
  and	
  
staggered	
  maps	
  
•  Download:	
  http://www.mapeditor.org/
Isometric	
  (3D	
  effect)	
  
Isometric	
  vs	
  Isometric	
  staggered	
  
Create	
  Blesheet	
  png	
  
CreaBng	
  new	
  Map	
  
Layers	
  
•  Your	
  world	
  may	
  contain	
  layers	
  
•  You	
  can	
  disable	
  and	
  enable	
  layers	
  during	
  
runBme	
  
•  You	
  can	
  add	
  object	
  layers	
  for	
  easy	
  collision	
  
detec@on	
  
USING	
  MAPS	
  
Loading	
  Map	
  
•  To	
  load	
  a	
  map	
  
– TiledMap tiledMap = tiledMap = new
TmxMapLoader().load("runner.tmx");
•  To	
  render	
  a	
  map,	
  use	
  TiledMapRenderer	
  
– TiledMapRenderer tiledMapRenderer = new
OrthogonalTiledMapRenderer(tiledMap);
Render	
  and	
  Camera	
  
@Override
public void render () {
batch.setProjectionMatrix(camera.combined);
// Sets the projection matrix and viewbounds from the given
// camera. If the camera changes, you have to call this method
// again. The viewbounds are taken from the camera's
// position and viewport size as well as the scale.
tiledMapRenderer.setView(camera);
// Render all layers to screen.
tiledMapRenderer.render();
}
MOVE	
  CAMERA	
  
Render	
  and	
  Camera	
  
@Override
public void render () {
batch.setProjectionMatrix(camera.combined);
// move camera (YOU HAVE TO IMPLEMENT THIS)
moveCamera();
// Update camera movement
camera.update();
// Which part of the map are we looking? Use camera's viewport
tiledMapRenderer.setView(camera);
// Render all layers to screen.
tiledMapRenderer.render();
}
moveCamera()
public void moveCamera() {
// Lot of possibilities.
// 1) Just move the camera to some direction:
camera.translate(1,0); // moves x++
// 2) Move to certain point
camera.position.x = 200;
// 3) Move to direction of some sprite
camera.position.x = player.getX();
}
COLLISION	
  DETECTION	
  
Collision	
  Checking	
  
/**
* Checks if player has collided with collectable
*/
private void checkCollisions() {
// Let's get the collectable rectangles layer
MapLayer collisionObjectLayer = (MapLayer)tiledMap.getLayers().get("collectable-rectangles");
// All the rectangles of the layer
MapObjects mapObjects = collisionObjectLayer.getObjects();
// Cast it to RectangleObjects array
Array<RectangleMapObject> rectangleObjects = mapObjects.getByType(RectangleMapObject.class);
// Iterate all the rectangles
for (RectangleMapObject rectangleObject : rectangleObjects) {
Rectangle rectangle = rectangleObject.getRectangle();
if (playerSprite.getBoundingRectangle().overlaps(rectangle)) {
clearCollectable();
}
}
}
MOVING	
  OBJECT	
  
0,0	
  
32px	
  
32px	
  
32,32	
  
32,32	
  
1.	
  Arrow	
  key	
  right	
  pressed	
  
2.	
  Movement	
  x	
  =	
  x	
  +	
  5	
  
37,32	
  
1.	
  Arrow	
  key	
  right	
  pressed	
  
2.	
  Movement	
  x	
  =	
  x	
  +	
  5	
  
3.	
  Crash!	
  
37,32	
  
if	
  x	
  =	
  x	
  +	
  5	
  does	
  not	
  
collide	
  with	
  background	
  
Does	
  37,32	
  collide?	
  
37,32	
  
We	
  need	
  to	
  check	
  
each	
  corner!	
  
69,32	
  !!	
  
69,64	
  37,64	
  
37,32	
  
Check	
  if	
  the	
  next	
  frame	
  
collides	
  with	
  bg.	
  If	
  not,	
  
move	
  to	
  next	
  frame	
  
69,32	
  !!	
  
69,64	
  37,64	
  
37,32	
  
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)	
  &&	
  	
  
	
  	
  	
  !upRightCollision	
  &&	
  !downRightCollision)	
  {	
  
	
  
	
  	
  	
  	
  //	
  try	
  to	
  move	
  player	
  to	
  right	
  
	
  	
  	
  //	
  this	
  is	
  NOT	
  done,	
  since	
  
	
  	
  	
  //	
  !downRightCollision	
  is	
  false!	
  
	
  	
  	
  	
  playerSprite.translateX(-­‐1	
  *	
  moveAmount);	
  
}	
  
69,32	
  !!	
  
69,64	
  37,64	
  
ConverBng	
  Sprite	
  posiBon	
  to	
  Tiled	
  
Map	
  index	
  
32px	
  
32px	
  
250,120	
  
0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  5	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  6	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  7	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  8	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  9	
  
8	
  
7	
  
6	
  
5	
  
4	
  
3	
  
2	
  
1	
  
0	
  
ConverBng	
  Sprite	
  posiBon	
  to	
  Tiled	
  
Map	
  index	
  
32px	
  
32px	
  
250	
  /	
  32	
  =	
  7.8	
  -­‐>	
  7	
  
120	
  /	
  32	
  =	
  3.8	
  -­‐>	
  3	
  
0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  3	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  4	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  5	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  6	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  7	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  8	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  9	
  
8	
  
7	
  
6	
  
5	
  
4	
  
3	
  
2	
  
1	
  
0	
  
isFree	
  -­‐	
  method	
  
private boolean isFree(float x, float y) {
// Calculate coordinates to tile coordinates
// example, (34,34) => (1,1)
int indexX = (int) x / TILE_WIDTH;
int indexY = (int) y / TILE_HEIGHT;
TiledMapTileLayer wallCells = (TiledMapTileLayer)
tiledMap.getLayers().get("wall-layer");
// Is the coordinate / cell free?
if(wallCells.getCell(indexX, indexY) != null) {
// There was a cell, it's not free
return false;
} else {
// There was no cell, it's free
return true;
}
}
Checking	
  all	
  Corners	
  
upleft = isFree(leftXPos, upYPos); // true
downleft = isFree(leftXPos, downYPos); // true
upright = isFree(rightXPos, upYPos); // true
downright = isFree(rightXPos, downYPos); // false
37,32	
  
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)	
  &&	
  	
  
	
  	
  	
  !upRightCollision	
  &&	
  !downRightCollision)	
  {	
  
	
  
	
  	
  	
  	
  //	
  try	
  to	
  move	
  player	
  to	
  right	
  
	
  	
  	
  //	
  this	
  is	
  NOT	
  done,	
  since	
  
	
  	
  	
  //	
  !downRightCollision	
  is	
  false!	
  
	
  	
  	
  	
  playerSprite.translateX(-­‐1	
  *	
  moveAmount);	
  
}	
  
69,32	
  !!	
  
69,64	
  37,64	
  
getMyCorners	
  
public void getMyCorners(float pX, float pY) {
// calculate all the corners of the sprite
float downYPos = pY;
float upYPos = playerSprite.getHeight() + downYPos;
float leftXPos = pX;
float rightXPos = playerSprite.getWidth() + leftXPos;
// update the attributes
upleft = isFree(leftXPos, upYPos);
downleft = isFree(leftXPos, downYPos);
upright = isFree(rightXPos, upYPos);
downright = isFree(rightXPos, downYPos);
}
movePlayer	
  
private void movePlayer(float delta) {
// moveAmount
float moveAmount = SPEED * delta;
// Is there Room in left? THIS
// modifies the upleft, downleft, upright and upleft attributes!
getMyCorners(playerSprite.getX() + -1 * moveAmount,
playerSprite.getY());
// Move left IF there is room!
if(Gdx.input.isKeyPressed(Input.Keys.LEFT) &&
playerSprite.getX() > TILE_WIDTH &&
upleft && downleft) {
playerSprite.translateX(-1 * moveAmount);
}
...
Ad

More Related Content

What's hot (20)

Human Pose Estimation by Deep Learning
Human Pose Estimation by Deep LearningHuman Pose Estimation by Deep Learning
Human Pose Estimation by Deep Learning
Wei Yang
 
Neural Scene Representation & Rendering: Introduction to Novel View Synthesis
Neural Scene Representation & Rendering: Introduction to Novel View SynthesisNeural Scene Representation & Rendering: Introduction to Novel View Synthesis
Neural Scene Representation & Rendering: Introduction to Novel View Synthesis
Vincent Sitzmann
 
Pr045 deep lab_semantic_segmentation
Pr045 deep lab_semantic_segmentationPr045 deep lab_semantic_segmentation
Pr045 deep lab_semantic_segmentation
Taeoh Kim
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
rehaniltifat
 
Tutorial on Generalization in Neural Fields, CVPR 2022 Tutorial on Neural Fie...
Tutorial on Generalization in Neural Fields, CVPR 2022 Tutorial on Neural Fie...Tutorial on Generalization in Neural Fields, CVPR 2022 Tutorial on Neural Fie...
Tutorial on Generalization in Neural Fields, CVPR 2022 Tutorial on Neural Fie...
Vincent Sitzmann
 
Self Organizing Maps
Self Organizing MapsSelf Organizing Maps
Self Organizing Maps
Daksh Raj Chopra
 
Transformer in Vision
Transformer in VisionTransformer in Vision
Transformer in Vision
Sangmin Woo
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
Talha Ocakçı
 
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
nemoux
 
Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...
Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...
Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...
changedaeoh
 
Yolo
YoloYolo
Yolo
Sourav Garai
 
ViT (Vision Transformer) Review [CDM]
ViT (Vision Transformer) Review [CDM]ViT (Vision Transformer) Review [CDM]
ViT (Vision Transformer) Review [CDM]
Dongmin Choi
 
You only look once
You only look onceYou only look once
You only look once
Gin Kyeng Lee
 
Reinforcement Learning with Deep Energy-Based Policies
Reinforcement Learning with Deep Energy-Based PoliciesReinforcement Learning with Deep Energy-Based Policies
Reinforcement Learning with Deep Energy-Based Policies
Sangwoo Mo
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
Deepthi Rachumallu
 
ConvNeXt: A ConvNet for the 2020s explained
ConvNeXt: A ConvNet for the 2020s explainedConvNeXt: A ConvNet for the 2020s explained
ConvNeXt: A ConvNet for the 2020s explained
Sushant Gautam
 
How to make multi level hierarchical picklists in Siebel
How to make multi level hierarchical picklists in SiebelHow to make multi level hierarchical picklists in Siebel
How to make multi level hierarchical picklists in Siebel
David Boukhors
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
Mark Kilgard
 
Yurii Pashchenko: Zero-shot learning capabilities of CLIP model from OpenAI
Yurii Pashchenko: Zero-shot learning capabilities of CLIP model from OpenAIYurii Pashchenko: Zero-shot learning capabilities of CLIP model from OpenAI
Yurii Pashchenko: Zero-shot learning capabilities of CLIP model from OpenAI
Lviv Startup Club
 
Deep Learning for Computer Vision: Object Detection (UPC 2016)
Deep Learning for Computer Vision: Object Detection (UPC 2016)Deep Learning for Computer Vision: Object Detection (UPC 2016)
Deep Learning for Computer Vision: Object Detection (UPC 2016)
Universitat Politècnica de Catalunya
 
Human Pose Estimation by Deep Learning
Human Pose Estimation by Deep LearningHuman Pose Estimation by Deep Learning
Human Pose Estimation by Deep Learning
Wei Yang
 
Neural Scene Representation & Rendering: Introduction to Novel View Synthesis
Neural Scene Representation & Rendering: Introduction to Novel View SynthesisNeural Scene Representation & Rendering: Introduction to Novel View Synthesis
Neural Scene Representation & Rendering: Introduction to Novel View Synthesis
Vincent Sitzmann
 
Pr045 deep lab_semantic_segmentation
Pr045 deep lab_semantic_segmentationPr045 deep lab_semantic_segmentation
Pr045 deep lab_semantic_segmentation
Taeoh Kim
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
rehaniltifat
 
Tutorial on Generalization in Neural Fields, CVPR 2022 Tutorial on Neural Fie...
Tutorial on Generalization in Neural Fields, CVPR 2022 Tutorial on Neural Fie...Tutorial on Generalization in Neural Fields, CVPR 2022 Tutorial on Neural Fie...
Tutorial on Generalization in Neural Fields, CVPR 2022 Tutorial on Neural Fie...
Vincent Sitzmann
 
Transformer in Vision
Transformer in VisionTransformer in Vision
Transformer in Vision
Sangmin Woo
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
Talha Ocakçı
 
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
nemoux
 
Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...
Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...
Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...
changedaeoh
 
ViT (Vision Transformer) Review [CDM]
ViT (Vision Transformer) Review [CDM]ViT (Vision Transformer) Review [CDM]
ViT (Vision Transformer) Review [CDM]
Dongmin Choi
 
Reinforcement Learning with Deep Energy-Based Policies
Reinforcement Learning with Deep Energy-Based PoliciesReinforcement Learning with Deep Energy-Based Policies
Reinforcement Learning with Deep Energy-Based Policies
Sangwoo Mo
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
Deepthi Rachumallu
 
ConvNeXt: A ConvNet for the 2020s explained
ConvNeXt: A ConvNet for the 2020s explainedConvNeXt: A ConvNet for the 2020s explained
ConvNeXt: A ConvNet for the 2020s explained
Sushant Gautam
 
How to make multi level hierarchical picklists in Siebel
How to make multi level hierarchical picklists in SiebelHow to make multi level hierarchical picklists in Siebel
How to make multi level hierarchical picklists in Siebel
David Boukhors
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
Mark Kilgard
 
Yurii Pashchenko: Zero-shot learning capabilities of CLIP model from OpenAI
Yurii Pashchenko: Zero-shot learning capabilities of CLIP model from OpenAIYurii Pashchenko: Zero-shot learning capabilities of CLIP model from OpenAI
Yurii Pashchenko: Zero-shot learning capabilities of CLIP model from OpenAI
Lviv Startup Club
 

Viewers also liked (20)

Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
Jussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
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
Jussi Pohjolainen
 
Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
Jussi Pohjolainen
 
IoT Devices, Which One Is Right for You to Learn?
IoT Devices, Which One Is Right for You to Learn?IoT Devices, Which One Is Right for You to Learn?
IoT Devices, Which One Is Right for You to Learn?
Agustaf Ryadi
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
Jussi Pohjolainen
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
IoT Devices, Which One is Right for You to Learn?
IoT Devices, Which One is Right for You to Learn?IoT Devices, Which One is Right for You to Learn?
IoT Devices, Which One is Right for You to Learn?
CodePolitan
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
Jussi Pohjolainen
 
esp8266 Wifi 4 PIC
esp8266 Wifi 4 PICesp8266 Wifi 4 PIC
esp8266 Wifi 4 PIC
Davide Mercanti
 
关于 Twitter 以及 Twitter 与 NGO2.0
关于 Twitter 以及 Twitter 与 NGO2.0关于 Twitter 以及 Twitter 与 NGO2.0
关于 Twitter 以及 Twitter 与 NGO2.0
刘 勇
 
Where can tell me who I am?
Where can tell me who I am?Where can tell me who I am?
Where can tell me who I am?
seltzoid
 
1886 6445-1-pb
1886 6445-1-pb1886 6445-1-pb
1886 6445-1-pb
Rogério Gonçalves
 
Ies electrical-engineering-paper-2-2005
Ies electrical-engineering-paper-2-2005Ies electrical-engineering-paper-2-2005
Ies electrical-engineering-paper-2-2005
Venugopala Rao P
 
Pppp
PpppPppp
Pppp
romeolavares
 
China Optical Expo on Barter
China Optical Expo on BarterChina Optical Expo on Barter
China Optical Expo on Barter
Daniel Evans
 
Samuel quero laplace
Samuel quero laplaceSamuel quero laplace
Samuel quero laplace
samuelquero
 
The Building Blocks of Great Video
The Building Blocks of Great VideoThe Building Blocks of Great Video
The Building Blocks of Great Video
Phil Nottingham
 
Talv
TalvTalv
Talv
piiak
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
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
Jussi Pohjolainen
 
IoT Devices, Which One Is Right for You to Learn?
IoT Devices, Which One Is Right for You to Learn?IoT Devices, Which One Is Right for You to Learn?
IoT Devices, Which One Is Right for You to Learn?
Agustaf Ryadi
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
IoT Devices, Which One is Right for You to Learn?
IoT Devices, Which One is Right for You to Learn?IoT Devices, Which One is Right for You to Learn?
IoT Devices, Which One is Right for You to Learn?
CodePolitan
 
关于 Twitter 以及 Twitter 与 NGO2.0
关于 Twitter 以及 Twitter 与 NGO2.0关于 Twitter 以及 Twitter 与 NGO2.0
关于 Twitter 以及 Twitter 与 NGO2.0
刘 勇
 
Where can tell me who I am?
Where can tell me who I am?Where can tell me who I am?
Where can tell me who I am?
seltzoid
 
Ies electrical-engineering-paper-2-2005
Ies electrical-engineering-paper-2-2005Ies electrical-engineering-paper-2-2005
Ies electrical-engineering-paper-2-2005
Venugopala Rao P
 
China Optical Expo on Barter
China Optical Expo on BarterChina Optical Expo on Barter
China Optical Expo on Barter
Daniel Evans
 
Samuel quero laplace
Samuel quero laplaceSamuel quero laplace
Samuel quero laplace
samuelquero
 
The Building Blocks of Great Video
The Building Blocks of Great VideoThe Building Blocks of Great Video
The Building Blocks of Great Video
Phil Nottingham
 
Talv
TalvTalv
Talv
piiak
 
Ad

Similar to libGDX: Tiled Maps (20)

openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
roxlu
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
contact41
 
Maps
MapsMaps
Maps
boybuon205
 
Mashup caravan android-talks
Mashup caravan android-talksMashup caravan android-talks
Mashup caravan android-talks
honjo2
 
I need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdfI need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdf
Conint29
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
Mark Kilgard
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
TashiBhutia12
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
Paul Smith
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
ganisyedtrd
 
OpenLayers Feature Frenzy
OpenLayers Feature FrenzyOpenLayers Feature Frenzy
OpenLayers Feature Frenzy
Andreas Hocevar
 
OpenGL L07-Skybox and Terrian
OpenGL L07-Skybox and TerrianOpenGL L07-Skybox and Terrian
OpenGL L07-Skybox and Terrian
Mohammad Shaker
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
dandylion13
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
Philip Schwarz
 
XNA L04–Primitives, IndexBuffer and VertexBuffer
XNA L04–Primitives, IndexBuffer and VertexBufferXNA L04–Primitives, IndexBuffer and VertexBuffer
XNA L04–Primitives, IndexBuffer and VertexBuffer
Mohammad Shaker
 
Opensource gis development - part 4
Opensource gis development - part 4Opensource gis development - part 4
Opensource gis development - part 4
Andrea Antonello
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
Jenchoke Tachagomain
 
Covering the earth and the cloud the next generation of spatial in sql server...
Covering the earth and the cloud the next generation of spatial in sql server...Covering the earth and the cloud the next generation of spatial in sql server...
Covering the earth and the cloud the next generation of spatial in sql server...
Texas Natural Resources Information System
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
Jenchoke Tachagomain
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
vidyamittal
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
roxlu
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
contact41
 
Mashup caravan android-talks
Mashup caravan android-talksMashup caravan android-talks
Mashup caravan android-talks
honjo2
 
I need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdfI need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdf
Conint29
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
Mark Kilgard
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
TashiBhutia12
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
Paul Smith
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
ganisyedtrd
 
OpenLayers Feature Frenzy
OpenLayers Feature FrenzyOpenLayers Feature Frenzy
OpenLayers Feature Frenzy
Andreas Hocevar
 
OpenGL L07-Skybox and Terrian
OpenGL L07-Skybox and TerrianOpenGL L07-Skybox and Terrian
OpenGL L07-Skybox and Terrian
Mohammad Shaker
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
dandylion13
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
Philip Schwarz
 
XNA L04–Primitives, IndexBuffer and VertexBuffer
XNA L04–Primitives, IndexBuffer and VertexBufferXNA L04–Primitives, IndexBuffer and VertexBuffer
XNA L04–Primitives, IndexBuffer and VertexBuffer
Mohammad Shaker
 
Opensource gis development - part 4
Opensource gis development - part 4Opensource gis development - part 4
Opensource gis development - part 4
Andrea Antonello
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
Jenchoke Tachagomain
 
Covering the earth and the cloud the next generation of spatial in sql server...
Covering the earth and the cloud the next generation of spatial in sql server...Covering the earth and the cloud the next generation of spatial in sql server...
Covering the earth and the cloud the next generation of spatial in sql server...
Texas Natural Resources Information System
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
Jenchoke Tachagomain
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
vidyamittal
 
Ad

More from Jussi Pohjolainen (20)

Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Jussi Pohjolainen
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
Jussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
Jussi Pohjolainen
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
Jussi Pohjolainen
 
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
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
Jussi Pohjolainen
 
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
Jussi Pohjolainen
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
Jussi Pohjolainen
 
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
Jussi Pohjolainen
 
JavaScript Inheritance
JavaScript InheritanceJavaScript Inheritance
JavaScript Inheritance
Jussi Pohjolainen
 
JS OO and Closures
JS OO and ClosuresJS OO and Closures
JS OO and Closures
Jussi Pohjolainen
 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
Jussi Pohjolainen
 
XAMPP
XAMPPXAMPP
XAMPP
Jussi Pohjolainen
 
Building Web Services
Building Web ServicesBuilding Web Services
Building Web Services
Jussi Pohjolainen
 

Recently uploaded (20)

Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 

libGDX: Tiled Maps

  • 1. libGDX:  Tiled  Maps   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 4. Tiled  Editor:  Tiled   •  EdiBng  tools  for  stamp,  fill  and  terrain  brushes   •  Rectangle,  ellipse,  polygon  and  image  objects   can  be  placed   •  Support  for  orthogonal,  isometric  and   staggered  maps   •  Download:  http://www.mapeditor.org/
  • 6. Isometric  vs  Isometric  staggered  
  • 9. Layers   •  Your  world  may  contain  layers   •  You  can  disable  and  enable  layers  during   runBme   •  You  can  add  object  layers  for  easy  collision   detec@on  
  • 11. Loading  Map   •  To  load  a  map   – TiledMap tiledMap = tiledMap = new TmxMapLoader().load("runner.tmx"); •  To  render  a  map,  use  TiledMapRenderer   – TiledMapRenderer tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
  • 12. Render  and  Camera   @Override public void render () { batch.setProjectionMatrix(camera.combined); // Sets the projection matrix and viewbounds from the given // camera. If the camera changes, you have to call this method // again. The viewbounds are taken from the camera's // position and viewport size as well as the scale. tiledMapRenderer.setView(camera); // Render all layers to screen. tiledMapRenderer.render(); }
  • 14. Render  and  Camera   @Override public void render () { batch.setProjectionMatrix(camera.combined); // move camera (YOU HAVE TO IMPLEMENT THIS) moveCamera(); // Update camera movement camera.update(); // Which part of the map are we looking? Use camera's viewport tiledMapRenderer.setView(camera); // Render all layers to screen. tiledMapRenderer.render(); }
  • 15. moveCamera() public void moveCamera() { // Lot of possibilities. // 1) Just move the camera to some direction: camera.translate(1,0); // moves x++ // 2) Move to certain point camera.position.x = 200; // 3) Move to direction of some sprite camera.position.x = player.getX(); }
  • 17. Collision  Checking   /** * Checks if player has collided with collectable */ private void checkCollisions() { // Let's get the collectable rectangles layer MapLayer collisionObjectLayer = (MapLayer)tiledMap.getLayers().get("collectable-rectangles"); // All the rectangles of the layer MapObjects mapObjects = collisionObjectLayer.getObjects(); // Cast it to RectangleObjects array Array<RectangleMapObject> rectangleObjects = mapObjects.getByType(RectangleMapObject.class); // Iterate all the rectangles for (RectangleMapObject rectangleObject : rectangleObjects) { Rectangle rectangle = rectangleObject.getRectangle(); if (playerSprite.getBoundingRectangle().overlaps(rectangle)) { clearCollectable(); } } }
  • 21. 32,32   1.  Arrow  key  right  pressed   2.  Movement  x  =  x  +  5  
  • 22. 37,32   1.  Arrow  key  right  pressed   2.  Movement  x  =  x  +  5   3.  Crash!  
  • 23. 37,32   if  x  =  x  +  5  does  not   collide  with  background   Does  37,32  collide?  
  • 24. 37,32   We  need  to  check   each  corner!   69,32  !!   69,64  37,64  
  • 25. 37,32   Check  if  the  next  frame   collides  with  bg.  If  not,   move  to  next  frame   69,32  !!   69,64  37,64  
  • 26. 37,32   if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)  &&          !upRightCollision  &&  !downRightCollision)  {            //  try  to  move  player  to  right        //  this  is  NOT  done,  since        //  !downRightCollision  is  false!          playerSprite.translateX(-­‐1  *  moveAmount);   }   69,32  !!   69,64  37,64  
  • 27. ConverBng  Sprite  posiBon  to  Tiled   Map  index   32px   32px   250,120   0                        1                    2                      3                    4                      5                    6                      7                      8                    9   8   7   6   5   4   3   2   1   0  
  • 28. ConverBng  Sprite  posiBon  to  Tiled   Map  index   32px   32px   250  /  32  =  7.8  -­‐>  7   120  /  32  =  3.8  -­‐>  3   0                        1                    2                      3                    4                      5                    6                      7                      8                    9   8   7   6   5   4   3   2   1   0  
  • 29. isFree  -­‐  method   private boolean isFree(float x, float y) { // Calculate coordinates to tile coordinates // example, (34,34) => (1,1) int indexX = (int) x / TILE_WIDTH; int indexY = (int) y / TILE_HEIGHT; TiledMapTileLayer wallCells = (TiledMapTileLayer) tiledMap.getLayers().get("wall-layer"); // Is the coordinate / cell free? if(wallCells.getCell(indexX, indexY) != null) { // There was a cell, it's not free return false; } else { // There was no cell, it's free return true; } }
  • 30. Checking  all  Corners   upleft = isFree(leftXPos, upYPos); // true downleft = isFree(leftXPos, downYPos); // true upright = isFree(rightXPos, upYPos); // true downright = isFree(rightXPos, downYPos); // false
  • 31. 37,32   if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)  &&          !upRightCollision  &&  !downRightCollision)  {            //  try  to  move  player  to  right        //  this  is  NOT  done,  since        //  !downRightCollision  is  false!          playerSprite.translateX(-­‐1  *  moveAmount);   }   69,32  !!   69,64  37,64  
  • 32. getMyCorners   public void getMyCorners(float pX, float pY) { // calculate all the corners of the sprite float downYPos = pY; float upYPos = playerSprite.getHeight() + downYPos; float leftXPos = pX; float rightXPos = playerSprite.getWidth() + leftXPos; // update the attributes upleft = isFree(leftXPos, upYPos); downleft = isFree(leftXPos, downYPos); upright = isFree(rightXPos, upYPos); downright = isFree(rightXPos, downYPos); }
  • 33. movePlayer   private void movePlayer(float delta) { // moveAmount float moveAmount = SPEED * delta; // Is there Room in left? THIS // modifies the upleft, downleft, upright and upleft attributes! getMyCorners(playerSprite.getX() + -1 * moveAmount, playerSprite.getY()); // Move left IF there is room! if(Gdx.input.isKeyPressed(Input.Keys.LEFT) && playerSprite.getX() > TILE_WIDTH && upleft && downleft) { playerSprite.translateX(-1 * moveAmount); } ...