Typescript를 사용하여 PIXI.js를 사용하여 원을 애니메이션합니다. 현재 원은 오른쪽 경계에서 아래 경계로 튀어 오르고 있습니다. 나는 또한 위쪽과 왼쪽에서 튀어 나와야한다.PIXI.js와 Typescript를 사용하여 원을 애니메이션하기
나는이 언어에 익숙하지 않으며, 대부분은 이해하기가 어렵다. 나는 '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>
어떤 접근 방식을 시도 했습니까? –