网上有很多现成的Flash游戏,一直想在手机上玩,虽说Android2.2支持Flash,但是大多数游戏需要键盘控制,最多的就是方向键,而手机大多数没有键盘(有键盘的好像也不行),所以实际上就没办法玩了。
现在Rexsee提供了一个很简单的解决方案,可以迅速将Flash游戏移植到Android手机上(2.2以上)。(目前Rexsee已经开源,在社区可以查看全部的开发手册、API说明与源码,?
www.rexsee.com?)?
下面是一个例子,把经典的美羊羊卡丁车移植到了手机上,而且有两个版本,一个用虚拟键盘,一个用方向传感器。
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:???????????????
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:?????????????}??
20:?????????????rexseeFlash.clearKeyboard();??????????????????????????????
21:?????????????if?(?para.leftKeyboard?)?rexseeFlash.setLeftKeyboard(para.leftKeys,para.leftKeyTheme,para.leftKeyboardStyle,para.leftKeyRowStyle,para.leftKeyStyle,para.leftKeyPressedStyle);??????????????
22:?????????????if?(?para.rightKeyboard?)?rexseeFlash.setRightKeyboard(para.rightKeys,para.rightKeyTheme,para.rightKeyboardStyle,para.rightKeyRowStyle,para.rightKeyStyle,para.rightKeyPressedStyle);??????
23:?????????????rexseeFlash.setSwfStyle(para.swfStyle);??????????????
24:?????????????rexseeFlash.show(para.swf,para.dialogStyle);??????
25:?????????}??
26:?????????var?paraKeyboardVersion?=?{??
27:?????????????????orientation:?????????????"landscape",??????????
28:?????????????????sensor:?????????????????false,??????????????????
29:???????????????????
30:?????????????????leftKeyboard:?????????????//是否启用左键盘??
31:?????????????????leftKeys:?????????????????"",??????????????????????
32:?????????????????leftKeyTheme:?????????????"",0)">//左键盘的样式,字符串,应在asset目录下创建以该字符串命名的文件夹,然后将按键图片(键值.png)放在该文件夹??
33:?????????????????leftKeyboardStyle:?????????"",0)">//左键盘的样式??
34:?????????????????leftKeyRowStyle:?????????"",0)">//左键盘中每一行的样式??
35:?????????????????leftKeyStyle:?????????????"",0)">//左键盘中每个按键的样式??
36:?????????????????leftKeyPressedStyle:?????????"",0)">//左键盘中每个按键被按下时的样式??
37:???????????????????
38:?????????????????rightKeyboard:?????????????true,??
39:?????????????????rightKeys:?????????????????"-1,-5;-2,62;21,22",0)">40:?????????????????rightKeyTheme:?????????????"keyboard/default",0)">41:?????????????????rightKeyboardStyle:?????"border-left-width:5px;border-left-color:#aaaaaa+#000000/2;background-color:#000000;",0)">42:?????????????????rightKeyRowStyle:?????????"",0)">43:?????????????????rightKeyStyle:?????????????"",0)">44:?????????????????rightKeyPressedStyle:????"",0)">45:???????????????????
46:?????????????????swfStyle:????????????????"",0)">47:???????????????????
48:?????????????????dialogStyle:?????????????"",0)">49:???????????????????
50:?????????????????swf:?????????????????????"game.swf"??
51:?????????};??
52:?????????var?paraSensorVersion?=?{??
53:?????????????????orientation:?????????????"landscape",0)">54:?????????????????sensor:?????????????????55:?????????????????leftKeyboard:?????????????56:?????????????????leftKeys:?????????????????"",0)">57:?????????????????leftKeyTheme:?????????????"",0)">58:?????????????????leftKeyboardStyle:?????????"",0)">59:?????????????????leftKeyRowStyle:?????????"",0)">60:?????????????????leftKeyStyle:?????????????"",0)">61:?????????????????leftKeyPressedStyle:?????????"",0)">62:?????????????????rightKeyboard:?????????????63:?????????????????rightKeys:?????????????????"-1;-5;-2;62",0)">64:?????????????????rightKeyTheme:?????????????"keyboard/default",0)">65:?????????????????rightKeyboardStyle:?????"border-left-width:5px;border-left-color:#aaaaaa+#000000/2;background-color:#000000;",0)">66:?????????????????rightKeyRowStyle:?????????"",0)">67:?????????????????rightKeyStyle:?????????????"",0)">68:?????????????????rightKeyPressedStyle:????"",0)">69:?????????????????swfStyle:????????????????"",0)">70:?????????????????dialogStyle:?????????????"",0)">71:?????????????????swf:?????????????????????"game.swf"??
72:?????????};??
73:???
74:?????????window.onRexseeReady?=?function(){??
75:???????????????
76:?????????????if?(?rexseeBuild.getSdk()<8)?{??
77:?????????????????alert("对不起,您的手机软件版本太低,不能运行该游戏,请使用Android2.2以上版本运行该游。");??
78:?????????????????rexseeApplication.quit();??
79:?????????????}??
80:?????????????if?(!rexseeFlash.isReady()){??
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();");??
82:?????????????}??
83:?????????????rexseeScreen.setScreenAlwaysOn(true);????????????????????
84:?????????????rexseeScreen.setScreenOrientation('portrait');????????
85:?????????????rexseeStatusBar.setStyle("visibility:hidden;");???????
86:?????????????????????}??
87:?????????window.onAjaxReturned?=?function(ajaxUrl,response){??
88:?????????????response?=?unescape(response);??
89:?????????????if?(?ajaxUrl?==?headerUrl)?document.getElementById("header").innerHTML?=?response;??
90:?????????????else?if?(?ajaxUrl?==?footerUrl)?document.getElementById("footer").innerHTML?=?response;??
91:?????????????if?(?ajaxUrl?==?jsUrl)?eval(response);??
92:?????????}??
93:?????????window.onFlashDialogDismissed?=?function(){??
94:???????????????
95:?????????????rexseeScreen.setScreenOrientation('portrait');??????????
96:?????????}??
97:?????????window.onbeforeunload?=?function(){??
98:???????????????
99:?????????????rexseeScreen.setScreenOrientation('auto');??????????????
100:????????????????rexseeOrientation.stop();??????????????????????????????
101:????????????}??
102:??????????????
103:????????????var?version?=?"";??
104:??????????????
105:????????????window.onKeyboardHelpPressed?=?function(){??
106:??????????????????
107:????????????????if?(?version?==?"keyboard"?)?alert("左右键向左或向右,空格键跳跃。");??
108:????????????????if?(?version?==?"sensor"?)?alert("左右倾斜手机向左或向右,虚拟键盘的空格键跳跃。");??
109:????????????}??
110:????????????window.onKeyboardQaPressed?=?function(){??
111:??????????????????
112:????????????????alert("QA?pressed.");??
113:????????????}??
114:????????????window.onKeyboardHomePressed?=?function(){??
115:??????????????????
116:????????????????if?(?window.confirm("要退出游戏吗?")?)?{??
117:????????????????????rexseeFlash.hide();??
118:????????????????????rexseeApplication.quit();??
119:????????????????}??
120:????????????}??
121:????????????window.onKeyboardCancelPressed?=?function(){??
122:??????????????????
123:????????????????124:????????????????????rexseeFlash.hide();??
125:????????????????}??
126:????????????}??
127:??????????????
128:????????????window.onOrientationChanged?=?function(){??
129:??????????????????
130:????????????????var?x?=?Math.round(rexseeOrientation.getLastKnownX());??
131:????????????????var?y?=?Math.round(rexseeOrientation.getLastKnownY());??
132:????????????????var?z?=?Math.round(rexseeOrientation.getLastKnownZ());??
133:????????????????if?(?y?>?10?)?{??
134:????????????????????rexseeFlash.keyDown(21);??
135:????????????????}?if?(?y<-10){??
136:????????????????????rexseeFlash.keyDown(22);??
137:????????????????}?138:????????????????????rexseeFlash.keyUp(139:????????????????????rexseeFlash.keyUp(140:????????????????}??
141:????????????}??
142:????????</SCRIPT>??
143:????????<STYLE>??
144:????????????body?{?margin:0px;?background-color:#eeeeee;}??
145:????????????.imageButton?{?width:100px;height:100px;?border:none;?margin:?0?10;?}??
146:????????????.section?{border:1px?solid;border-color:#f7f7f7?#7f9db5?#7f9db5?#f7f7f7;background-color:#ffffff;padding:15px;}??
147:????????????.gameTitle?{?font-size:24px;font-weight:bold;?color:#F01D17;margin:15?0;}??
148:????????????.gameIntro?{}??
149:????????????.gameVersion?{?font-size:20px;font-weight:bold;?color:#F01D17;margin:10?150:????????????.gameGuide?{?margin:?0;?}??
151:????????????#copyright?{background-color:#444444;padding:5px;color:white;font-size:10px;}??
152:????????</STYLE>??
153:????</HEAD>??
154:????<BODY>??
155:????<a?href="http://www.rexsee.com/flash/index.php"><img?src='banner.png'?width=100%?border=0></a>??
156:??????
157:????<div?class=section>??
158:????????<div?class=gameTitle>美羊羊卡丁车</div>??
159:????????<div?class=gameIntro>??
160:????????????可爱的美羊羊是赛车高手哦,来体验下美羊羊马路杀手的感觉吧,美羊羊开车的速度可是会越来越快哦,小心呀!??
161:????????????<br><br>游戏目标:帮助美羊羊躲避路障,安全抵达终点。??
162:????????????<br> ??
163:????????</div>??
164:????</div>??
165:????<div?166:????????<table?width=100%><tr>??
167:????????????<td?valign=top>??
168:????????????????<div?class=gameVersion>虚拟键盘版</div>??
169:????????????????<div?class=gameGuide>左右键向左或向右,空格键跳跃。</div>??
170:????????????</td>??
171:????????????<td><img?src="startNow.png"?onclick="version='keyboard';startFlashGame(paraKeyboardVersion);"?class=imageButton></td>??
172:????????</tr></table>??
173:????</div>??
174:????<div?175:????????<table?width=176:????????????<td?valign=top>??
177:????????????????<div?class=gameVersion>重力感应版</div>??
178:????????????????<div?class=gameGuide>左右倾斜手机向左或向右,虚拟键盘的空格键跳跃。</div>??
179:????????????</td>??
180:????????????<td><img?src="startNow.png"?onclick="version='sensor';startFlashGame(paraSensorVersion);"?181:????????</tr></table>??
182:????</div>??
183:????</BODY>??
184:????</HTML>??
?