标签:android cWeb style blog http color io os 使用
前些日子看到了一则新闻,flappybird原作者将携新游戏SwingCopters来袭,准备再靠这款姊妹篇游戏引爆大众眼球。就是下面这个小游戏:
(function(){ var lastTime = 0; var vendors = [‘ms‘, ‘moz‘, ‘webkit‘, ‘o‘]; for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { window.requestAnimationFrame = window[vendors[x] + ‘RequestAnimationFrame‘]; window.cancelAnimationFrame = window[vendors[x] + ‘CancelAnimationFrame‘] || window[vendors[x] + ‘CancelRequestAnimationFrame‘]; } if (!window.requestAnimationFrame) window.requestAnimationFrame = function(callback, element) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); lastTime = currTime + timeToCall; return id; } if (!window.cancelAnimationFrame) window.cancelAnimationFrame = function(id) { clearTimeout(id); } }());
下面我把一些技术细节来介绍下,介于小弟也是第一次做游戏,有些地方的实现不免走了弯路,或者损耗性能,有大牛发现了请一定赐教~
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
html, body{ height: 100%; position: relative; margin: 0; overflow: hidden; -webkit-user-select:none; }
#container{ height: 100%; position: relative; overflow: hidden; }
@media screen and (min-width: 1024px) { #container{ width: 360px; margin: 0 auto; } }
var game = { bgMove : function(){ posMark += 2; container.css(‘background-position‘, ‘0 ‘+posMark+‘px‘); timmer = requestAnimationFrame(game.bgMove); } }
@-webkit-keyframes flyr{ 0%{ background-position: 0 0; } 100%{ background-position: -108px 0; } }
.flyr{ -webkit-animation:flyr 200ms steps(2) 0 infinite; }
@-webkit-keyframes up{ 0%{ bottom: 0; } 100%{ bottom: 44%; } }
.flyl{ -webkit-animation:flyl 200ms steps(2) 0 infinite, up 4s linear 0 1 normal forwards; }
@-webkit-keyframes mover{ 0%{ left : 0; } 100%{ left : 100%; } }
.flyl{ left: 0 !important; -webkit-animation:flyl 200ms steps(2) 0 infinite, up 4s linear 0 1 normal forwards; } .flyr{ left: 100% !important; -webkit-animation:flyr 200ms steps(2) 0 infinite, up 4s linear 0 1 normal forwards; }
-webkit-transition : left 1.5s 0 linear;
$(document).on(‘click‘, function(){ if(++direction%2==0){ player[0].className = ‘flyl‘; } else{ player[0].className = ‘flyr‘; } });
-webkit-transform-origin:center 4px;
bgMove : function(){ game.generateHand();//产生横梁 posMark += 2; container.css(‘background-position‘, ‘0 ‘+posMark+‘px‘); var hands = $(‘.hand_l, .hand_r‘); hands.each(function(index, element){ var _this = $(this), thisTop = parseInt(_this.css(‘top‘)); if(thisTop>cHeight){ _this.remove(); } else{ thisTop += 2; _this.css(‘top‘, thisTop+‘px‘); } if(thisTop>player.offset().top+e1H){ //已经位于下方 if(!_this.data(‘pass‘) && index%2==0){ scroeC.text(++score); _this.data(‘pass‘, 1); } } else{ //碰撞检测 if(game.impactCheck(player, _this.find(‘.t‘))){ game.stop(); return false; } } }); timmer = requestAnimationFrame(game.bgMove); }
isMobile : function(){ var sUserAgent= navigator.userAgent.toLowerCase(), bIsIpad= sUserAgent.match(/ipad/i) == "ipad", bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os", bIsMidp= sUserAgent.match(/midp/i) == "midp", bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4", bIsUc= sUserAgent.match(/ucweb/i) == "ucweb", bIsAndroid= sUserAgent.match(/android/i) == "android", bIsCE= sUserAgent.match(/windows ce/i) == "windows ce", bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile", bIsWebview = sUserAgent.match(/webview/i) == "webview"; return (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM); } var eventType = this.isMobile() ? ‘touchstart‘ : ‘click‘; $(document).on(eventType, function(){ if(++direction%2==0){ player[0].className = ‘flyl‘; } else{ player[0].className = ‘flyr‘; } });
<a id="share" href="javascript:(function(){window.open(‘http://v.t.sina.com.cn/share/share.php?title=网页版SwingCopters,来,看看你有多挫&url=idoube.com/proj/SwingCopters&source=bookmark&pic=http%3A%2F%2Fidoube.com%2Fproj%2FSwingCopters%2FSwingCopters%2Fshot.jpg‘,‘_blank‘,‘width=450,height=400‘);})()">分享到微博</a>
标签:android cWeb style blog http color io os 使用
原文地址:http://www.cnblogs.com/lvdabao/p/3968464.html