www.pudn.com > 3DSplashScreen.rar > SplashScreen3D.java



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

/**
 * Shows how to display a 3D Splash Screen to the user
 * while time consuming initialization of the main
 * screen takes place.
 *
 * The 3D Splash Screen uses Mascot Capsule version 3
 * to render the graphics.
 *
 * If one just tries to display the splash in the startApp,
 * it might not show up at all until the initialization is done!
 * To prevent this separate Threads are used for the Splash
 * and the initialization. The init Thread doesn't start until
 * the splash actually has been drawn to the Canvas.
 *
 * Beacuse the Splash is animated it's important to give the Thread
 * CPU cycles now and then to be able to render!
 * 
 *
 * This code is part of the Tips & Tricks section at 
 * www.SonyEricsson.com/developer
 *
 * Written by Jöns Weimarck, 2004
 * 3D code based on code from HI Corp
 */
public class SplashScreen3D extends MIDlet implements CommandListener, Runnable {
    
    private Command exitCommand; 
    private Display display;
    private SplashScreen splashScreen;    
    private Form myForm;
       
    
    public SplashScreen3D() {
        display = Display.getDisplay(this);
        exitCommand = new Command("Exit", Command.EXIT, 0);
    }
    
    public void startApp() {
        //Creates the 3D Splash and dispalys it using a separate thread.
        splashScreen= new SplashScreen(display);

        //Creates and starts the main game
        Thread myGameThread = new Thread(this);
        myGameThread.start();       
    }
    
   /** 
    *    The main game thread
   */
    public void run(){
        // Don't start initializing until the Splash is shown, otherwise
        // the initializaation will delay the Splash from being shown!
        while(!SplashScreen.splashIsShown){
            Thread.yield();
        }
        
        doTimeConsumingInit();
        
        while(true){
            // Game loop           
            Thread.yield();
        }
    }
    
    /**
     * Do all initialization for the game here
     */
    private void doTimeConsumingInit(){ 
        // Just mimic some lengthy initialization for 10 secs
        long endTime= System.currentTimeMillis()+10000;

        while(System.currentTimeMillis()