Motorola C450, C550, C370 technical manual Using GameScreen

Page 43

8

Gaming API and Sound

public void playBackgroundMusic (BackgroundMusic bgm, boolean loop) - Plays the specified BackgroundMusic object from the beginning. This method first stops the current BackgroundMusic if any. Thus, this method may be used to start background music (by specifying a non-null BackgroundMusic object), restart the current background music (by specifying the same BackgroundMusic object), change the background music, or end the background music (by specifying null). The loop parameter is set to true if the BackgroundMusic is to repeat indefinitely. Otherwise, set to false.

Using GameScreen

The GameDemoScreen class uses the GameScreen class to provide a UI screen for a hypothetic game. GameDemoScreen is a subclass of GameScreen that implements runnable for running the main game loop thread.

The following code sample shows implementation of using GameScreen.

GameScreen

class GameDemoScreen extends GameScreen implements Runnable{

// ...

public void run() {

//Get the Graphics object for the

//off-screen buffer

Graphics g = getGraphics(); while (true) {

//Check user input and update

//positions if necessary

int keyState = getKeyStates(); if ((keyState & LEFT_KEY) != 0) {

sprite.move(-1, 0);

}

else if ((keyState & RIGHT_KEY) != 0) { sprite.move(1, 0);

}

//Draw the background g.drawImage(backgroundImage,0,0, Graphics.TOP

+Graphics.LEFT);

//Draw the sprite on top of the background sprite.draw(g);

//Flush the off-screen buffer flushGraphics();

}

}

// ...

}

43

Image 43
Contents Technical Manual Table of Contents Lcdui JAD Attributes Disclaimer IntroductionPurpose AudienceReferences Acronym Description Revision HistoryDefinitions, Abbreviations, Acronyms Date Name ReasonDocument Overview Introduction Java 2 Platform, Micro Edition J2ME J2ME IntroductionResources Available Motorola J2ME PlatformJava VM Description DisplayNetworking File & RMSGuide to Development in J2ME Developing and Packaging J2ME ApplicationsIntroduction to Development Page Installation OTA ProcedureDownloading Applications Program and Data space notes Starting Applications Java Application Installer/De-Installer JaidExiting Applications Launching Web Session for Http Download Error ChecksDownloading MIDlets XML Screen Renderings BombMan is back, now on your Taichi series of handsets Taichi handset New Games MIDlet Lifecycle Application ManagementMIDlet Suite Installation MIDlet Suite De-installation DestroyApp MIDlet Suite UpdatingCaller Purpose MethodStartApp or the pauseApp Using startApp MIDlet Control of MIDlet State Transitions Java SystemPage Network Connections Network APIClass Descriptions URL Format IOException when it detects a time-out conditionUDP Sockets TCP SocketsImplementation Notes Network API Description LcduiLcdui Functional Description Gaming API and SoundClass Hierarchy Gaming API containing a sound API Using BackgroundMusicBackgroundMusic Class BackgroundMusic MethodsGameScreen Fields GameScreen ClassPublic int getKeyStates GameScreen MethodsInformation, disabling key events can improve performance GameScreen Using GameScreenImageUtil Fields ImageUtil ClassImageUtil Methods RgbData Using ImageUtilPalleteImage Constructor PalleteImage ClassPalleteImage Methods Public void setTransparentIndexint index throws Using PalleteImagePlayField Class Using Static and Animated TilesDefining View Windows Using SpritesPlayField Constructor 2N+1 2N + Public void addSpriteSprite s throws PlayField MethodsPage Public boolean collidesWithAnyTileSprite s throws PlayField Using PlayFieldSoundEffect Methods Using SoundEffectSoundEffect Class Sprite ClassSprite Drawing Animation FramesSprite Constructor Sprite Methods Page Public final void drawGraphics g throws FileFormatNotSupportedException Using SpriteSprites Java Gaming Sound API Java Gaming Sound APIMax Midi Extension Support FileFormatNotSupportedException ConstructorsVibe and Backlight API Vibe and BacklightCreating a Message OverviewPermissions Sending a MessageJAD Attributes JAD AttributesMandatory attributes for manifest files MIDlet-Name RecordStore Record Management SystemClass Description Code ExamplesCaveats TipsPhonebook Access API Phonebook AccessSample of code to create object of PhoneBookRecord class Phonebook Access API PermissionsSimmemory Sample of code for calling of ‘getMaxEmailLength ’ method Sample of code for calling of ‘isPrimaryint speedNo’ method Sample of code for calling of ‘getNumberCategories’ method Sample of code for calling of ‘setCategoryView’ method Sample of code for calling of ‘getUsedRecords’ method Int index = ReceivedRecord.getRecord1 Intelligent Keypad Text Entry API ITAPKey Mapping for the C370, C450, and C550 Appendix a Key MappingCenter Select END Available Memory Appendix B Memory Management CalculationAppendix C Online FAQC370, C450, and C550 Spec Sheets Appendix D Spec SheetsDocumentation Motorola Developer Information ToolsReferences Purchase Motorola Developer Information Tools Motorola, Inc
Related manuals
Manual 110 pages 1.04 Kb