不知道问题粗在哪里呀,

Dontmissingu HTML5 Canvas 应用 最后由 上海小胖 于2016年10月14日回复

  • 1 回答
  • 1k 浏览
/** * Created by Administrator on 2016/10/14. */    var canvas;var stage;var img = new Image();var sprite;window.onload = function(){canvas = document.getElementById("canvas");stage = new createjs.Stage(canvas);stage.addEventListener("stagemousedown",clickCanvas);stage.addEventListener("stagemousemove",moveCanvas);var data = {image:["6.png"],frame:{width:20,height:20,regX:10,regY:10}        }sprite = new createjs.Sprite(new createjs.SpriteSheet(data));createjs.Ticker.setFPS(20);createjs.Ticker.addEventListener("tick",tick);    }function tick(e){var t = stage.getNumChildren();for(var i=t-1;i > 0 ;i--){var s = stage.getChildAt(i);s.vY +=2;s.vX +=1;s.x += s.vX;s.y += s.vY;s.scaleX = s.scaleY =s.scaleX + s.vS;s.alpha += s.vA;if(s.alpha <= 0 || s.y>canvas.height){stage.removeChildAt(i);            }        }stage.update(e);    }function clickCanvas(e){addS(Math.random()*200 + 100,stage.mouseX,stage.mouseY,2);    }function moveCanvas(e){addS(Math.random()*2 + 1,stage.mouseX,stage.mouseY,1);    }function addS(count,x,y,speed){for(var i = 0;i < count;i++){var s = sprite.clone();s.x = x;s.y = y;s.alpha = Math.random()*0.5 + 0.5;s.scaleX = s.scaleY = Math.random() + 0.3;var a = Math.PI * 0.2 * Math.random();var v = (Math.random() - 0.5 ) * 30 *speed;s.vX = Math.cos(a)*v;s.vY = Math.sin(a)*v;s.vS = (Math.random() - 0.5 ) * 0.2;s.vA = -Math.random() * 0.05 - 0.01;stage.addChild(s);        }    }
<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"><title></title><script src="easeljs-0.8.2.min.js"></script></head><body><canvas id="canvas" height="1000px" width="500px"></canvas><script src="app.js"></script></body></html>