| Reply | « Previous Thread | Next Thread » |
|
Hi, I am new to game developement. I want to diaplay a black box which can move around on the display using the arrow key. I am
display the object separately. When I want to display on at the same time using the following code, only the background image mimi.png is display. please suggest how to display object on a image backgroud Ken ===================================================================== package testgame; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class GameActionTest extends MIDlet { private static GameActionTest instance; Image image=null; private Display display; /** Constructor */ public GameActionTest() { display=Display.getDisplay(this); } /** Main method */ public void startApp() throws MIDletStateChangeException{ /** */ /** */ display.setCurrent (new GameActionTestCanvas()); /** try{ image = Image.createImage("/mime.png"); } catch(Exception e){ System.out.println("Icon not loaded!"); } Displayable d = new DrawImageCanvas(image); display.setCurrent(d); */ } /** Handle pausing the MIDlet */ public void pauseApp() { } /** Handle destroying the MIDlet */ public void destroyApp(boolean unconditional) { } class GameActionTestCanvas extends Canvas { int width, height; int deltaX, deltaY; int x,y; public GameActionTestCanvas() { deltaX =this.getWidth()/16; deltaY=this.getHeight()/16; width=deltaX*16; height=deltaY*16; x=64; y=64; } public void paint(Graphics g) { /** draw the image background */ try{ image = Image.createImage("/mime.png"); } catch(Exception e){ System.out.println("Icon not loaded!"); } Displayable d = new DrawImageCanvas(image); display.setCurrent(d); g.setColor(0x00FF00); g.fillRect(x+deltaX,y,deltaX,deltaY); g.setColor(0xFF0000); g.fillRect(x+2*deltaX,y,deltaX,deltaY); } public void keyPressed (int keycode) { switch(getGameAction(keycode)) { case Canvas.DOWN: y+=deltaY; if (y >= height) { y -= height; repaint(x, 0, 3*deltaX, height); } else { repaint(x, y - deltaY, deltaX*3, 2 * deltaY); } break; case Canvas.UP: y-=deltaY; if (y <0) { y += height; repaint(x, 0, deltaX*3, height); } else { repaint(x, y, deltaX*3, 2 * deltaY); } break; } } } public static void quitApp() { instance.destroyApp(true); instance.notifyDestroyed(); instance = null; } } |
| kenkwokkam |
| View Public Profile |
| Find all posts by kenkwokkam |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|