| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- --[[
- Copyright (c) 2011-2014 chukong-inc.com
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ]]
- local Node = cc.Node
- function Node:add(child, zorder, tag)
- if tag then
- self:addChild(child, zorder, tag)
- elseif zorder then
- self:addChild(child, zorder)
- else
- self:addChild(child)
- end
- return self
- end
- function Node:addTo(parent, zorder, tag)
- if tag then
- parent:addChild(self, zorder, tag)
- elseif zorder then
- parent:addChild(self, zorder)
- else
- parent:addChild(self)
- end
- return self
- end
- function Node:removeSelf()
- self:removeFromParent()
- return self
- end
- function Node:align(anchorPoint, x, y)
- self:setAnchorPoint(anchorPoint)
- return self:move(x, y)
- end
- function Node:show()
- self:setVisible(true)
- return self
- end
- function Node:hide()
- self:setVisible(false)
- return self
- end
- function Node:move(x, y)
- if y then
- self:setPosition(x, y)
- else
- self:setPosition(x)
- end
- return self
- end
- function Node:moveTo(args)
- transition.moveTo(self, args)
- return self
- end
- function Node:moveBy(args)
- transition.moveBy(self, args)
- return self
- end
- function Node:fadeIn(args)
- transition.fadeIn(self, args)
- return self
- end
- function Node:fadeOut(args)
- transition.fadeOut(self, args)
- return self
- end
- function Node:fadeTo(args)
- transition.fadeTo(self, args)
- return self
- end
- function Node:rotate(rotation)
- self:setRotation(rotation)
- return self
- end
- function Node:rotateTo(args)
- transition.rotateTo(self, args)
- return self
- end
- function Node:rotateBy(args)
- transition.rotateBy(self, args)
- return self
- end
- function Node:scaleTo(args)
- transition.scaleTo(self, args)
- return self
- end
- function Node:onUpdate(callback)
- self:scheduleUpdateWithPriorityLua(callback, 0)
- return self
- end
- Node.scheduleUpdate = Node.onUpdate
- function Node:onNodeEvent(eventName, callback)
- if "enter" == eventName then
- self.onEnterCallback_ = callback
- elseif "exit" == eventName then
- self.onExitCallback_ = callback
- elseif "enterTransitionFinish" == eventName then
- self.onEnterTransitionFinishCallback_ = callback
- elseif "exitTransitionStart" == eventName then
- self.onExitTransitionStartCallback_ = callback
- elseif "cleanup" == eventName then
- self.onCleanupCallback_ = callback
- end
- self:enableNodeEvents()
- end
- function Node:enableNodeEvents()
- if self.isNodeEventEnabled_ then
- return self
- end
- self:registerScriptHandler(function(state)
- if state == "enter" then
- self:onEnter_()
- elseif state == "exit" then
- self:onExit_()
- elseif state == "enterTransitionFinish" then
- self:onEnterTransitionFinish_()
- elseif state == "exitTransitionStart" then
- self:onExitTransitionStart_()
- elseif state == "cleanup" then
- self:onCleanup_()
- end
- end)
- self.isNodeEventEnabled_ = true
- return self
- end
- function Node:disableNodeEvents()
- self:unregisterScriptHandler()
- self.isNodeEventEnabled_ = false
- return self
- end
- function Node:onEnter()
- end
- function Node:onExit()
- end
- function Node:onEnterTransitionFinish()
- end
- function Node:onExitTransitionStart()
- end
- function Node:onCleanup()
- end
- function Node:onEnter_()
- self:onEnter()
- if not self.onEnterCallback_ then
- return
- end
- self:onEnterCallback_()
- end
- function Node:onExit_()
- self:onExit()
- if not self.onExitCallback_ then
- return
- end
- self:onExitCallback_()
- end
- function Node:onEnterTransitionFinish_()
- self:onEnterTransitionFinish()
- if not self.onEnterTransitionFinishCallback_ then
- return
- end
- self:onEnterTransitionFinishCallback_()
- end
- function Node:onExitTransitionStart_()
- self:onExitTransitionStart()
- if not self.onExitTransitionStartCallback_ then
- return
- end
- self:onExitTransitionStartCallback_()
- end
- function Node:onCleanup_()
- self:onCleanup()
- if not self.onCleanupCallback_ then
- return
- end
- self:onCleanupCallback_()
- end
|