Skip to content
Newer
Older
100644 32 lines (27 sloc) 1.1 KB
442c873 @joevennix Finally implemented deterministic physics and changed resolveCollisio…
joevennix authored
1 # simple button class handles mousedown and click events
2 # Constructor: new Button(x, y, width, height, defaultImage, activeImage, scene)
3 # == Delegate Methods == (* means Required)
4 # buttonDown(button)
5 # buttonUp(button)
6 # buttonPress(button) *
7 class Button extends Sprite
8 constructor: (@x, @y, @width, @height, @img, @downImg, @scene) ->
9 @down = false
10 super(@x, @y, @width, @height, @img)
11
12 handleMouseDown: (e) ->
13 # check if event is inside bounding box
14 @down = Helpers.inRect(e.x, e.y, @x, @y, @width, @height)
15
16 handleMouseUp: (e) ->
17 # check if event is inside bounding box
18 if @down && Helpers.inRect(e.x, e.y, @x, @y, @width, @height)
19 @scene.buttonPressed(this) if @scene # pass event back to delegate
20 @down = false
21
22 handleMouseMove: (e) ->
23 @down = Helpers.inRect(e.x, e.y, @x, @y, @width, @height) if @down
24
25 handleClick: (e) ->
26 @down = false
0b58577 @joevennix Improved portability, rewrote resolveCollisions()
joevennix authored
27 # if Helpers.inRect(e.x, e.y, @x, @y, @width, @height)
28 # @scene.buttonPressed(this) if @scene # pass event back to delegate
442c873 @joevennix Finally implemented deterministic physics and changed resolveCollisio…
joevennix authored
29
30 draw: (ctx) ->
31 return unless @img
32 ctx.drawImage (if @down then @downImg else @img), Helpers.round(@x), Helpers.round(@y)
Something went wrong with that request. Please try again.