/ld26

To get this branch, use:
bzr branch /bzr/ld26

« back to all changes in this revision

Viewing changes to zoetrope/ui/cursor.lua

  • Committer: Josh C
  • Date: 2013-04-27 16:36:06 UTC
  • Revision ID: josh@9ix.org-20130427163606-0eef0f5v9wbzoi0j
zoetrope 1.4

Show diffs side-by-side

added added

removed removed

 
1
-- Class: Cursor
 
2
-- A cursor is a group that follows the user's cursor.
 
3
 
 
4
Cursor = Group:extend{
 
5
        -- Property: hotspot
 
6
        -- A table with x and y offsets for the cursor. e.g. if
 
7
        -- you want the user to click with a center of a crosshairs
 
8
        -- image, set this to half the width and half the height of
 
9
        -- the image.
 
10
        hotspot = { x = 0, y = 0 },
 
11
 
 
12
        new = function (self, obj)
 
13
                obj = self:extend(obj)
 
14
                the.cursor = obj
 
15
                if obj.onNew then obj:onNew() end
 
16
                return obj
 
17
        end,
 
18
 
 
19
        update = function (self, elapsed)
 
20
                -- follow the mouse
 
21
 
 
22
                self.translate.x = the.mouse.x - self.hotspot.x
 
23
                self.translate.y = the.mouse.y - self.hotspot.y
 
24
                
 
25
                Group.update(self, elapsed)
 
26
        end
 
27
}