Skip to content

Instantly share code, notes, and snippets.

@gawaooooo
Created March 13, 2013 03:45
Show Gist options
  • Save gawaooooo/5149242 to your computer and use it in GitHub Desktop.
Save gawaooooo/5149242 to your computer and use it in GitHub Desktop.
JavaScriptで横揺れ
count = 0
degree = 0
radian = 0
speed = 25
radius = 5
beforeLeft = @targetEnemy.css('left')
# centerX = parseInt(@targetEnemy.css('left'), 10) /2
x = (if beforeLeft is 'auto' then 0 else parseInt(beforeLeft, 10))
timer = setInterval(=>
if count <= 100
degree += speed
# degreeは0~360
degree = (degree % 360 + 360) % 360
radian = degree * Math.PI / 180
@targetEnemy.css
left: x + (Math.cos(radian) * radius) + 'px'
count += 1
else
clearInterval timer if count > 100
, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment