Motorola C370, C550, C450 technical manual GameScreen Methods, Public int getKeyStates

Page 41

8

Gaming API and Sound

public static final int VOLUME_MIN - The minimum volume for playing sound effects. This constant has a value of 0.

GameScreen Methods

The GameScreen class defines the following methods:

protected Graphics getGraphics() - Obtains the Graphics object for rendering GameScreens. The Graphics object renders to an off-screen buffer whose size is equal to that of the GameScreen (use getWidth() and getHeight() to determine the size of the GameScreen). The buffer is initially filled with white pixels. Rendering operations do not appear on the display until flushGraphics() is called; flushing the buffer does not change its contents (that is, the pixels are not cleared as a result of the flushing operation). Only one image buffer is supported because without a vertical sync blanking period or its equivalent, there is little or no benefit from having multiple image buffers. Only one Graphics object exists for each GameScreen instance.

public int getKeyStates() - Gets the states of the physical keys. Each bit in the returned integer represents a specific key on the device. A key's bit will be set if the key is currently pressed or was pressed at least once since the last time this method was called. The bit will be 0 if the key is not currently pressed and was not pressed at all since the last time this method was called. This latching behavior ensures that a rapid key press and release will always be caught by the game loop, regardless of how slowly the loop runs. This method may be called twice to check if a key is currently pressed; that is, calling this method twice effectively disables the latching behavior. The lower bits are defined by UP_KEY, DOWN_KEY, LEFT_KEY, etc.; the remaining bits may be mapped to device-specific keys.

The following is a code sample to show implementation of public int getKeyStates():

Public int getKeyStates ()

// Get the key state and store it

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

positionX--;

} else if ((keyState & RIGHT_KEY) != 0) { positionX++;

}

public void enableKeyEvents(boolean enabled) - Enables or disables key event calls to this GameScreen. If disabled, the Canvas key event methods (keyPressed, keyRepeated, keyReleased) are not called when keys are pressed or released; however, the developer can still call getKeyStates to query the state of the keys. For games that poll key state and do not need event-driven key

41

Image 41
Contents Technical Manual Table of Contents Lcdui JAD Attributes Purpose IntroductionAudience DisclaimerReferences Definitions, Abbreviations, Acronyms Revision HistoryDate Name Reason Acronym DescriptionDocument Overview Introduction Java 2 Platform, Micro Edition J2ME J2ME IntroductionResources Available Motorola J2ME PlatformNetworking Description DisplayFile & RMS Java VMIntroduction to Development Developing and Packaging J2ME ApplicationsGuide to Development in J2ME Page Downloading Applications OTA ProcedureInstallation Program and Data space notes Exiting Applications Java Application Installer/De-Installer JaidStarting Applications Downloading MIDlets Error ChecksLaunching Web Session for Http Download 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 conditionImplementation Notes TCP SocketsUDP Sockets Network API Description LcduiLcdui Class Hierarchy Gaming API and Sound Functional Description BackgroundMusic Class Using BackgroundMusicBackgroundMusic Methods Gaming API containing a sound APIGameScreen Fields GameScreen ClassPublic int getKeyStates GameScreen MethodsInformation, disabling key events can improve performance GameScreen Using GameScreenImageUtil Methods ImageUtil ClassImageUtil Fields RgbData Using ImageUtilPalleteImage Methods PalleteImage ClassPalleteImage Constructor Public void setTransparentIndexint index throws Using PalleteImagePlayField Class Using Static and Animated TilesPlayField Constructor Using SpritesDefining View Windows 2N+1 2N + Public void addSpriteSprite s throws PlayField MethodsPage Public boolean collidesWithAnyTileSprite s throws PlayField Using PlayFieldSoundEffect Class Using SoundEffectSprite Class SoundEffect MethodsSprite Constructor Animation FramesSprite Drawing Sprite Methods Page Public final void drawGraphics g throws Sprites Using SpriteFileFormatNotSupportedException Max Midi Extension Support Java Gaming Sound APIFileFormatNotSupportedException Constructors Java Gaming Sound APIVibe and Backlight API Vibe and BacklightCreating a Message OverviewPermissions Sending a MessageJAD Attributes JAD AttributesMandatory attributes for manifest files MIDlet-Name Class Description Record Management SystemCode Examples RecordStoreCaveats 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 SheetsReferences Purchase Motorola Developer Information ToolsDocumentation Motorola Developer Information Tools Motorola, Inc
Related manuals
Manual 110 pages 1.04 Kb