Created
December 5, 2012 16:45
-
-
Save vib3oh/4217284 to your computer and use it in GitHub Desktop.
Custom Event Tutorial (OO-Lua, 3/4) http://blog.ardentkid.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Mouse.lua | |
| local scene = scene | |
| local Mouse = {Instances={}} | |
| --MOUSE CLASS METHODS (FIRST LETTER IS CAPITOLIZED) | |
| Mouse.Get = scene.Get | |
| Mouse.Show = scene.Show | |
| Mouse.Dispose = scene.Dispose | |
| function Mouse:New() | |
| --creates a mouse instance | |
| local mouse = display.newImage('mouse.png') | |
| mouse.show = self.show | |
| mouse.hide = self.hide | |
| table.insert(self.Instances, mouse) | |
| return mouse | |
| end | |
| --MOUSE INSTANCE METHODS (FIRST LETTER IS LOWERCASE) | |
| function Mouse:show(config) | |
| --show this mouse somewhere on-screen | |
| self.x, self.y = config.x, config.y | |
| self.isVisible = true | |
| --tell the world this mouse has shown | |
| scene:dispatchEvent({name='onMouseShow', x=self.x, y=self.y}) | |
| end | |
| function Mouse:hide() | |
| --hide this mouse | |
| Mouse:Dispose(self) | |
| self.isVisible = false | |
| --then tell the world this mouse has hidden. | |
| scene:dispatchEvent({name='onMouseHide'}) | |
| end | |
| --CREATE 1 MOUSE | |
| Mouse:New() | |
| return Mouse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment