当前位置:软件学习 > Flash >>

半小时移植Flash游戏到Android上

 

继续研究国内的移动Web开发平台Rexsee。。

 

该平台已经正式开源,rexsee社区可以查看全部的扩展API说明与开发源码。。http://www.rexsee.com/

 

 

 

有一段代码,介绍如何将Flash游戏移植到Android手机上,并可以通过虚拟键盘或者方向传感器解决操控问题。所有代码是用HTML和JS写的,包括全部HTML,总共只有100多行。步骤如下:

 

 

 

 

 

准备键盘图片,这里用到了6个键,左、右、空格(跳跃)、退出、消息和Rexsee市场键,Rexsee提供了几套现成的键可以下载。将键的图片放到asset/keyboard/default/文件夹中,这样用"keyboard/default"来指定theme参数即可,否则要用放图片的文件夹的完整路径(本地SD卡或网络地址均可)来制定theme参数。文件名就是键值,后缀名是.png

将美羊羊卡丁车的swf文件放在asset/文件夹中

将横幅图片(这里是banner.png)和启动按钮图片(这里是startNow.png)放在asset/文件夹中

当然还有图标要放在res中,还要将string.xml中的首页地址设为file:///android_asset/index.html。这是唯一的一个程序文件,100多行。

这是离线版的,所以要下载Rexsee的JAR包,自己用Eclipse编译,如果嫌麻烦,可以在线编译一个首页地址指向服务器某个网页地址,然后将下面的index.html的代码放在这个文件中(有些路径要改,比如图片什么的),如果也想离线玩,可以在首次载入后将swf文件和图片自己或者用rexseeClient下载到本地。当然也可以不下载,就在线玩。

 

 

 

 

 

先看一下res/values/string.xml

 

 

Html代码 

<?xml version="1.0" encoding="utf-8"?> 

<resources> 

<string name="app_name">美羊羊卡丁车</string> 

<string name="app_home">file:///android_asset/index.html</string> 

<string name="rexsee_home">http://www.rexsee.com/flash/index.php</string> 

</resources> 

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="app_name">美羊羊卡丁车</string>

<string name="app_home">file:///android_asset/index.html</string>

<string name="rexsee_home">http://www.rexsee.com/flash/index.php</string>

</resources> 

在看一下AndroidManifest.xml

 

 

Xml代码 

<?xml version="1.0" encoding="utf-8"?> 

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

<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true" /> 

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"> 

<activity android:name="rexsee.activity.RexseeActivity" android:configChanges="orientation|keyboardHidden" android:launchMode="singleTop"> 

<intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter> 

 

</activity> 

</application> 

<uses-permission android:name="android.permission.INTERNET"/> 

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

</manifest> 

 

<?xml version="1.0" encoding="utf-8"?>

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

<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true" />

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">

<activity android:name="rexsee.activity.RexseeActivity" android:configChanges="orientation|keyboardHidden" android:launchMode="singleTop">

<intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter>

 

</activity>

</application>

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

</manifest> 

最后是asset/index.html源的代码

 

 

Html代码 

1:  <HTML> 

2:  <HEAD> 

3:      <TITLE>美羊羊卡丁车</TITLE> 

4:      <META http-equiv=Content-Type content=text/html charset=GB2312>    

5:      <META http-equiv=Expires content=0> 

6:      <META http-equiv=Cache-Control content=no-cache> 

7:      <META http-equiv=Pragma content=no-cache> 

8:      <SCRIPT type=text/javascript> 

9:            

10:         function startFlashGame(para){  

11:             //开始Flash游戏  

12:             rexseeScreen.setScreenOrientation(para.orientation);     //将屏幕方向设为水平  

13:             if ( para.sensor ) {  

14:                 rexseeOrientation.setRate('fastest');                //将传感器敏感程度设为最高  

15:                 rexseeOrientation.start();                            //启动传感器  

16:             } else {  

17:                 rexseeOrientation.setRate('normal');                //将传感器敏感程度设为正常  

18:                 rexseeOrientation.stop();                            //停止传感器  

19:     &nbs

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,