lua练习2

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:12:341330browse

今天的第二个任务和第一个差不多,不同的是:要在弹出的UI里包括,一个关闭,这个关闭是remove而不是不可见,点击播放按钮播放个动画 在下面的按键反应的函数中,与以往不同的是没有用local定义newui2,也没用全局变量,因为本.lua文件中其他函数要用到这个

今天的第二个任务和第一个差不多,不同的是:要在弹出的UI里包括,一个关闭,这个关闭是remove而不是不可见,点击播放按钮播放个动画


在下面的按键反应的函数中,与以往不同的是没有用local定义newui2,也没用全局变量,因为本.lua文件中其他函数要用到这个变量,此外应尽量尽量避免使用全局的变量,不小心就会导致未知的错误,查找起来特别的困难。

function MainScene:onChange(tag, event)      
    if event == TouchEventType.TOUCH_EVENT_ENDED then
        self.newui2 = self:createCocostudioUI2()
        self.newui2:ignoreAnchorPointForPosition(false)
        self.newui2:setScale(0.5)
        self.newui2:setAnchorPoint(CCPoint(0.5, 0.5))
        self.newui2:setPosition(CCPoint(display.cx - 70,display.cy))
        self:addChild(self.newui2)
    end   
end
在关闭按钮的函数里,这里也尽量不要用也尽量不要用removeFromParentAndcleanup(true)。removeFromParent是从父节点直接删除,removeFromParentAndCleanup是从父节点中删除当前子节点 如果Cleanup为true则删除当前节点的所有动作及回调函数
function MainScene:onChangeClose(tag, event)
    if event == TouchEventType.TOUCH_EVENT_ENDED then
       self.newui2:removeFromParent()
    end
end




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn