mgdk
Class MCanvas

java.lang.Object
  |
  +--javax.microedition.lcdui.Displayable
        |
        +--javax.microedition.lcdui.Canvas
              |
              +--javax.microedition.lcdui.game.GameCanvas
                    |
                    +--mgdk.MCanvas
All Implemented Interfaces:
java.lang.Runnable

public class MCanvas
extends javax.microedition.lcdui.game.GameCanvas
implements java.lang.Runnable

The base class for MIDlets created with MGDK, every MIDlet should have one. Extend it and overload handleInput(), updateObjects() and draw(). Initialize sprites etc in your new class constructor.


Field Summary
 javax.microedition.lcdui.game.LayerManager layers
          All games will probable use a LayerManager, use this one :o)
 int msgBoxBack
           
 int msgBoxBorder
           
 int msgBoxText
           
 
Fields inherited from class javax.microedition.lcdui.game.GameCanvas
DOWN_PRESSED, FIRE_PRESSED, GAME_A_PRESSED, GAME_B_PRESSED, GAME_C_PRESSED, GAME_D_PRESSED, LEFT_PRESSED, RIGHT_PRESSED, UP_PRESSED
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
MCanvas()
          Constructor, sets default values and creates some objects.
 
Method Summary
 void clear(javax.microedition.lcdui.Graphics gr, int r, int g, int b)
          Clears the screen.
 void draw(javax.microedition.lcdui.Graphics g)
          Draw objects to the screen here (overload it).
 void handleInput()
          Handle inputs in this one (overload it).
 boolean keyA()
           
 boolean keyB()
           
 boolean keyC()
           
 boolean keyD()
           
 boolean keyDown()
          Checks if key down is pressed.
 boolean keyFire()
          Checks if the fire key is pressed.
 boolean keyLeft()
          Checks if key left is pressed.
 boolean keyRight()
          Checks if key right is pressed.
 boolean keyUp()
          Checks if key up is pressed.
 void msgBox(java.lang.String msg, int width, int height)
          Displays a simple messagebox centered on screen.
 void run()
          The main game loop.
 void start()
          Start the main game loop.
 void stop()
          Stop the main game loop.
 void updateObjects()
          Update (move, animation) your objects (sprites, maps) in this one (overload it).
 void wishFPS(int fps)
          Set how many frames per second you wish for your game to have.
 void wishTimePerFrame(int tpf)
          Set how much time you wish to spend for each update of your game.
 
Methods inherited from class javax.microedition.lcdui.game.GameCanvas
flushGraphics, flushGraphics, getGraphics, getKeyStates, paint
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, keyPressed, keyReleased, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setFullScreenMode, showNotify, sizeChanged
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

layers

public javax.microedition.lcdui.game.LayerManager layers
All games will probable use a LayerManager, use this one :o)


msgBoxBack

public int msgBoxBack

msgBoxText

public int msgBoxText

msgBoxBorder

public int msgBoxBorder
Constructor Detail

MCanvas

public MCanvas()
Constructor, sets default values and creates some objects.

Method Detail

wishFPS

public void wishFPS(int fps)
Set how many frames per second you wish for your game to have. Not guranteed, rather a maximum... Uses wishTimePerFrame.


wishTimePerFrame

public void wishTimePerFrame(int tpf)
Set how much time you wish to spend for each update of your game. Not guranteed, rather a minimum...


start

public void start()
Start the main game loop.


stop

public void stop()
Stop the main game loop.


run

public void run()
The main game loop. Calls other methods that should be overloaded in a subclass.

Specified by:
run in interface java.lang.Runnable

handleInput

public void handleInput()
Handle inputs in this one (overload it). Called from the game loop (run).


updateObjects

public void updateObjects()
Update (move, animation) your objects (sprites, maps) in this one (overload it). Called from the game loop (run)


draw

public void draw(javax.microedition.lcdui.Graphics g)
Draw objects to the screen here (overload it). If you use the LayerManager (layers) for everythin, then just paint it (layers.paint(g)).


msgBox

public void msgBox(java.lang.String msg,
                   int width,
                   int height)
Displays a simple messagebox centered on screen. Dismissed by pressing fire.


clear

public void clear(javax.microedition.lcdui.Graphics gr,
                  int r,
                  int g,
                  int b)
Clears the screen. By drawing a filled rectangle with the specified color.


keyLeft

public boolean keyLeft()
Checks if key left is pressed.


keyRight

public boolean keyRight()
Checks if key right is pressed.


keyDown

public boolean keyDown()
Checks if key down is pressed.


keyUp

public boolean keyUp()
Checks if key up is pressed.


keyFire

public boolean keyFire()
Checks if the fire key is pressed.


keyA

public boolean keyA()

keyB

public boolean keyB()

keyC

public boolean keyC()

keyD

public boolean keyD()