cocos2d-x lua 類對象的使用

在lua中使用類對象很簡單也很方便,下面以創建精靈爲例

require "Cocos2d"
require "Cocos2dConstants"

--精靈類測試

local testSprite = class("testSprite",function (name)

return cc.Sprite:create(name)
	
end)


function testSprite:createSprite(name)

--創建精靈
	local sp = testSprite.new(name)
	
	return sp
	
end

--返回精靈類對象
return testSprite

在main.lua中這麼調用

 local tests=require("testSprite")
    local sp3=tests:createSprite("land.png")
    sp3:setPosition(180,250)
    layer:addChild(sp3,1)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章