LGame01——开篇,游戏框架

讨论LGame的人太少了,资料太少了,换了


libs:LAE-1.1.jar


配置文件:

在主Activity中添加android:configChanges="orientation|keyboardHidden"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.lgamestudy"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".LGameStudyActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

主Activity文件

LGameStudyActivity.java

package com.example.lgamestudy;

import org.loon.framework.android.game.LGameAndroid2DActivity;

public class LGameStudyActivity extends LGameAndroid2DActivity
{

	@Override
	public void onGamePaused()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void onGameResumed()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void onMain()
	{
		// TODO Auto-generated method stub
		/* 设置游戏是否横屏 */  
		   
        this.initialization(true);  

          
        /* 给Activity赋予一个画面,有点类似于View */  

        this.setScreen(new ScreenExample());  

          
        /* 这个厉害了,指定游戏的帧速率,每秒30帧 */  

        this.setFPS(30);  

          
        /* 是否显示游戏帧数(当然显示喇) */  

        this.setShowFPS(true);  

          
        /* 不显示Logo(这个没试过显示,先不管,我们要的是HelloWorld) */  

        this.setShowLogo(false);  

          
        /* OK,一切准备就绪,显示游戏画面 */  

        this.showScreen();
	}

}


绘图类

ScreenExample.java

package com.example.lgamestudy;

import org.loon.framework.android.game.action.sprite.Sprite;
import org.loon.framework.android.game.action.sprite.Sprites;
import org.loon.framework.android.game.core.graphics.LColor;
import org.loon.framework.android.game.core.graphics.LImage;
import org.loon.framework.android.game.core.graphics.Screen;
import org.loon.framework.android.game.core.graphics.device.LGraphics;
import org.loon.framework.android.game.core.timer.LTimerContext;

public class ScreenExample extends Screen
{
	private LImage bgImage = null;
	private LImage tipImage = null;
	
	private final String TAG = "zhang";
	private Sprite girlSprite = null;/* 精灵:一个弓手女孩 */
	private Sprites sprMgr = null;
	
	public ScreenExample() {
		/* 加载资源方式1:加载Assets目录的资源,必须制定assets目录名称 */
		bgImage = LImage.createImage("assets/bgImg.jpg");
		/* 加载资源方式2:加载res目录的资源,必须制定res目录名称,包括子目录 */  
		tipImage = LImage.createImage("res/drawable-mdpi/text.png");
		
		girlSprite = new Sprite("assets/girl.png", 103, 114);
		girlSprite.setLocation(50, 250);
		sprMgr = new Sprites();
		sprMgr.add(girlSprite);
		   
    }
	/*  
     * 官方解释: 

     * 与J2SE版相同,draw中LGraphics会根据设定的FPS自动刷新,使用上与标准的J2SE 

     * Graphics以及J2MEGraphics接口没有区别(API为二者的综合) 

     */
	

	@Override
	public void alter(LTimerContext arg0)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void draw(LGraphics g)
	{
		// TODO Auto-generated method stub
		/* 简单吧?就是咱们的canvas.drawColor(Color.GRAY) */  
		   
        g.drawClear(LColor.gray);  
        g.drawImage(bgImage, 0, 0);
        g.drawImage(tipImage, 10, 10);
        
        sprMgr.createUI(g);
        sprMgr.update(100);

          
        /*  
         * 来了,我们的最爱——HelloWorld! 

         * 太简单了,我都不想解释了,绘制"HelloWorld"字符串到屏幕的(100,100)位置 

         */  

        g.drawString("HelloWorld", 100, 100);
	}

	@Override
	public void onTouchDown(LTouch arg0)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void onTouchMove(LTouch arg0)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void onTouchUp(LTouch arg0)
	{
		// TODO Auto-generated method stub

	}

}

说明:内容多处直接摘用其他网络文章。

你可能感兴趣的:(游戏,android,J2SE,application,Class,action)