今天的第二个任务和第一个差不多,不同的是:要在弹出的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() endend
