SlideShare uma empresa Scribd logo
1 de 44
Java™Platform, Micro Edition Part 5 – Game API 1 Andreas Jakl, 2009 v3.0a – 19 April 2009
Contents Performance Game API GameCanvas Bitmaps Sprite Layer andTiledLayer LayerManager Andreas Jakl, 2009 2
Benchmarks Take care of performance Multiply a lot faster than divide No hardware floating point support (mostly SW-emulated, available since CLDC 1.1) PC-Emulator no reference for phone performance Performance of different phones can differ a LOT Benchmark results Based on SPMark Java06 Basic Edition http://www.futuremark.com/benchmarks/mobilebenchmarks/ Andreas Jakl, 2009 3
Game Performance Andreas Jakl, 2009 4
Calculation Performance Andreas Jakl, 2009 5
GameCanvas Optimized for game loops Andreas Jakl, 2009 6
Games using a Canvas Andreas Jakl, 2009 7 public void myCanvas extends Canvas implements Runnable {	public void run() { // Main game loop 		while (true) { 			... 			// Do processing 			repaint();		// Request repaint 		} 	} 	public void paint (Graphics g) { // Painting code 	} 	protected void keyPressed (intkeyCode) { // Handle user input 	} } Thread Thread Thread
GameCanvas Andreas Jakl, 2009 8 Display One Display-object per MIDlet Displayable Canvas Screen Graphics Methodsfordrawingtothecanvas / offscreenbuffer GameCanvas High Level UI
Canvas vs. GameCanvas Canvas Keys: sent as events, asynchronous processing Drawing: only in paint()-method, own thread Suited for event-based games and applications GameCanvas Keys: query state in the game loop for every iteration Drawing: everywhere, graphics shown when calling flushGraphics() from GameLoop (Both new features are optional in the GameCanvas!) Suited for games Andreas Jakl, 2009 9
GameCanvas Construction Key Event delivery Call constructor of GameCanvas base class in first line of own constructor Requires boolean parameter: true: if using getKeyStates() to query currently pressed keys. Suppresses key event delivery to keyPressed(), keyRepeated() and keyReleased()  increases performance. false: deliver key events to the methods stated above, like for normal Canvas. Full screen (also available for Canvas) Call setFullScreenMode(bool) for (de)activating full screen mode Hides softkey and title area Note: UI guidelines usually require you to highlight at least one softkey that can be used for exiting the application, even during a game! Andreas Jakl, 2009 10
Games using a GameCanvas Andreas Jakl, 2009 11 public void myGameCanvas extends GameCanvas implements Runnable { 	public PlayCanvas() 	{ super(true);// Suppress key events -> query with getKeyStates() setFullScreenMode(true);	// Use full screen mode for the game 	} 	public void startGame() { 		Thread t = new Thread(this); t.start();				// Start the game loop in its own thread 	}	public void run() { 		Graphics g = getGraphics();  		// Main game loop 		while (true) { intkeyStates = getKeyStates(); // ... process key input and update the world ... flushGraphics();	// Method from GameCanvas base class -> do not override! Thread.sleep(20);	// Make sure the other system threads get some time 		} 	} } Thread
Game Loop Andreas Jakl, 2009 12 public void run() { // Get the Graphics object for the off-screen buffer Graphics g = getGraphics(); 	while (true) { // Query user input 		… // Update game state 		… // Do drawing 		… // Flush the off-screen buffer flushGraphics();	// Method from GameCanvas base class 					// -> do not override! 	} }
Polling Input Andreas Jakl, 2009 13 Traditional Canvas Game Canvas get key state Canvas.keyPressed()iPressedKey = LEFT; get key state get key state Game Loop Game Loop get key state Canvas.keyReleased()iPressedKey = NONE; get key state get key state get key state Time
Advantages of Key Polling Multiple keypress More than one button held simultaneously? (if supported by the hardware) Query all buttons in one call Update state at defined position Easier management of action handling Performance May increase – no event handling required Andreas Jakl, 2009 14
Game Actions Andreas Jakl, 2009 15 0 1 2 3 4 5 6 7 8 9 10 11 12 GAME_D_PRESSED UP_PRESSED RIGHT_PRESSED FIRE_PRESSED GAME_C_PRESSED DOWN_PRESSED LEFT_PRESSED GAME_B_PRESSED // Get state of all keys intkeyStates = getKeyStates(); // Handle all required keys if ((keyStates & UP_PRESSED) != 0) { // Handle up...} else if ((keyStates & LEFT_PRESSED) != 0) {// Handle left...} else if ... GAME_A_PRESSED
Game Graphics Using Andreas Jakl, 2009 16
Double Buffering SupportedbytheGameCanvas Andreas Jakl, 2009 17 Transferredas a wholewhen drawingis finished Back Buffer Upon construction, the buffer is filled with white by the GameCanvas Screen
Utility Classes for Graphics Andreas Jakl, 2009 18 Layer Represents a visual element in a game. LayerManager Simplifies sorting and drawing layers. Sprite Used for graphical moving objects. Can be animated. TiledLayer Used for backgrounds. Grid of cells that can be filled with tile images.
Layer Abstract base class for a visual element Defines paint()-method Properties: Position (upper-left corner) Size Visibility Andreas Jakl, 2009 19
Sprite Pre-rendered 2D figure, usually with transparency, integrated into larger scene Early video gaming Sprite: hardware feature built into graphics subsystem Limited number of sprites on the screen (GBA, SNES, ...) Software-based Sprite in Java ME Drawing Moving, rotating, flipping Animation Collision detection Andreas Jakl, 2009 20
Loading Create using: Image img = Image.createImage(“/player.png”);Sprite mySprite = new Sprite(img); NetBeans 6+: Add a resource folder to the project  Andreas Jakl, 2009 21
Reference Pixel Andreas Jakl, 2009 22 y Default Positions reference sprite at its upper left corner Custom anchor point Define reference point: Relative to un-transformed upper left corner of sprite May be outside of sprite’s bounds mySprite.defineReferencePixel(int x, int y); Position sprite: Reference pixel is located at pos x/y on painter’s coordinate system mySprite.setRefPixelPosition(intx, int y); Query sprite position: In the painter’s coordinate system int x = mySprite.getRefPixelX(); // getRefPixelY() (50, 50) x Default behavior y x Custom (centered)reference point
Transformations Possible in 90°-steps, no smooth rotation mySprite.setTransform(int transform); Andreas Jakl, 2009 23
Animation Several instances of the sprite that are slightly different All frames have the same size Only one frame displayed at the same time Create using: Sprite mySprite = new Sprite(img, intframeWidth, intframeHeight); Andreas Jakl, 2009 24 frameHeight frameWidth
Animation – Frames Set frame to display mySprite.setFrame(intsequenceIndex); Andreas Jakl, 2009 25 Frame ... 0 1 2
Animation – Frame Sequence For continuous animations: int[] frameSequence = {0, 1, 2, 1};mySprite.setFrameSequence (frameSequence);...mySprite.nextFrame(); Wraps automatically Andreas Jakl, 2009 26 Frame ... 0 1 2
Collision Checking for collision between a Sprite and ... another Sprite an Image a TiledLayer Andreas Jakl, 2009 27
Rectangle Collision Checks collision based on frame boundary if (mySprite.collidesWith(yourSprite, false)) { ... } Fast and efficient Possible to define collision rectangle size mySprite.defineCollisionRectangle (int x, int y, int width, int height); Andreas Jakl, 2009 28  collision  no collision
Pixel Collision Checks for overlapping, non-transparent pixels if (mySprite.collidesWith(yourSprite, true)) { ... } Considerably more expensive than rectangle check Andreas Jakl, 2009 29  collision  no collision
TiledLayer Create beautiful backgrounds Andreas Jakl, 2009 30
TiledLayer For displaying background graphics Made of repeating elements (=tiles) Create variety of backgrounds with less space What is a tile? Square bitmap Arranged in “tile maps” Andreas Jakl, 2009 31 Diamond RushCopyright 2006 Gameloft
How does it work? Original image (contains all tiles): Tile Map: Andreas Jakl, 2009 32 private static final char bg_map [] = { 4, 14, 1, 3, 5, 10, 8, 4, 7, 5, 3, 2, 2, 9, 11, 12, 6, 6, 11, 1, 1, 1, 1, 1, 1 };
Creating Tileable Tiles Create empty image in Photoshop (eg. 300x300 px) Copy part of a texture to the clipboard Filter  Pattern Maker... Andreas Jakl, 2009 33 Non tileable graphic: 5. Adapt parameters and generate versions until you are happy 4. Specify width and height of the tiles you want to create (eg. 32x32) 6. OK; then copy any tile-sized part (eg. 32x32) of the final image to a new image. This is your tile!
Creating a TileMap Free tool: Mappy (or use NetBeansGameBuilder) http://www.tilemap.co.uk/ (install .png-support as well) Export as text file for use with JavaME Andreas Jakl, 2009 34
The JavaME-Side Create TiledLayer-Object TiledLayermyBg = new TiledLayer(intcolums, int rows, Image img, inttileWidth, inttileHeight); All tiles in the image have the same size imageWidth = multiple of tileWidth imageHeight = multiple of tileHeight Set Tile Map Single cell: myBg.setCell (intcol, int row, inttileIndex); Fill area: myBg.fillCells (intcol, int row, intnumCols, intnumRows, inttileIndex); Andreas Jakl, 2009 35 tileIndex 0 = empty (transparent) cell
Assign Tile-Array Assign 1D Tile-array to tile map: Andreas Jakl, 2009 36 final inttileCols = 5;		// Columns (width) of the tile map final inttileRows = 5;		// Rows (height) of the tile mapfinal inttileSizePixelsW = 32;		// Width (pixels) of the individual tiles final inttileSizePixelsH = 32;	// Height (pixels) of the individual tiles TiledLayerbgLayer = new TiledLayer(tileCols, tileRows, Image.createImage ("/res/tiles.png"),tileSizePixelsW, tileSizePixelsH); for (inti = 0; i < bg_map.length; i++)		// Go through 1D array { int column = i % tileRows;// Current column int row = (i - column) / tileCols;// Current row bgLayer.setCell (column, row, bg_map[i]);	// Assign cell }
Drawing Manually drawing the TileMap (without LayerManager) bgLayer.paint(Graphics g); Move layer (scrolling, ...) bgLayer.move(intxOffset, intyOffset); eg. calling move(-3, 0); moves layer 3 pixels to the right Andreas Jakl, 2009 37
Animating Tiles For effects like water, wind brushing through trees, etc. Generate animated tile index intanimTileIndex = bgLayer.createAnimatedTile(1); Parameter: Initial static tile index that will be displayed Returns negative index, this can be assigned to cells that should be animated Switch to different tile bgLayer.setAnimatedTile(animTileIndex, 2); Causes static tile 2 to be displayed instead of 1 for all cells that have the animTileIndex as content Andreas Jakl, 2009 38
Animated Tiles – Example  Andreas Jakl, 2009 39 1. Tiles: 2. Array used to createthe tile map: 3. Code to create animated tiles: // Indicate that the tile should be animated intanimatedIndex = bg.createAnimatedTile(7); // animatedIndex should be -1 (first assignment) // -> Java ME will display tile 7 instead of -1 4. Code to animate tiles: // Switch the animated tile bg.setAnimatedTile(animatedIndex, 5); // -> Java ME will display tile 5 instead of 7 Images taken from theSun Java ME documentation
LayerManager Don’t want to do all the work yourself? Andreas Jakl, 2009 40
LayerManager Manages multiple layers Sprites, TiledLayers and own classes derived from those Paints all layers with a single call to LayerManager.paint(Graphics g, int x, int y) ,[object Object],Andreas Jakl, 2009 41 iLayerManager = new LayerManager (); iLayerManager.append (iPlayerSprite); iLayerManager.append (iEnemySprite); iLayerManager.append (iBulletSprite); iLayerManager.append (iBgLayer); visibility draw order
Positioning Layers Andreas Jakl, 2009 42 x (0, 0) (-50, 30) (100, 100) (200, 200) (250, 200) iLayerManager.setViewWindow (100, 100, iWidth, iHeight); iBgLayer.setPosition (-50, 30); iPlayerSprite.setPosition (200, 200); iBulletSprite.setPosition (250, 200); z
NetBeansGameBuilder NetBeans 6+ has got an integrated game editor Andreas Jakl, 2009 43
Thanks for your attention That’s it! Andreas Jakl, 2009 44

Mais conteúdo relacionado

Mais procurados

Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...DevGAMM Conference
 
Scene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesScene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesBryan Duggan
 
Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "Nikhil Jain
 
OpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsOpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsPrabindh Sundareson
 

Mais procurados (8)

Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...Optimization in Unity: simple tips for developing with "no surprises" / Anton...
Optimization in Unity: simple tips for developing with "no surprises" / Anton...
 
Soc research
Soc researchSoc research
Soc research
 
Scene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesScene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game Engines
 
Simulink
SimulinkSimulink
Simulink
 
Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "
 
Unity 13 space shooter game
Unity 13 space shooter gameUnity 13 space shooter game
Unity 13 space shooter game
 
OpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsOpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI Platforms
 
Masked Occlusion Culling
Masked Occlusion CullingMasked Occlusion Culling
Masked Occlusion Culling
 

Semelhante a Java ME - 05 - Game API

Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Korhan Bircan
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185Mahmoud Samir Fayed
 
WP7 HUB_XNA overview
WP7 HUB_XNA overviewWP7 HUB_XNA overview
WP7 HUB_XNA overviewMICTT Palma
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APITomi Aarnio
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2dVinsol
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsNick Pruehs
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platformgoodfriday
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android GamesPlatty Soft
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
 
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.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184Mahmoud Samir Fayed
 
Java me 08-mobile3d
Java me 08-mobile3dJava me 08-mobile3d
Java me 08-mobile3dHemanth Raju
 
GRAPHICS AND OPENGL.pptx
GRAPHICS AND OPENGL.pptxGRAPHICS AND OPENGL.pptx
GRAPHICS AND OPENGL.pptxOMNATHSINGH1
 

Semelhante a Java ME - 05 - Game API (20)

Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185
 
Scmad Chapter07
Scmad Chapter07Scmad Chapter07
Scmad Chapter07
 
WP7 HUB_XNA overview
WP7 HUB_XNA overviewWP7 HUB_XNA overview
WP7 HUB_XNA overview
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2d
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Unity workshop
Unity workshopUnity workshop
Unity workshop
 
MIDP: Game API
MIDP: Game APIMIDP: Game API
MIDP: Game API
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platform
 
WP7 HUB_XNA
WP7 HUB_XNAWP7 HUB_XNA
WP7 HUB_XNA
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android Games
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
 
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.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184
 
Java me 08-mobile3d
Java me 08-mobile3dJava me 08-mobile3d
Java me 08-mobile3d
 
Peint talk
Peint talkPeint talk
Peint talk
 
Tutorial flash
Tutorial flashTutorial flash
Tutorial flash
 
GRAPHICS AND OPENGL.pptx
GRAPHICS AND OPENGL.pptxGRAPHICS AND OPENGL.pptx
GRAPHICS AND OPENGL.pptx
 

Mais de Andreas Jakl

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityAndreas Jakl
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAndreas Jakl
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndreas Jakl
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndreas Jakl
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndreas Jakl
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Andreas Jakl
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web TechnologiesAndreas Jakl
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreAndreas Jakl
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Andreas Jakl
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test AutomationAndreas Jakl
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Andreas Jakl
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneAndreas Jakl
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingAndreas Jakl
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartAndreas Jakl
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosAndreas Jakl
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentAndreas Jakl
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)Andreas Jakl
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt CommunicationAndreas Jakl
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and GraphicsAndreas Jakl
 

Mais de Andreas Jakl (20)

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented Reality
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with Unity
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App Management
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSON
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - Introduction
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web Technologies
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test Automation
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer Training
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC Quickstart
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App Scenarios
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC Development
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt Communication
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt Data
 

Último

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 

Último (20)

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 

Java ME - 05 - Game API

  • 1. Java™Platform, Micro Edition Part 5 – Game API 1 Andreas Jakl, 2009 v3.0a – 19 April 2009
  • 2. Contents Performance Game API GameCanvas Bitmaps Sprite Layer andTiledLayer LayerManager Andreas Jakl, 2009 2
  • 3. Benchmarks Take care of performance Multiply a lot faster than divide No hardware floating point support (mostly SW-emulated, available since CLDC 1.1) PC-Emulator no reference for phone performance Performance of different phones can differ a LOT Benchmark results Based on SPMark Java06 Basic Edition http://www.futuremark.com/benchmarks/mobilebenchmarks/ Andreas Jakl, 2009 3
  • 6. GameCanvas Optimized for game loops Andreas Jakl, 2009 6
  • 7. Games using a Canvas Andreas Jakl, 2009 7 public void myCanvas extends Canvas implements Runnable { public void run() { // Main game loop while (true) { ... // Do processing repaint(); // Request repaint } } public void paint (Graphics g) { // Painting code } protected void keyPressed (intkeyCode) { // Handle user input } } Thread Thread Thread
  • 8. GameCanvas Andreas Jakl, 2009 8 Display One Display-object per MIDlet Displayable Canvas Screen Graphics Methodsfordrawingtothecanvas / offscreenbuffer GameCanvas High Level UI
  • 9. Canvas vs. GameCanvas Canvas Keys: sent as events, asynchronous processing Drawing: only in paint()-method, own thread Suited for event-based games and applications GameCanvas Keys: query state in the game loop for every iteration Drawing: everywhere, graphics shown when calling flushGraphics() from GameLoop (Both new features are optional in the GameCanvas!) Suited for games Andreas Jakl, 2009 9
  • 10. GameCanvas Construction Key Event delivery Call constructor of GameCanvas base class in first line of own constructor Requires boolean parameter: true: if using getKeyStates() to query currently pressed keys. Suppresses key event delivery to keyPressed(), keyRepeated() and keyReleased()  increases performance. false: deliver key events to the methods stated above, like for normal Canvas. Full screen (also available for Canvas) Call setFullScreenMode(bool) for (de)activating full screen mode Hides softkey and title area Note: UI guidelines usually require you to highlight at least one softkey that can be used for exiting the application, even during a game! Andreas Jakl, 2009 10
  • 11. Games using a GameCanvas Andreas Jakl, 2009 11 public void myGameCanvas extends GameCanvas implements Runnable { public PlayCanvas() { super(true);// Suppress key events -> query with getKeyStates() setFullScreenMode(true); // Use full screen mode for the game } public void startGame() { Thread t = new Thread(this); t.start(); // Start the game loop in its own thread } public void run() { Graphics g = getGraphics(); // Main game loop while (true) { intkeyStates = getKeyStates(); // ... process key input and update the world ... flushGraphics(); // Method from GameCanvas base class -> do not override! Thread.sleep(20); // Make sure the other system threads get some time } } } Thread
  • 12. Game Loop Andreas Jakl, 2009 12 public void run() { // Get the Graphics object for the off-screen buffer Graphics g = getGraphics(); while (true) { // Query user input … // Update game state … // Do drawing … // Flush the off-screen buffer flushGraphics(); // Method from GameCanvas base class // -> do not override! } }
  • 13. Polling Input Andreas Jakl, 2009 13 Traditional Canvas Game Canvas get key state Canvas.keyPressed()iPressedKey = LEFT; get key state get key state Game Loop Game Loop get key state Canvas.keyReleased()iPressedKey = NONE; get key state get key state get key state Time
  • 14. Advantages of Key Polling Multiple keypress More than one button held simultaneously? (if supported by the hardware) Query all buttons in one call Update state at defined position Easier management of action handling Performance May increase – no event handling required Andreas Jakl, 2009 14
  • 15. Game Actions Andreas Jakl, 2009 15 0 1 2 3 4 5 6 7 8 9 10 11 12 GAME_D_PRESSED UP_PRESSED RIGHT_PRESSED FIRE_PRESSED GAME_C_PRESSED DOWN_PRESSED LEFT_PRESSED GAME_B_PRESSED // Get state of all keys intkeyStates = getKeyStates(); // Handle all required keys if ((keyStates & UP_PRESSED) != 0) { // Handle up...} else if ((keyStates & LEFT_PRESSED) != 0) {// Handle left...} else if ... GAME_A_PRESSED
  • 16. Game Graphics Using Andreas Jakl, 2009 16
  • 17. Double Buffering SupportedbytheGameCanvas Andreas Jakl, 2009 17 Transferredas a wholewhen drawingis finished Back Buffer Upon construction, the buffer is filled with white by the GameCanvas Screen
  • 18. Utility Classes for Graphics Andreas Jakl, 2009 18 Layer Represents a visual element in a game. LayerManager Simplifies sorting and drawing layers. Sprite Used for graphical moving objects. Can be animated. TiledLayer Used for backgrounds. Grid of cells that can be filled with tile images.
  • 19. Layer Abstract base class for a visual element Defines paint()-method Properties: Position (upper-left corner) Size Visibility Andreas Jakl, 2009 19
  • 20. Sprite Pre-rendered 2D figure, usually with transparency, integrated into larger scene Early video gaming Sprite: hardware feature built into graphics subsystem Limited number of sprites on the screen (GBA, SNES, ...) Software-based Sprite in Java ME Drawing Moving, rotating, flipping Animation Collision detection Andreas Jakl, 2009 20
  • 21. Loading Create using: Image img = Image.createImage(“/player.png”);Sprite mySprite = new Sprite(img); NetBeans 6+: Add a resource folder to the project Andreas Jakl, 2009 21
  • 22. Reference Pixel Andreas Jakl, 2009 22 y Default Positions reference sprite at its upper left corner Custom anchor point Define reference point: Relative to un-transformed upper left corner of sprite May be outside of sprite’s bounds mySprite.defineReferencePixel(int x, int y); Position sprite: Reference pixel is located at pos x/y on painter’s coordinate system mySprite.setRefPixelPosition(intx, int y); Query sprite position: In the painter’s coordinate system int x = mySprite.getRefPixelX(); // getRefPixelY() (50, 50) x Default behavior y x Custom (centered)reference point
  • 23. Transformations Possible in 90°-steps, no smooth rotation mySprite.setTransform(int transform); Andreas Jakl, 2009 23
  • 24. Animation Several instances of the sprite that are slightly different All frames have the same size Only one frame displayed at the same time Create using: Sprite mySprite = new Sprite(img, intframeWidth, intframeHeight); Andreas Jakl, 2009 24 frameHeight frameWidth
  • 25. Animation – Frames Set frame to display mySprite.setFrame(intsequenceIndex); Andreas Jakl, 2009 25 Frame ... 0 1 2
  • 26. Animation – Frame Sequence For continuous animations: int[] frameSequence = {0, 1, 2, 1};mySprite.setFrameSequence (frameSequence);...mySprite.nextFrame(); Wraps automatically Andreas Jakl, 2009 26 Frame ... 0 1 2
  • 27. Collision Checking for collision between a Sprite and ... another Sprite an Image a TiledLayer Andreas Jakl, 2009 27
  • 28. Rectangle Collision Checks collision based on frame boundary if (mySprite.collidesWith(yourSprite, false)) { ... } Fast and efficient Possible to define collision rectangle size mySprite.defineCollisionRectangle (int x, int y, int width, int height); Andreas Jakl, 2009 28  collision  no collision
  • 29. Pixel Collision Checks for overlapping, non-transparent pixels if (mySprite.collidesWith(yourSprite, true)) { ... } Considerably more expensive than rectangle check Andreas Jakl, 2009 29  collision  no collision
  • 30. TiledLayer Create beautiful backgrounds Andreas Jakl, 2009 30
  • 31. TiledLayer For displaying background graphics Made of repeating elements (=tiles) Create variety of backgrounds with less space What is a tile? Square bitmap Arranged in “tile maps” Andreas Jakl, 2009 31 Diamond RushCopyright 2006 Gameloft
  • 32. How does it work? Original image (contains all tiles): Tile Map: Andreas Jakl, 2009 32 private static final char bg_map [] = { 4, 14, 1, 3, 5, 10, 8, 4, 7, 5, 3, 2, 2, 9, 11, 12, 6, 6, 11, 1, 1, 1, 1, 1, 1 };
  • 33. Creating Tileable Tiles Create empty image in Photoshop (eg. 300x300 px) Copy part of a texture to the clipboard Filter  Pattern Maker... Andreas Jakl, 2009 33 Non tileable graphic: 5. Adapt parameters and generate versions until you are happy 4. Specify width and height of the tiles you want to create (eg. 32x32) 6. OK; then copy any tile-sized part (eg. 32x32) of the final image to a new image. This is your tile!
  • 34. Creating a TileMap Free tool: Mappy (or use NetBeansGameBuilder) http://www.tilemap.co.uk/ (install .png-support as well) Export as text file for use with JavaME Andreas Jakl, 2009 34
  • 35. The JavaME-Side Create TiledLayer-Object TiledLayermyBg = new TiledLayer(intcolums, int rows, Image img, inttileWidth, inttileHeight); All tiles in the image have the same size imageWidth = multiple of tileWidth imageHeight = multiple of tileHeight Set Tile Map Single cell: myBg.setCell (intcol, int row, inttileIndex); Fill area: myBg.fillCells (intcol, int row, intnumCols, intnumRows, inttileIndex); Andreas Jakl, 2009 35 tileIndex 0 = empty (transparent) cell
  • 36. Assign Tile-Array Assign 1D Tile-array to tile map: Andreas Jakl, 2009 36 final inttileCols = 5; // Columns (width) of the tile map final inttileRows = 5; // Rows (height) of the tile mapfinal inttileSizePixelsW = 32; // Width (pixels) of the individual tiles final inttileSizePixelsH = 32; // Height (pixels) of the individual tiles TiledLayerbgLayer = new TiledLayer(tileCols, tileRows, Image.createImage ("/res/tiles.png"),tileSizePixelsW, tileSizePixelsH); for (inti = 0; i < bg_map.length; i++) // Go through 1D array { int column = i % tileRows;// Current column int row = (i - column) / tileCols;// Current row bgLayer.setCell (column, row, bg_map[i]); // Assign cell }
  • 37. Drawing Manually drawing the TileMap (without LayerManager) bgLayer.paint(Graphics g); Move layer (scrolling, ...) bgLayer.move(intxOffset, intyOffset); eg. calling move(-3, 0); moves layer 3 pixels to the right Andreas Jakl, 2009 37
  • 38. Animating Tiles For effects like water, wind brushing through trees, etc. Generate animated tile index intanimTileIndex = bgLayer.createAnimatedTile(1); Parameter: Initial static tile index that will be displayed Returns negative index, this can be assigned to cells that should be animated Switch to different tile bgLayer.setAnimatedTile(animTileIndex, 2); Causes static tile 2 to be displayed instead of 1 for all cells that have the animTileIndex as content Andreas Jakl, 2009 38
  • 39. Animated Tiles – Example Andreas Jakl, 2009 39 1. Tiles: 2. Array used to createthe tile map: 3. Code to create animated tiles: // Indicate that the tile should be animated intanimatedIndex = bg.createAnimatedTile(7); // animatedIndex should be -1 (first assignment) // -> Java ME will display tile 7 instead of -1 4. Code to animate tiles: // Switch the animated tile bg.setAnimatedTile(animatedIndex, 5); // -> Java ME will display tile 5 instead of 7 Images taken from theSun Java ME documentation
  • 40. LayerManager Don’t want to do all the work yourself? Andreas Jakl, 2009 40
  • 41.
  • 42. Positioning Layers Andreas Jakl, 2009 42 x (0, 0) (-50, 30) (100, 100) (200, 200) (250, 200) iLayerManager.setViewWindow (100, 100, iWidth, iHeight); iBgLayer.setPosition (-50, 30); iPlayerSprite.setPosition (200, 200); iBulletSprite.setPosition (250, 200); z
  • 43. NetBeansGameBuilder NetBeans 6+ has got an integrated game editor Andreas Jakl, 2009 43
  • 44. Thanks for your attention That’s it! Andreas Jakl, 2009 44