Results 1 to 2 of 2
- 08-18-2011, 09:55 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
How to run TiledLayer in midp 2.0 of j2me
hi....every one
I need help of you to run tiledlayer in j2me.when i run below program it is saying IlligalStateExcepion.so i unable to run this program.so plz kindly help me.
I written program as like below
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class SpriteCollideMIDlet extends MIDlet {
SpriteCollideCancas canvas = new SpriteCollideCancas();
public SpriteCollideMIDlet(){ }
protected void destroyApp(boolean some) throws MIDletStateChangeException{ }
protected void pauseApp() { }
protected void startApp()throws MIDletStateChangeException {
Display display = Display.getDisplay(this);
canvas.start();
display.setCurrent(canvas);
}
}
class SpriteCollideCancas extends GameCanvas implements Runnable {
static int FRONT_DIRECTION = 0;
static int LEFT_DIRECTION = 1;
static int RIGHT_DIRECTION = 2;
static int BACK_DIRECTION = 3;
Sprite hero,hero2;
boolean running;
int[][] sequence = {{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};
int s2[] ={8,9,10,11};
int w,h;
Image img_bg = null;
int cx,cy,cx2,cy2;
int currentDirection = FRONT_DIRECTION;
protected SpriteCollideCancas() {
super(true);
Image im = null,hm2 = null;
try{
im = Image.createImage("/grid.png");
hm2 = Image.createImage("/grid1.png");
img_bg = Image.createImage("/kodim22.png");
}catch(IOException e){ }
hero = new Sprite(im,8,10);
hero2 = new Sprite(hm2,8,10);
w = getWidth();
h = getHeight();
cx = w/2;
cy = h/2;
hero.setFrameSequence(sequence[0]);
hero2.setFrameSequence(s2);
}
public void start(){
running = true;
Thread t = new Thread(this);
t.start();
}
public void run(){
Graphics g =getGraphics();
int delay=100;
while(running){
moving();
getInput();
hero2.nextFrame();
drawScreen(g);
try{
Thread.sleep(delay);
}catch(InterruptedException e){}
}
}
void moving(){
if(cx2>getWidth()){
cx2=0;
}
if(!hero2.collidesWith(hero,false))
cx2++;
}
void getInput(){
int keyState = getKeyStates();
int cDirection = currentDirection;
if(keyState==LEFT_PRESSED){
if(!hero.collidesWith(hero2,false)){
cx=cx-5;cx=Math.max(0,cx);
currentDirection=LEFT_DIRECTION;
}hero.nextFrame();
}else if(keyState==RIGHT_PRESSED){
cx=cx+5;cx=Math.min(cx,w-32);
currentDirection=RIGHT_DIRECTION;
hero.nextFrame();
}else if(keyState==UP_PRESSED){
cy=cy-5;cy=Math.max(0,cy);
currentDirection=BACK_DIRECTION;
hero.nextFrame();
}else if(keyState==DOWN_PRESSED){
cy=cy-5; cy=Math.min(cy,h-50);
currentDirection=FRONT_DIRECTION;
hero.nextFrame();
}
if(cDirection!=currentDirection){
hero.setFrameSequence(sequence[currentDirection]);
}
}
void drawScreen(Graphics g){
g.drawImage(img_bg,0-cx,0-cy,Graphics.TOP|Graphics.LEFT);
hero2.setPosition(cx2,cy2+20);
hero2.paint(g);
hero.setPosition(cx,cy);
hero.paint(g);
flushGraphics();
}
}
- 08-18-2011, 10:26 AM #2
Similar Threads
-
Bluetooth connection not working on US Nokia phones from J2ME Midlet (MIDP 2.0)
By yash2009 in forum CLDC and MIDPReplies: 1Last Post: 08-07-2009, 09:30 AM -
MIDP web browser
By islamfunny in forum CLDC and MIDPReplies: 0Last Post: 10-06-2008, 11:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks