Skip to content

Commit

Permalink
Added camera target game object
Browse files Browse the repository at this point in the history
  • Loading branch information
STRd6 committed Apr 30, 2013
1 parent e7b05b9 commit 52b7211
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions source/camera_target.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CameraTarget = (I={}) ->
Object.reverseMerge I,
target: "Player.controller=0"
lead: 1.25

self = GameObject(I).extend
draw: -> # NOP

self.on "update", (canvas) ->
if target = engine.first(I.target)
targetPosition = target.position()
targetVelocity = target.velocity()

# Camera should lead target's position by a multiple of the targets velocity
position = targetPosition.add(targetVelocity.scale(I.lead))

I.x = position.x
I.y = position.y

return self

0 comments on commit 52b7211

Please sign in to comment.