You Are Here:

Community: Developer Discussion Boards

#1 Old Game Developement - Display object on a image background - 2003-02-08, 15:58

Join Date: Mar 2003
Posts: 1
kenkwokkam
Offline
Registered User
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;
}

}
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia