mirror of https://github.com/axmolengine/axmol.git
add Cocos Studio support
This commit is contained in:
parent
653b15b4b8
commit
82c40ca5e8
|
@ -5,6 +5,18 @@ function ViewBase:ctor(app, name)
|
|||
self:enableNodeEvents()
|
||||
self.app_ = app
|
||||
self.name_ = name
|
||||
|
||||
-- check CSB resource file
|
||||
local res = rawget(self.class, "RESOURCE_FILENAME")
|
||||
if res then
|
||||
self:createResoueceNode(res)
|
||||
end
|
||||
|
||||
local binding = rawget(self.class, "RESOURCE_BINDING")
|
||||
if res and binding then
|
||||
self:createResoueceBinding(binding)
|
||||
end
|
||||
|
||||
if self.onCreate then self:onCreate() end
|
||||
end
|
||||
|
||||
|
@ -16,6 +28,35 @@ function ViewBase:getName()
|
|||
return self.name_
|
||||
end
|
||||
|
||||
function ViewBase:getResourceNode()
|
||||
return self.resourceNode_
|
||||
end
|
||||
|
||||
function ViewBase:createResoueceNode(resourceFilename)
|
||||
if self.resourceNode_ then
|
||||
self.resourceNode_:removeSelf()
|
||||
self.resourceNode_ = nil
|
||||
end
|
||||
self.resourceNode_ = cc.CSLoader:createNode(resourceFilename)
|
||||
assert(self.resourceNode_, string.format("ViewBase:createResoueceNode() - load resouce node from file \"%s\" failed", resourceFilename))
|
||||
self:addChild(self.resourceNode_)
|
||||
end
|
||||
|
||||
function ViewBase:createResoueceBinding(binding)
|
||||
assert(self.resourceNode_, "ViewBase:createResoueceBinding() - not load resource node")
|
||||
for nodeName, nodeBinding in pairs(binding) do
|
||||
local node = self.resourceNode_:getChildByName(nodeName)
|
||||
if nodeBinding.varname then
|
||||
self[nodeBinding.varname] = node
|
||||
end
|
||||
for _, event in ipairs(nodeBinding.events or {}) do
|
||||
if event.event == "touch" then
|
||||
node:onTouch(handler(self, self[event.method]))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ViewBase:showWithScene(transition, time, more)
|
||||
self:setVisible(true)
|
||||
local scene = display.newScene(self.name_)
|
||||
|
|
Loading…
Reference in New Issue