Splash Screen

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

Splash Screen

Postby thinkandapply » Tue Dec 30, 2008 6:49 am

hi I have tried to create a splash screen using Thread. but i am not able to siwitch the next display.
Plz help

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
* @author Deepz
*/
public class a extends MIDlet {
public b splash;
public c next;
public Display display;
public Displayable sz;


public a()
{
init();
}
public void startApp() {
display=Display.getDisplay(this);

splash=new b();
splash.start();
display.setCurrent(splash);
if(display==null)
{
display=Display.getDisplay(this);
next.start();
display.setCurrent(sz);
}
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
public void init()
{
next=new c();
next.start();
}
}



2nd


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Deepz
*/
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class b extends GameCanvas implements Runnable {
private boolean isPlay; // Game Loop runs when isPlay is true
private long delay; // To give thread consistency
private int currentX, currentY; // To hold current position of the 'X'
private int width; // To hold screen width
private int height; // To hold screen height
// Constructor and initialization
public b() {
super(true);
width = getWidth();
height = getHeight();
currentX = width / 2;
currentY = height / 2;
delay = 20;
}
// Automatically start thread for game loop
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() { isPlay = false; }
// Main Game Loop
public void run() {
synchronized(this)
{

Graphics g = getGraphics();
while (isPlay == true) {
input();
drawScreen(g);
try { wait(3000l);
dismiss();
}
catch (InterruptedException ie) {}
}
}
}
// Method to Handle User Inputs
private void input() {
int keyStates = getKeyStates();
// Left
if ((keyStates & LEFT_PRESSED) != 0)
currentX = Math.max(0, currentX - 1);
// Right
if ((keyStates & RIGHT_PRESSED) !=0 )
if ( currentX + 5 < width)
currentX = Math.min(width, currentX + 1);
// Up
if ((keyStates & UP_PRESSED) != 0)
currentY = Math.max(0, currentY - 1);
// Down
if ((keyStates & DOWN_PRESSED) !=0)
if ( currentY + 10 < height)
currentY = Math.min(height, currentY + 1);
}
// Method to Display Graphics
private void drawScreen(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x0000ff);
g.drawString("X",currentX,currentY,Graphics.TOP|Graphics.LEFT);
flushGraphics();
}
public void dismiss()
{
System.out.println("Saplsh done");
a test=new a();
test.init();
}
}


3rd

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Deepz
*/
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class c extends GameCanvas implements Runnable {
private boolean isPlay; // Game Loop runs when isPlay is true
private long delay; // To give thread consistency
private int currentX, currentY; // To hold current position of the 'X'
private int width; // To hold screen width
private int height; // To hold screen height
// Constructor and initialization
public c() {
super(true);
width = getWidth();
height = getHeight();
currentX = width / 2;
currentY = height / 2;
delay = 20;
}
// Automatically start thread for game loop
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() { isPlay = false; }
// Main Game Loop
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
input();
drawScreen(g);
try { Thread.sleep(delay); }
catch (InterruptedException ie) {}
}
}
// Method to Handle User Inputs
private void input() {
int keyStates = getKeyStates();
// Left
if ((keyStates & LEFT_PRESSED) != 0)
currentX = Math.max(0, currentX - 1);
// Right
if ((keyStates & RIGHT_PRESSED) !=0 )
if ( currentX + 5 < width)
currentX = Math.min(width, currentX + 1);
// Up
if ((keyStates & UP_PRESSED) != 0)
currentY = Math.max(0, currentY - 1);
// Down
if ((keyStates & DOWN_PRESSED) !=0)
if ( currentY + 10 < height)
currentY = Math.min(height, currentY + 1);
}
// Method to Display Graphics
private void drawScreen(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255,128,0);
g.drawString("X",currentX,currentY,Graphics.TOP|Graphics.LEFT);
flushGraphics();
}
}
thinkandapply
 
Posts: 15
Joined: Wed Nov 05, 2008 5:42 pm

Return to J2ME Games

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron