移植flash游戏到android
网上有很多现成的Flash游戏,一直想在手机上玩,虽说Android2.2支持Flash,但是大多数游戏需要键盘控制,最多的就是方向键,而手机大多数没有键盘(有键盘的好像也不行),所以实际上就没办法玩了。
现在Rexsee提供了一个很简单的解决方案,可以迅速将Flash游戏移植到Android手机上(2.2以上)。(目前Rexsee已经开源,在社区可以查看全部的开发手册、API说明与源码,www.rexsee.com)
下面是一个例子,把经典的美羊羊卡丁车移植到了手机上,而且有两个版本,一个用虚拟键盘,一个用方向传感器。
所有代码是用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下载到本地。当然也可以不下载,就在线玩。
标签: Rexsee Android SDK
代码片段(3)[全屏查看所有代码]
1. [代码]先看一下res/values/string.xml
1
|
<?xml version= "1.0" encoding= "utf-8" ?>
|
2
|
<resources>
|
3
|
<string name= "app_name" >美羊羊卡丁车</string>
|
4
|
<string name= "app_home" >file: ///android_asset/index.html</string>
|
5
|
<string name= "rexsee_home" >http: //www.rexsee.com/flash/index.php</string>
|
6
|
</resources>
|
2. [代码]再看一下AndroidManifest.xml
01
|
<?xml version= "1.0" encoding= "utf-8" ?>
|
02
|
<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "MeiYangYangKaDingChe.rexsee" android:versionCode= "1" android:versionName= "1.0" >
|
03
|
<supports-screens android:largeScreens= "true" android:normalScreens= "true" android:smallScreens= "true" android:anyDensity= "true" />
|
04
|
<application android:icon= "@drawable/icon" android:label= "@string/app_name" android:theme= "@android:style/Theme.NoTitleBar" >
|
05
|
<activity android:name= "rexsee.activity.RexseeActivity" android:configChanges= "orientation|keyboardHidden" android:launchMode= "singleTop" >
|
06
|
<intent-filter><action android:name= "android.intent.action.MAIN" /><category android:name= "android.intent.category.LAUNCHER" /></intent-filter>
|
07
|
08
|
</activity>
|
09
|
</application>
|
10
|
<uses-permission android:name= "android.permission.INTERNET" />
|
11
|
<uses-permission android:name= "android.permission.ACCESS_NETWORK_STATE" />
|
12
|
</manifest>
|
3. [代码]最后是asset/index.html的源代码
001
|
1: <HTML>
|
002
|
2: <HEAD>
|
003
|
3: <TITLE>美羊羊卡丁车</TITLE>
|
004
|
4: <META http-equiv=Content-Type content=text/html charset=GB2312>
|
005
|
5: <META http-equiv=Expires content=0>
|
006
|
6: <META http-equiv=Cache-Control content=no-cache>
|
007
|
7: <META http-equiv=Pragma content=no-cache>
|
008
|
8: <SCRIPT type=text/javascript>
|
009
|
9:
|
010
|
10: function startFlashGame(para){
|
011
|
11: //开始Flash游戏
|
012
|
12: rexseeScreen.setScreenOrientation(para.orientation); //将屏幕方向设为水平
|
013
|
13: if ( para.sensor ) {
|
014
|
14: rexseeOrientation.setRate( 'fastest' ); //将传感器敏感程度设为最高
|
015
|
15: rexseeOrientation.start(); //启动传感器
|
016
|
16: } else {
|
017
|
17: rexseeOrientation.setRate( 'normal' ); //将传感器敏感程度设为正常
|
018
|
18: rexseeOrientation.stop(); //停止传感器
|
019
|
19: }
|
020
|
20: rexseeFlash.clearKeyboard(); //清空键盘
|
021
|
21: if ( para.leftKeyboard ) rexseeFlash.setLeftKeyboard(para.leftKeys,para.leftKeyTheme,para.leftKeyboardStyle,para.leftKeyRowStyle,para.leftKeyStyle,para.leftKeyPressedStyle); //设置左键盘
|
022
|
22: if ( para.rightKeyboard ) rexseeFlash.setRightKeyboard(para.rightKeys,para.rightKeyTheme,para.rightKeyboardStyle,para.rightKeyRowStyle,para.rightKeyStyle,para.rightKeyPressedStyle); //设置右键盘
|
023
|
23: rexseeFlash.setSwfStyle(para.swfStyle); //设置Flash游戏区域的样式
|
024
|
24: rexseeFlash.show(para.swf,para.dialogStyle); //设置对话框样式并启动对话框
|
025
|
25: }
|
026
|
26: var paraKeyboardVersion = {
|
027
|
27: orientation: "landscape" , //屏幕方向
|
028
|
28: sensor: false , //是否启用方向传感器
|
029
|
29: //设置左边键盘
|
030
|
30: leftKeyboard: false , //是否启用左键盘
|
031
|
31: leftKeys: "" , //左键盘的按键,数字序列,同一行按键使用逗号分隔,不同行使用分号分隔,Rexsee自定义按键包括-2,-3,-4,-5,其余按键请参考http://developer.android.com/reference/android/view/KeyEvent.html
|
032
|
32: leftKeyTheme: "" , //左键盘的样式,字符串,应在asset目录下创建以该字符串命名的文件夹,然后将按键图片(键值.png)放在该文件夹
|
033
|
33: leftKeyboardStyle: "" , //左键盘的样式
|
034
|
34: leftKeyRowStyle: "" , //左键盘中每一行的样式
|
035
|
35: leftKeyStyle: "" , //左键盘中每个按键的样式
|
036
|
36: leftKeyPressedStyle: "" , //左键盘中每个按键被按下时的样式
|
037
|
37: //设置右边键盘,参看上面左键盘说明
|
038
|
38: rightKeyboard: true ,
|
039
|
39: rightKeys: "-1,-5;-2,62;21,22" ,
|
040
|
40: rightKeyTheme: "keyboard/default" ,
|
041
|
41: rightKeyboardStyle: "border-left-width:5px;border-left-color:#aaaaaa+#000000/2;background-color:#000000;" ,
|
042
|
42: rightKeyRowStyle: "" ,
|
043
|
43: rightKeyStyle: "" ,
|
044
|
44: rightKeyPressedStyle: "" ,
|
045
|
45: //设置Flash区域的样式
|
046
|
46: swfStyle: "" ,
|
047
|
47: //设置对话框的样式
|
048
|
48: dialogStyle: "" ,
|
049
|
49: //设置Flash游戏的地址
|
050
|
50: swf: "game.swf"
|
051
|
51: };
|
052
|
52: var paraSensorVersion = {
|
053
|
53: orientation: "landscape" ,
|
054
|
54: sensor: true ,
|
055
|
55: leftKeyboard: false ,
|
056
|
56: leftKeys: "" ,
|
057
|
57: leftKeyTheme: "" ,
|
058
|
58: leftKeyboardStyle: "" ,
|
059
|
59: leftKeyRowStyle: "" ,
|
060
|
60: leftKeyStyle: "" ,
|
061
|
61: leftKeyPressedStyle: "" ,
|
062
|
62: rightKeyboard: true ,
|
063
|
63: rightKeys: "-1;-5;-2;62" ,
|
064
|
64: rightKeyTheme: "keyboard/default" ,
|
065
|
65: rightKeyboardStyle: "border-left-width:5px;border-left-color:#aaaaaa+#000000/2;background-color:#000000;" ,
|
066
|
66: rightKeyRowStyle: "" ,
|
067
|
67: rightKeyStyle: "" ,
|
068
|
68: rightKeyPressedStyle: "" ,
|
069
|
69: swfStyle: "" ,
|
070
|
70: dialogStyle: "" ,
|
071
|
71: swf: "game.swf"
|
072
|
72: };
|
073
|
73:
|
074
|
74: window.onRexseeReady = function (){
|
075
|
75: //在页面装载完毕时运行
|
076
|
76: if ( rexseeBuild.getSdk()<8) {
|
077
|
77: alert( "对不起,您的手机软件版本太低,不能运行该游戏,请使用Android2.2以上版本运行该游。" );
|
078
|
78: rexseeApplication.quit();
|
079
|
79: }
|
080
|
80: if (!rexseeFlash.isReady()){
|
081
|
81: rexseeDialog.confirm( "Adobe Flash Player" , "Adobe Flash Player没有安装,无法运行该游戏。是否现在安装?" , "现在安装" , "退出程序" , "javascript:rexseeBrowser.open('http://www.rexsee.com/flash/flashplayer/download.php');rexseeApplication.exit();" , "javascript:rexseeApplication.exit();" );
|
082
|
82: }
|
083
|
83: rexseeScreen.setScreenAlwaysOn( true ); //总是点亮屏幕
|
084
|
84: rexseeScreen.setScreenOrientation( 'portrait' ); //将将屏幕方向设为垂直
|
085
|
85: rexseeStatusBar.setStyle( "visibility:hidden;" ); //隐藏状态栏
|
086
|
86: }
|
087
|
87: window.onAjaxReturned = function (ajaxUrl,response){
|
088
|
88: response = unescape(response);
|
089
|
89: if ( ajaxUrl == headerUrl) document.getElementById( "header" ).innerHTML = response;
|
090
|
90: else if ( ajaxUrl == footerUrl) document.getElementById( "footer" ).innerHTML = response;
|
091
|
91: else if ( ajaxUrl == jsUrl) eval(response);
|
092
|
92: }
|
093
|
93: window.onFlashDialogDismissed = function (){
|
094
|
94: //在退出Flash游戏返页面时运行
|
095
|
95: rexseeScreen.setScreenOrientation( 'portrait' ); //将屏幕方向设为垂直
|
096
|
96: }
|
097
|
97: window.onbeforeunload = function (){
|
098
|
98: //在退出页面时运行
|
099
|
99: rexseeScreen.setScreenOrientation( 'auto' ); //将屏幕方向设为自动
|
100
|
100: rexseeOrientation.stop(); //停止方向传感器
|
101
|
101: }
|
102
|
102:
|
103
|
103: var version = "" ;
|
104
|
104: //Rexsee新增按键的回调函数
|
105
|
105: window.onKeyboardHelpPressed = function (){
|
106
|
106: //对应键值:-2
|
107
|
107: if ( version == "keyboard" ) alert( "左右键向左或向右,空格键跳跃。" );
|
108
|
108: else if ( version == "sensor" ) alert( "左右倾斜手机向左或向右,虚拟键盘的空格键跳跃。" );
|
109
|
109: }
|
110
|
110: window.onKeyboardQaPressed = function (){
|
111
|
111: //对应键值:-3
|
112
|
112: alert( "QA pressed." );
|
113
|
113: }
|
114
|
114: window.onKeyboardHomePressed = function (){
|
115
|
115: //对应键值:-4
|
116
|
116: if ( window.confirm( "要退出游戏吗?" ) ) {
|
117
|
117: rexseeFlash.hide();
|
118
|
118: rexseeApplication.quit();
|
119
|
119: }
|
120
|
120: }
|
121
|
121: window.onKeyboardCancelPressed = function (){
|
122
|
122: //对应键值:-5
|
123
|
123: if ( window.confirm( "要退出游戏吗?" ) ) {
|
124
|
124: rexseeFlash.hide();
|
125
|
125: }
|
126
|
126: }
|
127
|
127:
|
128
|
128: window.onOrientationChanged = function (){
|
129
|
129: //如果启用方向传感器,在回调函数中向Flash游戏发送键值
|
130
|
130: var x = Math.round(rexseeOrientation.getLastKnownX());
|
131
|
131: var y = Math.round(rexseeOrientation.getLastKnownY());
|
132
|
132: var z = Math.round(rexseeOrientation.getLastKnownZ());
|
133
|
133: if ( y > 10 ) {
|
134
|
134: rexseeFlash.keyDown(21);
|
135
|
135: } else if ( y<-10){
|
136
|
136: rexseeFlash.keyDown(22);
|
137
|
137: } else {
|
138
|
138: rexseeFlash.keyUp(21);
|
139
|
139: rexseeFlash.keyUp(22);
|
140
|
140: }
|
141
|
141: }
|
142
|
142: </SCRIPT>
|
143
|
143: <STYLE>
|
144
|
144: body { margin:0px; background-color: #eeeeee;}
|
145
|
145: .imageButton { width:100px;height:100px; border:none; margin: 0 0 0 10; }
|
146
|
146: .section {border:1px solid;border-color: #f7f7f7 #7f9db5 #7f9db5 #f7f7f7;background-color:#ffffff;padding:15px;}
|
147
|
147: .gameTitle { font-size:24px;font-weight:bold; color: #F01D17;margin:15 0 15 0;}
|
148
|
148: .gameIntro {}
|
149
|
149: .gameVersion { font-size:20px;font-weight:bold; color: #F01D17;margin:10 0 15 0;}
|
150
|
150: .gameGuide { margin: 0 0 10 0; }
|
151
|
151: #copyright {background-color:#444444;padding:5px;color:white;font-size:10px;}
|
152
|
152: </STYLE>
|
153
|
153: </HEAD>
|
154
|
154: <BODY>
|
155
|
155: <a href= "http://www.rexsee.com/flash/index.php" ><img src= 'banner.png' width=100% border=0></a>
|
156
|
156:
|
157
|
157: <div class=section>
|
158
|
158: <div class=gameTitle>美羊羊卡丁车</div>
|
159
|
159: <div class=gameIntro>
|
160
|
160: 可爱的美羊羊是赛车高手哦,来体验下美羊羊马路杀手的感觉吧,美羊羊开车的速度可是会越来越快哦,小心呀!
|
161
|
161: <br><br>游戏目标:帮助美羊羊躲避路障,安全抵达终点。
|
162
|
162: <br>
|
163
|
163: </div>
|
164
|
164: </div>
|
165
|
165: <div class=section>
|
166
|
166: <table width=100%><tr>
|
167
|
167: <td valign=top>
|
168
|
168: <div class=gameVersion>虚拟键盘版</div>
|
169
|
169: <div class=gameGuide>左右键向左或向右,空格键跳跃。</div>
|
170
|
170: </td>
|
171
|
171: <td><img src= "startNow.png" onclick= "version='keyboard';startFlashGame(paraKeyboardVersion);" class=imageButton></td>
|
172
|
172: </tr></table>
|
173
|
173: </div>
|
174
|
174: <div class=section>
|
175
|
175: <table width=100%><tr>
|
176
|
176: <td valign=top>
|
177
|
177: <div class=gameVersion>重力感应版</div>
|
178
|
178: <div class=gameGuide>左右倾斜手机向左或向右,虚拟键盘的空格键跳跃。</div>
|
179
|
179: </td>
|
180
|
180: <td><img src= "startNow.png" onclick= "version='sensor';startFlashGame(paraSensorVersion);" class=imageButton></td>
|
181
|
181: </tr></table>
|
182
|
182: </div>
|
183
|
183: </BODY>
|
184
|
184: </HTML>
|
移植flash游戏到android相关推荐
- 移植cocos2d-x 游戏从Android平台到IOS平台分辨率问题及解决办法
问题描述: 因为游戏刚开始设计时是在Android平台上运行的,所以使用的是当时Android主流的分辨率(800 * 480), 使用cocos2d-x在其他Android平台可以做到等比例缩放,所 ...
- android平台运行flash游戏
android平台运行flash游戏 http://blog.csdn.net/yearafteryear/article/details/8959475 http://www.oschina.net ...
- flash游戏移植html5,分享将游戏从Flash移植到Unity的5个体会
作者:Alex Nichiporchik <No Time to Explain>最初是一款网页Flash游戏,之后转向Kickstarter平台筹资,成为Steam上的一款商业游戏.这款 ...
- 快速创建精彩的Flash游戏(一) Flash2D游戏引擎简介
原文链接:http://xiazhihui321.blog.163.com/blog/static/81328893201141851158857/ Adobe Flash自诞生之日就与游戏结下不解之 ...
- 学ios 需要学html5me,针对iOS平台移植Flash内容的指导教程(1)
针对iOS平台移植Flash内容的指导教程(1) 发布时间:2011-12-07 15:18:16 Tags:Mac,在iOS平台开发Flash内容,指导教程 作者:Sina Kashanizadeh ...
- 一个完整的嵌入式程序_【荐读】贪食蛇游戏的Android嵌入式系统设计
贪食蛇游戏的Android嵌入式系统设计 Design of Android Embedded-System for Greedy Snake Game 作者: 韩 中, 苟和平, 李 援:琼台师范学 ...
- qq游戏大厅 android,QQ游戏中心(android)(原创教程)
关键词:QQ游戏中心,android,原创教程 QQ游戏中心客户端(Android版)经过几个月的努力设计上终于告一段落,目前版本还在继续优化打磨中.团队对新版上花了大量的精力和心血,大家努力把新版做 ...
- 利用 Flare3D 和 Stage3D 创建 3D Flash 游戏
目录 设置 Flash Builder 以便于使用 Stage3D 和 Flare3D 库 步骤1:将 3D 模型加载到 Flash 步骤2:使用 ActionScript 将行为应用于对象 步骤 3 ...
- 被Adobe官宣死亡后,延续Flash游戏的n种方法
本文转载自 触乐,作者 祝思齐 早在2017年,Adobe公司就宣布在2020年12月31日停止对Flash的所有支持.如果说不再更新与维护还算不上真正的死亡宣判,1月12日,Adobe正式对所有在F ...
最新文章
- 【Python】百度贴吧图片的爬虫实现(努力努力再努力)
- HTTP详解-工作原理
- ios/mac command
- “约见”面试官系列之常见面试题之第五十八篇之join和split(建议收藏)
- 用JS来create结点,纯JS代码生成html页面(作业练习)
- mybatis文件中SQL总结
- python出现—with the features you requested: lxml. Do you need to install a parser library?
- 第八章 深度强化学习-Nature深度Q网络(Nature DQN)
- com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor和oracle不识别
- jeecg框架解决跨域问题
- Programer四境界-摘自《代码大全》
- 虚拟机桥接模式联网设置
- JavaScript 特效三大系列总结
- JavaScript数据类型 - Undefined类型
- Gradle配置文件解决你的问题。
- a-table的数据内容特定处换行处理
- 海思平台(hi3559av100)异构多系统的使用Linux(2*A53+2*A73)+liteos(A53)+liteos(M7)
- chatbot使用_如何使用Python构建Chatbot项目
- php html转换成word,php如何实现html转换word?_后端开发
- 混频对两路同频同源射频信号相位差的影响
热门文章
- 【Semantic segmentation】Scratching the surface
- 被裁员?这是上帝为你开了一扇窗,你知道吗?
- YUMI制作启动盘安装ubuntu时报错:booting ‘find /menu.lstk /boot/grub/menu.lst, /grub/menu.lst‘
- iptv linux 安卓 盒子,基于嵌入式Linux的IPTV机顶盒设计
- KITTI 3D目标检测数据集入门
- python黑客帝国代码雨特效
- 该如何学习三维点云配准的相关知识?
- Oracle监听器启动出错:本地计算机上的OracleOraDb11g_home1TNSListener服务启动后又停止了解决方案...
- IO流案例以及特殊操作流/对象对象序列化流/Properties集合
- opengl 下载安装+vs2010配置