Pages

Thursday, October 28, 2010

about canvas class and using it in mobile game

If you want using keys or touch or graphics in your game you should use canvas class.Canvas class have predefined function for detect key press or drag or screen  touch and also important paint function .First you should add new canvas class with right click on your project and go new and select MIDP canvas…..

In this class you’ll see some function like this

protected  void keyPressed(int keyCode) {
   }
  
   /**
    * Called when a key is released.
    */
   protected  void keyReleased(int keyCode) {
   }

   /**
    * Called when a key is repeated (held down).
    */
   protected  void keyRepeated(int keyCode) {
   }

……………..

……………

…………….

……………

they are contains code that running when key pressed or released or repeated or…you can add code like draw string in keypress and create text when key pressed .Now you should running canvas in your game .For this purpose you should add code like this in startApp function in your middlet.

 Display.getDisplay(this).setCurrent(new MIDPCanvas());

jus thisWinking smile

in next post I’ll describe how you can detect fire,back,numbers,..keys and pointer into your software 

No comments:

Post a Comment

linkwithin

Related Posts Plugin for WordPress, Blogger...