1. 程式人生 > >Java Android 遊戲開發框架LGame-0 2 7釋出

Java Android 遊戲開發框架LGame-0 2 7釋出

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               

2010-08-19更新內容:

 

1、針對Android版增加了多點觸控支援。

 

2、增加了一組模擬按鈕,以Screen實現Emulator監聽(此監聽器對應8種按鈕事件)即可直接使用。

 

3、增加了一些細節處的功能擴充套件,譬如Android版LSystem類已和JavaSE版一樣提供了大量系統環境引數。

 

4、修正了某些環境會遇到的中文亂碼問題以及新發現的框架BUG(舊版LGraphics類仿J2ME實現部分有BUG,建議更新此版)。

原始碼及jar下載地址:http://loon-simple.googlecode.com/files/LGame-0.2.7.7z

 

Android版啟動函式變更:

 

在0.2.7版中,略微變更了遊戲初始化方式,入口函式改為onMain。

 

[java]
view plain copy print ?
  1. public class Main extends LGameAndroid2DActivity {  
  2.       
  3.     public void onMain() {  
  4.         //this.initialization(false,LAD.LEFT, "Admob ID",60);
      
  5.         this.initialization(false);  
  6.         this.setShowLogo(false);  
  7.         this.setScreen(new EmulatorTest());  
  8.         this.setFPS(50);  
  9.         this.setShowFPS(true);  
  10.         this.showScreen();  
  11.     }  
  12. }  
public class Main extends LGameAndroid2DActivity {  public void onMain() {  //this.initialization(false,LAD.LEFT, "Admob ID",60);  this.initialization(false);  this.setShowLogo(false);  this.setScreen(new EmulatorTest());  this.setFPS(50);  this.setShowFPS(true);  this.showScreen(); }}

 

新增模擬按鈕的使用

 

為了適應複雜操作環境及格鬥遊戲需要,特為Android及JavaSE版LGame新增一組模擬按鈕,在任意Screen中實現EmulatorListener監聽即可呼叫。

 

基本使用方式如下:

 

[java] view plain copy print ?
  1. package org.loon.test;  
  2. import org.loon.framework.android.game.action.sprite.ColorBackground;  
  3. import org.loon.framework.android.game.core.EmulatorListener;  
  4. import org.loon.framework.android.game.core.graphics.LColor;  
  5. import org.loon.framework.android.game.core.graphics.Screen;  
  6. import org.loon.framework.android.game.core.graphics.device.LGraphics;  
  7. import android.view.KeyEvent;  
  8. import android.view.MotionEvent;  
  9. //所有的Screen(Screen、ThreadScreen、CanvasScreen)只要實現EmulatorListener監聽,  
  10. //即會自動呼叫模擬按鍵。   
  11. public class EmulatorTest extends Screen implements EmulatorListener {  
  12.     private ColorBackground background;  
  13.     public EmulatorTest() {  
  14.                //通過getEmulatorButtons函式可以返回當前模擬按鈕的陣列集合。   
  15.                //getEmulatorButtons();  
  16.     }  
  17.     // 0.2.7版新增函式,會在Screen構建完成後執行並載入其中資料  
  18.     public void onLoad() {  
  19.         // 製作一塊紅色的背景,大小為48x48  
  20.         this.background = new ColorBackground(LColor.red, 4848);  
  21.         // 居中(ColorBackground本身為精靈)  
  22.         this.centerOn(background);  
  23.         // 載入  
  24.         this.add(background);  
  25.     }  
  26.     public void draw(LGraphics g) {  
  27.     }  
  28.     // 0.2.7版新增函式,仿照rokon同名函式構建,僅在支援多點觸控的環境中才能被觸發。  
  29.     public void onTouch(float x, float y, MotionEvent e, int pointerCount,  
  30.             int pointerId) {  
  31.     }  
  32.     public boolean onKeyDown(int keyCode, KeyEvent e) {  
  33.         return true;  
  34.     }  
  35.     public boolean onKeyUp(int keyCode, KeyEvent e) {  
  36.         return true;  
  37.     }  
  38.     public boolean onTouchDown(MotionEvent e) {  
  39.         return true;  
  40.     }  
  41.     public boolean onTouchMove(MotionEvent e) {  
  42.         return true;  
  43.     }  
  44.     public boolean onTouchUp(MotionEvent e) {  
  45.         return true;  
  46.     }  
  47.     public void onUpClick() {  
  48.         if (background != null) {  
  49.             background.move_up(4);  
  50.         }  
  51.     }  
  52.     public void onDownClick() {  
  53.         if (background != null) {  
  54.             background.move_down(4);  
  55.         }  
  56.     }  
  57.     public void onLeftClick() {  
  58.         if (background != null) {  
  59.             background.move_left(4);  
  60.         }  
  61.     }  
  62.     public void onRightClick() {  
  63.         if (background != null) {  
  64.             background.move_right(4);  
  65.         }  
  66.     }  
  67.     public void onCancelClick() {  
  68.         if (background != null) {  
  69.             background.setVisible(false);  
  70.         }  
  71.     }  
  72.     public void onCircleClick() {  
  73.           
  74.     }  
  75.     public void onSquareClick() {  
  76.     }  
  77.     public void onTriangleClick() {  
  78.         if (background != null) {  
  79.             background.setVisible(true);  
  80.         }  
  81.     }  
  82.     public void unCancelClick() {  
  83.     }  
  84.     public void unCircleClick() {  
  85.     }  
  86.     public void unDownClick() {  
  87.     }  
  88.     public void unLeftClick() {  
  89.     }  
  90.     public void unRightClick() {  
  91.     }  
  92.     public void unSquareClick() {  
  93.     }  
  94.     public void unTriangleClick() {  
  95.     }  
  96.     public void unUpClick() {  
  97.     }   
package org.loon.test;import org.loon.framework.android.game.action.sprite.ColorBackground;import org.loon.framework.android.game.core.EmulatorListener;import org.loon.framework.android.game.core.graphics.LColor;import org.loon.framework.android.game.core.graphics.Screen;import org.loon.framework.android.game.core.graphics.device.LGraphics;import android.view.KeyEvent;import android.view.MotionEvent;//所有的Screen(Screen、ThreadScreen、CanvasScreen)只要實現EmulatorListener監聽,//即會自動呼叫模擬按鍵。 public class EmulatorTest extends Screen implements EmulatorListener { private ColorBackground background; public EmulatorTest() {               //通過getEmulatorButtons函式可以返回當前模擬按鈕的陣列集合。                //getEmulatorButtons(); } // 0.2.7版新增函式,會在Screen構建完成後執行並載入其中資料 public void onLoad() {  // 製作一塊紅色的背景,大小為48x48  this.background = new ColorBackground(LColor.red, 48, 48);  // 居中(ColorBackground本身為精靈)  this.centerOn(background);  // 載入  this.add(background); } public void draw(LGraphics g) { } // 0.2.7版新增函式,仿照rokon同名函式構建,僅在支援多點觸控的環境中才能被觸發。 public void onTouch(float x, float y, MotionEvent e, int pointerCount,   int pointerId) { } public boolean onKeyDown(int keyCode, KeyEvent e) {  return true; } public boolean onKeyUp(int keyCode, KeyEvent e) {  return true; } public boolean onTouchDown(MotionEvent e) {  return true; } public boolean onTouchMove(MotionEvent e) {  return true; } public boolean onTouchUp(MotionEvent e) {  return true; } public void onUpClick() {  if (background != null) {   background.move_up(4);  } } public void onDownClick() {  if (background != null) {   background.move_down(4);  } } public void onLeftClick() {  if (background != null) {   background.move_left(4);  } } public void onRightClick() {  if (background != null) {   background.move_right(4);  } } public void onCancelClick() {  if (background != null) {   background.setVisible(false);  } } public void onCircleClick() {   } public void onSquareClick() { } public void onTriangleClick() {  if (background != null) {   background.setVisible(true);  } } public void unCancelClick() { } public void unCircleClick() { } public void unDownClick() { } public void unLeftClick() { } public void unRightClick() { } public void unSquareClick() { } public void unTriangleClick() { } public void unUpClick() { } 

 

用新增的模擬按鍵可以輕鬆實現格鬥類或需要複雜操作的遊戲:

 

00

 


框架基本使用方法請參見此文:http://blog.csdn.net/cping1982/archive/2010/08/06/5794380.aspx

 

以下為較早前釋出過的一些程式示例畫面(請下載較早前LGame釋出版本獲得):

以下為LGame-Simple開發的部分遊戲示例畫面。

 


原始碼及jar下載地址:http://loon-simple.googlecode.com/files/LGame-0.2.7.7z

 

 

           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述