【发布时间】:2014-09-12 00:19:59
【问题描述】:
我正在使用 Typescript 使用 PIXI.js 为圆圈设置动画。目前,圆圈从底部边界反弹,然后从右边界反弹。我还需要它从顶部和左侧反弹。
我对这门语言非常陌生,而且我在理解大部分内容时遇到了一些困难。我已经尝试过嵌套“else”语句,但我不确定这是否应该包含在这种情况下。
'main.ts'
///<reference path="PIXI.d.ts"/>
///<reference path="setup.ts"/>
var drawing:PIXI.Graphics = new PIXI.Graphics();
stage.addChild(drawing);
animate();
function animate() {
renderer.render(stage);
draw();
requestAnimationFrame(animate);
}
var x:number = 0;
var y:number = 0;
var xspeed:number = 2;
var yspeed:number = 2;
// MY CODE
function draw(){
// clear drawing
drawing.clear();
// draw circle
drawing.beginFill(0x999999);
drawing.drawCircle(x,y,100);
// move circle down and to the right for the next frame
x += xspeed;
y += yspeed;
// set boundary for circle to bounce from y
if(y > 600){
// bounce the circle
yspeed *= -1;
// affix to the bottom of the stage
y = 600;
}
// set boundary for circle to bounce from x
if(x > 800){
xspeed *= -1;
x = 800;
}
}
HTML
<script src="src/pixi.js"></script>
<script src="src/setup.js"></script>
<script src="src/main.js"></script>
</body>
</html>
【问题讨论】:
-
你尝试过哪些方法?
标签: javascript animation typescript pixi.js