⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crender2d.java

📁 一个3D的保龄球的源代码
💻 JAVA
字号:
/**
 * <p>Title: class CRender2D</p>
 * <p>Description: Manage 2D resources and draw 2D modules.</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: Gameloft ShangHai</p>
 * @author Tao Qing
 * @version 1.0
 */

import javax.microedition.lcdui.Graphics;
import java.io.*;

class CRender2D
{

  /** The file include string data and animation data.*/
private static final String DATA_FILE_NAME = "/o.bin";
/** All string stored here.*/
public static String[] m_text;
/** All animations data stored here.*/
public static Animations[] m_anims;

  public CRender2D(){
    //load animation and string data
    loadData();
  }



///////////////function to load data//////////////////////
 void loadData()
 {
   byte[] indexbytes;
   try
   {
     DataInputStream is_data = null;
     if (is_data == null)
     {
       System.gc();
       is_data = new DataInputStream(DATA_FILE_NAME.getClass().getResourceAsStream(DATA_FILE_NAME));
     }


     if (is_data == null)
     {
       System.out.println("STILL NULL");
     }

     // read data part count
     int count = is_data.readUnsignedShort();

     // read data part index
     indexbytes = new byte[count * 4];
     is_data.readFully(indexbytes, 0, indexbytes.length);

     // load string
     System.gc();
     loadString(is_data);

     // animation data
     System.gc();
     loadAnimation(is_data);

     is_data.close();
     is_data = null;

     System.gc();
   }
   catch (Exception e) {e.printStackTrace();}
 }

 int loadString(DataInputStream is)
 {
   try
   {
     int count;
     // following 3 line code is to skip the index data
     count = is.readUnsignedShort();

    // is.skip(count * 4);
     if (m_text == null)
       m_text = new String[count];
     for (int i = 0; i < count; i++)
     {
       m_text[i] = is.readUTF();
     }
   }
   catch (Exception e) {e.printStackTrace();}
   return 0;
 }

 int loadAnimation(DataInputStream is)
 {
   try
   {
     int count;
     count = is.readUnsignedShort();

     m_anims = new Animations[count];

     for (int i = 0; i < count; i++)
     {
       is.readUnsignedShort(); // animation data size
       Animations a = new Animations();
       m_anims[i] = a;
       a.loadAnimation(is);
     }
   }
   catch (Exception e) {e.printStackTrace();}
   return 0;
 }
///////////////function to load data end//////////////////////

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -