Coffeescript Game Tutorial Action

원이 대각선 아래로 움직이는 코드이다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
x = 150
y = 150
dx = 2
dy = 4
ctx = null
init = ->
canvas = document.getElementById("myCanvas")
ctx = canvas.getContext("2d")
return setInterval(draw, 10)
draw = ->
ctx.clearRect(0, 0, 300, 300)
ctx.beginPath()
ctx.arc(x, y, 10, 0, Math.PI*2, true)
ctx.closePath()
ctx.fill()
x += dx;
y += dy;
window.onload = ->
init()

Reference

Share Comments