做了一个很简单小游戏,东西上升,点击后消失,用的框架是createjs。但发现在微信端点击游戏里面的对象时会有短暂的卡顿 不知道是代码写的哪里不对影响性能了,并且andriod 在微信里看的时候对象上升也会有一些卡顿。求优化方式 谢谢核心游戏代码
var canvas = document.getElementById("canvas"); var stage = new createjs.Stage(canvas); createjs.Touch.enable(stage); var container = new createjs.Container(); stage.addChild(container); for (var i = 0; i < 10; i++) { var ball = new createjs.Bitmap(queue.getResult("ball")); ball.point = 30; ball.speed = 4; ball.x = (canvas.width-100) * Math.random(); ball.y = canvas.width+50*Math.random()*20; ball.cursor = "pointer"; ball.on("mousedown", function () { this.visible = false; }); container.addChild(ball); stage.addChild(container); } createjs.Ticker.timingMode = createjs.Ticker.RAF; createjs.Ticker.setFPS(60); createjs.Ticker.addEventListener("tick", tick); function tick(event) { var l = container.getNumChildren() ; for (var i = 0; i < l; i++) { shape = container.getChildAt(i); shape.y = shape.y-shape.speed; if(shape.y<-250||!shape.visible){ shape.x = (canvas.width-150) * Math.random(); shape.y = canvas.height; shape.visible = true; } } stage.update(event); 线上地址 http://1.snackwei.sinaapp.com/gameDemo/