mirror of https://github.com/axmolengine/axmol.git
issue #2768:Add Armature lua binding and releated test samples
This commit is contained in:
parent
850efa5eac
commit
357466bab2
|
@ -56,4 +56,11 @@
|
|||
|
||||
#include "CCDeprecated-ext.h"
|
||||
|
||||
#include "CCArmature/CCArmature.h"
|
||||
#include "CCArmature/animation/CCArmatureAnimation.h"
|
||||
#include "CCArmature/display/CCSkin.h"
|
||||
#include "CCArmature/CCBone.h"
|
||||
#include "CCArmature/utils/CCArmatureDataManager.h"
|
||||
#include "CCArmature/datas/CCDatas.h"
|
||||
|
||||
#endif /* __COCOS2D_EXT_H__ */
|
||||
|
|
|
@ -0,0 +1,815 @@
|
|||
local itemTagBasic = 1000
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
local scheduler = cc.Director:getInstance():getScheduler()
|
||||
local ArmatureTestIndex =
|
||||
{
|
||||
TEST_COCOSTUDIO_WITH_SKELETON = 1,
|
||||
TEST_COCOSTUDIO_WITHOUT_SKELETON = 2,
|
||||
TEST_DRAGON_BONES_2_0 = 3,
|
||||
TEST_PERFORMANCE = 4,
|
||||
TEST_CHANGE_ZORDER = 5,
|
||||
TEST_ANIMATION_EVENT = 6,
|
||||
TEST_PARTICLE_DISPLAY = 7,
|
||||
TEST_USE_DIFFERENT_PICTURE = 8,
|
||||
TEST_BOUDINGBOX = 9,
|
||||
TEST_ANCHORPOINT = 10,
|
||||
TEST_ARMATURE_NESTING = 11,
|
||||
}
|
||||
local armatureSceneIdx = ArmatureTestIndex.TEST_COCOSTUDIO_WITH_SKELETON
|
||||
|
||||
local ArmatureTestScene = class("ArmatureTestScene")
|
||||
ArmatureTestScene.__index = ArmatureTestScene
|
||||
|
||||
function ArmatureTestScene.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, ArmatureTestScene)
|
||||
return target
|
||||
end
|
||||
|
||||
function ArmatureTestScene:runThisTest()
|
||||
cc.ArmatureDataManager:getInstance():addArmatureFileInfo("armature/TestBone0.png", "armature/TestBone0.plist", "armature/TestBone.json")
|
||||
cc.ArmatureDataManager:getInstance():addArmatureFileInfo("armature/Cowboy0.png", "armature/Cowboy0.plist", "armature/Cowboy.json")
|
||||
cc.ArmatureDataManager:getInstance():addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml")
|
||||
cc.ArmatureDataManager:getInstance():addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml")
|
||||
cc.ArmatureDataManager:getInstance():addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml")
|
||||
cc.ArmatureDataManager:getInstance():addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml")
|
||||
cc.ArmatureDataManager:getInstance():addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml")
|
||||
|
||||
armatureSceneIdx = ArmatureTestIndex.TEST_COCOSTUDIO_WITH_SKELETON
|
||||
self:addChild(restartArmatureTest())
|
||||
end
|
||||
|
||||
function ArmatureTestScene.create()
|
||||
local scene = ArmatureTestScene.extend(cc.Scene:create())
|
||||
local bg = cc.Sprite:create("armature/bg.jpg")
|
||||
bg:setPosition(VisibleRect:center())
|
||||
|
||||
local scaleX = VisibleRect:getVisibleRect().width / bg:getContentSize().width
|
||||
local scaleY = VisibleRect:getVisibleRect().height / bg:getContentSize().height
|
||||
|
||||
bg:setScaleX(scaleX)
|
||||
bg:setScaleY(scaleY)
|
||||
|
||||
scene:addChild(bg)
|
||||
return scene
|
||||
end
|
||||
|
||||
function ArmatureTestScene.toMainMenuCallback()
|
||||
cc.ArmatureDataManager:purgeArmatureSystem()
|
||||
end
|
||||
|
||||
local ArmatureTestLayer = class("ArmatureTestLayer")
|
||||
ArmatureTestLayer.__index = ArmatureTestLayer
|
||||
|
||||
function ArmatureTestLayer:onEnter()
|
||||
|
||||
end
|
||||
|
||||
function ArmatureTestLayer.title(idx)
|
||||
if ArmatureTestIndex.TEST_COCOSTUDIO_WITH_SKELETON == idx then
|
||||
return "Test Export From CocoStudio With Skeleton Effect"
|
||||
elseif ArmatureTestIndex.TEST_COCOSTUDIO_WITHOUT_SKELETON == idx then
|
||||
return "Test Export From CocoStudio Without Skeleton Effect"
|
||||
elseif ArmatureTestIndex.TEST_DRAGON_BONES_2_0 == idx then
|
||||
return "Test Export From DragonBones version 2.0"
|
||||
elseif ArmatureTestIndex.TEST_PERFORMANCE == idx then
|
||||
return "Test Performance"
|
||||
elseif ArmatureTestIndex.TEST_CHANGE_ZORDER == idx then
|
||||
return "Test Change ZOrder Of Different Armature"
|
||||
elseif ArmatureTestIndex.TEST_ANIMATION_EVENT == idx then
|
||||
return "Test Armature Animation Event"
|
||||
elseif ArmatureTestIndex.TEST_PARTICLE_DISPLAY == idx then
|
||||
return "Test Particle Display"
|
||||
elseif ArmatureTestIndex.TEST_USE_DIFFERENT_PICTURE == idx then
|
||||
return "Test One Armature Use Different Picture"
|
||||
elseif ArmatureTestIndex.TEST_BOUDINGBOX == idx then
|
||||
return "Test BoundingBox"
|
||||
elseif ArmatureTestIndex.TEST_ANCHORPOINT == idx then
|
||||
return "Test Set AnchorPoint"
|
||||
elseif ArmatureTestIndex.TEST_ARMATURE_NESTING == idx then
|
||||
return "Test Armature Nesting"
|
||||
end
|
||||
end
|
||||
|
||||
function ArmatureTestLayer.subTitle(idx)
|
||||
if ArmatureTestIndex.TEST_PERFORMANCE == idx then
|
||||
return "Current Armature Count : "
|
||||
elseif ArmatureTestIndex.TEST_PARTICLE_DISPLAY == idx then
|
||||
return "Touch to change animation"
|
||||
elseif ArmatureTestIndex.TEST_USE_DIFFERENT_PICTURE == idx then
|
||||
return "weapon and armature are in different picture"
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
function ArmatureTestLayer.create()
|
||||
local layer = ArmatureTestLayer.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
function ArmatureTestLayer.backCallback()
|
||||
local newScene = ArmatureTestScene.create()
|
||||
newScene:addChild(backArmatureTest())
|
||||
cc.Director:getInstance():replaceScene(newScene)
|
||||
end
|
||||
|
||||
function ArmatureTestLayer.restartCallback()
|
||||
local newScene = ArmatureTestScene.create()
|
||||
newScene:addChild(restartArmatureTest())
|
||||
cc.Director:getInstance():replaceScene(newScene)
|
||||
end
|
||||
|
||||
function ArmatureTestLayer.nextCallback()
|
||||
local newScene = ArmatureTestScene.create()
|
||||
newScene:addChild(nextArmatureTest())
|
||||
cc.Director:getInstance():replaceScene(newScene)
|
||||
end
|
||||
|
||||
function ArmatureTestLayer:createMenu()
|
||||
local menu = cc.Menu:create()
|
||||
|
||||
local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2)
|
||||
item1:registerScriptTapHandler(self.backCallback)
|
||||
menu:addChild(item1,itemTagBasic)
|
||||
local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2)
|
||||
item2:registerScriptTapHandler(self.restartCallback)
|
||||
menu:addChild(item2,itemTagBasic)
|
||||
local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2)
|
||||
menu:addChild(item3,itemTagBasic)
|
||||
item3:registerScriptTapHandler(self.nextCallback)
|
||||
|
||||
local size = cc.Director:getInstance():getWinSize()
|
||||
item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2))
|
||||
item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2))
|
||||
item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2))
|
||||
|
||||
menu:setPosition(cc.p(0, 0))
|
||||
|
||||
self:addChild(menu)
|
||||
end
|
||||
|
||||
function ArmatureTestLayer.toExtensionMenu()
|
||||
local scene = ExtensionsTestMain()
|
||||
if scene ~= nil then
|
||||
cc.Director:getInstance():replaceScene(scene)
|
||||
end
|
||||
end
|
||||
|
||||
function ArmatureTestLayer:createToExtensionMenu()
|
||||
cc.MenuItemFont:setFontName("Arial")
|
||||
cc.MenuItemFont:setFontSize(24)
|
||||
local menuItemFont = cc.MenuItemFont:create("Back")
|
||||
menuItemFont:setPosition(cc.p(VisibleRect:rightBottom().x - 50, VisibleRect:rightBottom().y + 25))
|
||||
menuItemFont:registerScriptTapHandler(ArmatureTestLayer.toExtensionMenu)
|
||||
|
||||
local backMenu = cc.Menu:create()
|
||||
backMenu:addChild(menuItemFont)
|
||||
backMenu:setPosition(cc.p(0, 0))
|
||||
self:addChild(backMenu,10)
|
||||
end
|
||||
|
||||
function ArmatureTestLayer:creatTitleAndSubTitle(idx)
|
||||
local title = cc.LabelTTF:create(ArmatureTestLayer.title(idx),"Arial",18)
|
||||
title:setColor(cc.c3b(0,0,0))
|
||||
self:addChild(title, 1, 10000)
|
||||
title:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 30))
|
||||
local subTitle = nil
|
||||
if "" ~= ArmatureTestLayer.subTitle(idx) then
|
||||
local subTitle = cc.LabelTTF:create(ArmatureTestLayer.subTitle(idx), "Arial", 18)
|
||||
subTitle:setColor(cc.c3b(0,0,0))
|
||||
self:addChild(subTitle, 1, 10001)
|
||||
subTitle:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 60) )
|
||||
end
|
||||
end
|
||||
|
||||
local TestCSWithSkeleton = class("TestCSWithSkeleton",ArmatureTestLayer)
|
||||
TestCSWithSkeleton.__index = TestCSWithSkeleton
|
||||
|
||||
function TestCSWithSkeleton.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestCSWithSkeleton)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestCSWithSkeleton:onEnter()
|
||||
local armature = cc.Armature:create("Cowboy")
|
||||
armature:getAnimation():playByIndex(0)
|
||||
armature:setScale(0.2)
|
||||
armature:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
armature:setPosition(cc.p(winSize.width / 2, winSize.height / 2))
|
||||
self:addChild(armature)
|
||||
end
|
||||
|
||||
function TestCSWithSkeleton.create()
|
||||
local layer = TestCSWithSkeleton.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestCSWithoutSkeleton = class("TestCSWithoutSkeleton",ArmatureTestLayer)
|
||||
TestCSWithoutSkeleton.__index = TestCSWithoutSkeleton
|
||||
|
||||
function TestCSWithoutSkeleton.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestCSWithoutSkeleton)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestCSWithoutSkeleton:onEnter()
|
||||
local armature = cc.Armature:create("TestBone")
|
||||
armature:getAnimation():playByIndex(0)
|
||||
armature:setScale(0.2)
|
||||
armature:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
armature:setPosition(cc.p(winSize.width / 2, winSize.height / 2))
|
||||
self:addChild(armature)
|
||||
end
|
||||
|
||||
function TestCSWithoutSkeleton.create()
|
||||
local layer = TestCSWithoutSkeleton.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestDragonBones20 = class("TestDragonBones20",ArmatureTestLayer)
|
||||
TestDragonBones20.__index = TestDragonBones20
|
||||
|
||||
function TestDragonBones20.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestDragonBones20)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestDragonBones20:onEnter()
|
||||
local armature = cc.Armature:create("Dragon")
|
||||
armature:getAnimation():playByIndex(1)
|
||||
armature:getAnimation():setAnimationScale(0.4)
|
||||
armature:setScale(0.6)
|
||||
armature:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
armature:setPosition(cc.p(winSize.width / 2, winSize.height / 2))
|
||||
self:addChild(armature)
|
||||
end
|
||||
|
||||
function TestDragonBones20.create()
|
||||
local layer = TestDragonBones20.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestPerformance = class("TestPerformance",ArmatureTestLayer)
|
||||
TestPerformance.__index = TestPerformance
|
||||
TestPerformance.armatureCount = 0
|
||||
TestPerformance.times = 0
|
||||
TestPerformance.testPerformanceEntry = 0
|
||||
TestPerformance.selfLayer = nil
|
||||
|
||||
function TestPerformance.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestPerformance)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestPerformance.update(delta)
|
||||
TestPerformance.times = TestPerformance.times + delta
|
||||
if TestPerformance.times > 0.25 then
|
||||
TestPerformance.time = 0
|
||||
local armature = cc.Armature:create("Knight_f/Knight")
|
||||
armature:getAnimation():playByIndex(0)
|
||||
armature:setPosition(cc.p(50 + TestPerformance.armatureCount * 5, winSize.height / 2))
|
||||
armature:setScale(0.6)
|
||||
TestPerformance.armatureCount = TestPerformance.armatureCount + 1
|
||||
TestPerformance.selfLayer:addChild(armature,TestPerformance.armatureCount)
|
||||
|
||||
local subTitle = tolua.cast(TestPerformance.selfLayer:getChildByTag(10001),"LabelTTF")
|
||||
if nil ~= subTitle then
|
||||
local info = ArmatureTestLayer.subTitle(ArmatureTestIndex.TEST_PERFORMANCE) .. TestPerformance.armatureCount
|
||||
subTitle:setString(info)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function TestPerformance.onEnterOrExit(tag)
|
||||
if tag == "enter" then
|
||||
TestPerformance.testPerformanceEntry = scheduler:scheduleScriptFunc(TestPerformance.update, 0.0, false)
|
||||
elseif tag == "exit" then
|
||||
scheduler:unscheduleScriptEntry(TestPerformance.testPerformanceEntry)
|
||||
end
|
||||
end
|
||||
|
||||
function TestPerformance:onEnter()
|
||||
TestPerformance.armatureCount = 0
|
||||
TestPerformance.times = 0
|
||||
TestPerformance.selfLayer = nil
|
||||
self:registerScriptHandler(self.onEnterOrExit)
|
||||
end
|
||||
|
||||
function TestPerformance.create()
|
||||
local layer = TestPerformance.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
TestPerformance.selfLayer = layer
|
||||
end
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestCSWithoutSkeleton = class("TestCSWithoutSkeleton",ArmatureTestLayer)
|
||||
TestCSWithoutSkeleton.__index = TestCSWithoutSkeleton
|
||||
|
||||
function TestCSWithoutSkeleton.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestCSWithoutSkeleton)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestCSWithoutSkeleton:onEnter()
|
||||
local armature = cc.Armature:create("TestBone")
|
||||
armature:getAnimation():playByIndex(0)
|
||||
armature:setScale(0.2)
|
||||
armature:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
armature:setPosition(cc.p(winSize.width / 2, winSize.height / 2))
|
||||
self:addChild(armature)
|
||||
end
|
||||
|
||||
function TestCSWithoutSkeleton.create()
|
||||
local layer = TestCSWithoutSkeleton.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestChangeZorder = class("TestChangeZorder",ArmatureTestLayer)
|
||||
TestChangeZorder.__index = TestChangeZorder
|
||||
TestChangeZorder.currentTag = -1
|
||||
|
||||
function TestChangeZorder.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestChangeZorder)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestChangeZorder:onEnter()
|
||||
self.currentTag = -1
|
||||
|
||||
local armature = cc.Armature:create("Knight_f/Knight")
|
||||
armature:getAnimation():playByIndex(0)
|
||||
armature:setPosition(cc.p(winSize.width / 2, winSize.height / 2 - 100 ))
|
||||
armature:setScale(0.6)
|
||||
self.currentTag = self.currentTag + 1
|
||||
self:addChild(armature, self.currentTag, self.currentTag)
|
||||
|
||||
armature = cc.Armature:create("TestBone")
|
||||
armature:getAnimation():playByIndex(0)
|
||||
armature:setScale(0.24)
|
||||
armature:setPosition(cc.p(winSize.width / 2, winSize.height / 2 - 100))
|
||||
self.currentTag = self.currentTag + 1
|
||||
self:addChild(armature, self.currentTag, self.currentTag)
|
||||
|
||||
armature = cc.Armature:create("Dragon")
|
||||
armature:getAnimation():playByIndex(0)
|
||||
armature:setPosition(cc.p(winSize.width / 2, winSize.height / 2 - 100))
|
||||
armature:setScale(0.6)
|
||||
self.currentTag = self.currentTag + 1
|
||||
self:addChild(armature, self.currentTag, self.currentTag)
|
||||
|
||||
local function changeZorder(dt)
|
||||
local node = self:getChildByTag(self.currentTag)
|
||||
node:setZOrder(math.random(0,1) * 3)
|
||||
self.currentTag = (self.currentTag + 1) % 3
|
||||
end
|
||||
|
||||
schedule(self,changeZorder, 1)
|
||||
end
|
||||
|
||||
function TestChangeZorder.create()
|
||||
local layer = TestChangeZorder.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
return layer
|
||||
end
|
||||
|
||||
--UNDO callback
|
||||
local TestAnimationEvent = class("TestAnimationEvent",ArmatureTestLayer)
|
||||
TestAnimationEvent.__index = TestAnimationEvent
|
||||
|
||||
function TestAnimationEvent.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestAnimationEvent)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestAnimationEvent:onEnter()
|
||||
local armature = cc.Armature:create("Cowboy")
|
||||
armature:getAnimation():play("Fire")
|
||||
armature:setScaleX(-0.24)
|
||||
armature:setScaleY(0.24)
|
||||
armature:setPosition(cc.p(VisibleRect:left().x + 50, VisibleRect:left().y))
|
||||
--armature:getAnimation()->MovementEventSignal.connect(this, &TestAnimationEvent::animationEvent)
|
||||
self:addChild(armature)
|
||||
end
|
||||
|
||||
function TestAnimationEvent.create()
|
||||
local layer = TestAnimationEvent.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestParticleDisplay = class("TestParticleDisplay",ArmatureTestLayer)
|
||||
TestParticleDisplay.__index = TestParticleDisplay
|
||||
TestParticleDisplay.animationID = 0
|
||||
TestParticleDisplay.armature = nil
|
||||
|
||||
function TestParticleDisplay.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestParticleDisplay)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestParticleDisplay:onEnter()
|
||||
self:setTouchEnabled(true)
|
||||
self.animationID = 0
|
||||
|
||||
self.armature = cc.Armature:create("robot")
|
||||
self.armature:getAnimation():playByIndex(0)
|
||||
self.armature:setPosition(VisibleRect:center())
|
||||
self.armature:setScale(0.48)
|
||||
self:addChild(self.armature)
|
||||
|
||||
local displayData = cc.ParticleDisplayData:create()
|
||||
displayData:setParam("Particles/SmallSun.plist")
|
||||
|
||||
local bone = cc.Bone:create("p1")
|
||||
bone:addDisplay(displayData, 0)
|
||||
bone:changeDisplayByIndex(0, true)
|
||||
bone:setIgnoreMovementBoneData(true)
|
||||
bone:setZOrder(100)
|
||||
bone:setScale(1.2)
|
||||
self.armature:addBone(bone, "bady-a3")
|
||||
|
||||
bone = cc.Bone:create("p2")
|
||||
bone:addDisplay(displayData, 0)
|
||||
bone:changeDisplayByIndex(0, true)
|
||||
bone:setIgnoreMovementBoneData(true)
|
||||
bone:setZOrder(100)
|
||||
bone:setScale(1.2)
|
||||
self.armature:addBone(bone, "bady-a30")
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
self.animationID = (self.animationID + 1) % self.armature:getAnimation():getMovementCount()
|
||||
self.armature:getAnimation():playByIndex(self.animationID)
|
||||
return false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x,y)
|
||||
end
|
||||
end
|
||||
|
||||
self:registerScriptTouchHandler(onTouch)
|
||||
end
|
||||
|
||||
function TestParticleDisplay.create()
|
||||
local layer = TestParticleDisplay.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestUseMutiplePicture = class("TestUseMutiplePicture",ArmatureTestLayer)
|
||||
TestUseMutiplePicture.__index = TestUseMutiplePicture
|
||||
TestUseMutiplePicture.displayIndex = 0
|
||||
TestUseMutiplePicture.armature = nil
|
||||
|
||||
function TestUseMutiplePicture.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestUseMutiplePicture)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestUseMutiplePicture:onEnter()
|
||||
self:setTouchEnabled(true)
|
||||
self.displayIndex = 1
|
||||
|
||||
self.armature = cc.Armature:create("Knight_f/Knight")
|
||||
self.armature:getAnimation():playByIndex(0)
|
||||
self.armature:setPosition(cc.p(VisibleRect:left().x + 70, VisibleRect:left().y))
|
||||
self.armature:setScale(1.2)
|
||||
self:addChild(self.armature)
|
||||
|
||||
local weapon =
|
||||
{
|
||||
"weapon_f-sword.png",
|
||||
"weapon_f-sword2.png",
|
||||
"weapon_f-sword3.png",
|
||||
"weapon_f-sword4.png",
|
||||
"weapon_f-sword5.png",
|
||||
"weapon_f-knife.png",
|
||||
"weapon_f-hammer.png",
|
||||
};
|
||||
|
||||
local spriteDisplayData = cc.SpriteDisplayData:create()
|
||||
local i = 1
|
||||
for i = 1,table.getn(weapon) do
|
||||
spriteDisplayData:setParam(weapon[i])
|
||||
self.armature:getBone("weapon"):addDisplay(spriteDisplayData, i - 1)
|
||||
end
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
self.displayIndex = (self.displayIndex + 1) % (table.getn(weapon) - 1)
|
||||
self.armature:getBone("weapon"):changeDisplayByIndex(self.displayIndex, true)
|
||||
return false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x,y)
|
||||
end
|
||||
end
|
||||
|
||||
self:registerScriptTouchHandler(onTouch)
|
||||
end
|
||||
|
||||
function TestUseMutiplePicture.create()
|
||||
local layer = TestUseMutiplePicture.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestBoundingBox = class("TestBoundingBox",ArmatureTestLayer)
|
||||
TestBoundingBox.__index = TestBoundingBox
|
||||
|
||||
function TestBoundingBox.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestBoundingBox)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestBoundingBox:onEnter()
|
||||
local armature = cc.Armature:create("Cowboy")
|
||||
armature:getAnimation():playByIndex(0)
|
||||
armature:setPosition(VisibleRect:center())
|
||||
armature:setScale(0.2)
|
||||
self:addChild(armature)
|
||||
end
|
||||
|
||||
function TestBoundingBox.create()
|
||||
local layer = TestBoundingBox.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestAnchorPoint = class("TestAnchorPoint",ArmatureTestLayer)
|
||||
TestAnchorPoint.__index = TestAnchorPoint
|
||||
|
||||
function TestAnchorPoint.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestAnchorPoint)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestAnchorPoint:onEnter()
|
||||
local i = 1
|
||||
for i = 1 , 5 do
|
||||
local armature = cc.Armature:create("Cowboy")
|
||||
armature:getAnimation():playByIndex(0);
|
||||
armature:setPosition(VisibleRect:center())
|
||||
armature:setScale(0.2)
|
||||
self:addChild(armature, 0, i - 1)
|
||||
end
|
||||
|
||||
self:getChildByTag(0):setAnchorPoint(cc.p(0,0))
|
||||
self:getChildByTag(1):setAnchorPoint(cc.p(0,1))
|
||||
self:getChildByTag(2):setAnchorPoint(cc.p(1,0))
|
||||
self:getChildByTag(3):setAnchorPoint(cc.p(1,1))
|
||||
self:getChildByTag(4):setAnchorPoint(cc.p(0.5,0.5))
|
||||
end
|
||||
|
||||
function TestAnchorPoint.create()
|
||||
local layer = TestAnchorPoint.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
local TestArmatureNesting = class("TestArmatureNesting",ArmatureTestLayer)
|
||||
TestArmatureNesting.__index = TestArmatureNesting
|
||||
TestArmatureNesting.weaponIndex = 0
|
||||
TestArmatureNesting.armature = nil
|
||||
|
||||
function TestArmatureNesting.extend(target)
|
||||
local t = tolua.getpeer(target)
|
||||
if not t then
|
||||
t = {}
|
||||
tolua.setpeer(target, t)
|
||||
end
|
||||
setmetatable(t, TestArmatureNesting)
|
||||
return target
|
||||
end
|
||||
|
||||
function TestArmatureNesting:onEnter()
|
||||
self:setTouchEnabled(true)
|
||||
self.weaponIndex = 0
|
||||
|
||||
self.armature = cc.Armature:create("cyborg")
|
||||
self.armature:getAnimation():playByIndex(1)
|
||||
self.armature:setPosition(VisibleRect:center())
|
||||
self.armature:setScale(1.2)
|
||||
self.armature:getAnimation():setAnimationScale(0.4)
|
||||
self:addChild(self.armature)
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
self.weaponIndex = (self.weaponIndex + 1) % 4
|
||||
self.armature:getBone("armInside"):getChildArmature():getAnimation():playByIndex(self.weaponIndex)
|
||||
self.armature:getBone("armOutside"):getChildArmature():getAnimation():playByIndex(self.weaponIndex)
|
||||
return false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x,y)
|
||||
end
|
||||
end
|
||||
|
||||
self:registerScriptTouchHandler(onTouch)
|
||||
end
|
||||
|
||||
function TestArmatureNesting.create()
|
||||
local layer = TestArmatureNesting.extend(cc.Layer:create())
|
||||
|
||||
if nil ~= layer then
|
||||
layer:createMenu()
|
||||
layer:createToExtensionMenu()
|
||||
layer:onEnter()
|
||||
layer:creatTitleAndSubTitle(armatureSceneIdx)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
local armatureSceneArr =
|
||||
{
|
||||
TestCSWithSkeleton.create,
|
||||
TestCSWithoutSkeleton.create,
|
||||
TestDragonBones20.create,
|
||||
TestPerformance.create,
|
||||
TestChangeZorder.create,
|
||||
TestAnimationEvent.create,
|
||||
TestParticleDisplay.create,
|
||||
TestUseMutiplePicture.create,
|
||||
TestBoundingBox.create,
|
||||
TestAnchorPoint.create,
|
||||
TestArmatureNesting.create,
|
||||
}
|
||||
|
||||
function nextArmatureTest()
|
||||
armatureSceneIdx = armatureSceneIdx + 1
|
||||
armatureSceneIdx = armatureSceneIdx % table.getn(armatureSceneArr)
|
||||
if 0 == armatureSceneIdx then
|
||||
armatureSceneIdx = table.getn(armatureSceneArr)
|
||||
end
|
||||
return armatureSceneArr[armatureSceneIdx]()
|
||||
end
|
||||
|
||||
function backArmatureTest()
|
||||
armatureSceneIdx = armatureSceneIdx - 1
|
||||
if armatureSceneIdx <= 0 then
|
||||
armatureSceneIdx = armatureSceneIdx + table.getn(armatureSceneArr)
|
||||
end
|
||||
|
||||
return armatureSceneArr[armatureSceneIdx]()
|
||||
end
|
||||
|
||||
function restartArmatureTest()
|
||||
return armatureSceneArr[armatureSceneIdx]()
|
||||
end
|
||||
|
||||
local function addFileInfo()
|
||||
|
||||
end
|
||||
|
||||
function runArmatureTest()
|
||||
local newScene = ArmatureTestScene.create()
|
||||
newScene:runThisTest()
|
||||
return newScene
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
require "luaScript/ExtensionTest/CocosBuilderTest"
|
||||
require "luaScript/ExtensionTest/WebProxyTest"
|
||||
require "luaScript/ExtensionTest/ArmatureTest"
|
||||
|
||||
local LINE_SPACE = 40
|
||||
local kItemTagBasic = 1000
|
||||
|
@ -13,7 +14,8 @@ local ExtensionTestEnum =
|
|||
TEST_EDITBOX = 4,
|
||||
TEST_TABLEVIEW = 5,
|
||||
TEST_SCROLLVIEW = 6,
|
||||
TEST_MAX_COUNT = 7,
|
||||
TEST_ARMATURE = 7,
|
||||
TEST_MAX_COUNT = 8,
|
||||
}
|
||||
|
||||
local testsName =
|
||||
|
@ -25,6 +27,7 @@ local testsName =
|
|||
"EditBoxTest",
|
||||
"TableViewTest",
|
||||
"ScrollViewTest",
|
||||
"ArmatureTest",
|
||||
}
|
||||
|
||||
|
||||
|
@ -1190,6 +1193,7 @@ local CreateExtensionsTestTable =
|
|||
runEditBoxTest,
|
||||
runTableViewTest,
|
||||
runScrollViewTest,
|
||||
runArmatureTest,
|
||||
}
|
||||
|
||||
|
||||
|
@ -1240,6 +1244,44 @@ local function ExtensionsMainLayer()
|
|||
|
||||
layer:addChild(menu)
|
||||
|
||||
-- handling touch events
|
||||
local beginPos = {x = 0, y = 0}
|
||||
local function onTouchBegan(x, y)
|
||||
beginPos = {x = x, y = y}
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchMoved(x, y)
|
||||
local nMoveY = y - beginPos.y
|
||||
local curPosx, curPosy = menu:getPosition()
|
||||
local nextPosy = curPosy + nMoveY
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
if nextPosy < 0 then
|
||||
menu:setPosition(0, 0)
|
||||
return
|
||||
end
|
||||
|
||||
if nextPosy > ((ExtensionTestEnum.TEST_MAX_COUNT + 1) * LINE_SPACE - winSize.height) then
|
||||
menu:setPosition(0, ((ExtensionTestEnum.TEST_MAX_COUNT + 1) * LINE_SPACE - winSize.height))
|
||||
return
|
||||
end
|
||||
|
||||
menu:setPosition(curPosx, nextPosy)
|
||||
beginPos = {x = x, y = y}
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x, y)
|
||||
elseif eventType == "moved" then
|
||||
return onTouchMoved(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
layer:setTouchEnabled(true)
|
||||
|
||||
layer:registerScriptTouchHandler(onTouch)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
a9fdccd58c6cf8ce3cb5d00ea294ef9ff216d439
|
||||
2412d119adc08bbb78bebb1bc2e66d0d40b8b146
|
|
@ -1329,6 +1329,102 @@ static void extendTableView(lua_State* L)
|
|||
}
|
||||
}
|
||||
|
||||
static int lua_cocos2dx_extension_Bone_setIgnoreMovementBoneData(lua_State* L)
|
||||
{
|
||||
if (nullptr == L)
|
||||
return 0;
|
||||
|
||||
int argc = 0;
|
||||
armature::Bone* self = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(L,1,"Bone",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
self = static_cast<armature::Bone*>(tolua_tousertype(L,1,0));
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (nullptr == self) {
|
||||
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_extension_Bone_setIgnoreMovementBoneData'\n", NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(L) - 1;
|
||||
|
||||
if (1 == argc)
|
||||
{
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isboolean(L, 2, 0, &tolua_err))
|
||||
goto tolua_lerror;
|
||||
#endif
|
||||
bool ignore = (bool)tolua_toboolean(L, 2, 0);
|
||||
self->setIgnoreMovementBoneData(ignore);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CCLOG("'setIgnoreMovementBoneData' function of Bone has wrong number of arguments: %d, was expecting %d\n", argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'setIgnoreMovementBoneData'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int lua_cocos2dx_extension_Bone_getIgnoreMovementBoneData(lua_State* L)
|
||||
{
|
||||
if (nullptr == L)
|
||||
return 0;
|
||||
|
||||
int argc = 0;
|
||||
armature::Bone* self = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(L,1,"Bone",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
self = static_cast<armature::Bone*>(tolua_tousertype(L,1,0));
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (nullptr == self) {
|
||||
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_extension_Bone_getIgnoreMovementBoneData'\n", NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(L) - 1;
|
||||
|
||||
if (0 == argc)
|
||||
{
|
||||
tolua_pushboolean(L, self->getIgnoreMovementBoneData());
|
||||
return 1;
|
||||
}
|
||||
|
||||
CCLOG("'getIgnoreMovementBoneData' function of Bone has wrong number of arguments: %d, was expecting %d\n", argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'getIgnoreMovementBoneData'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void extendBone(lua_State* L)
|
||||
{
|
||||
lua_pushstring(L, "Bone");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
if (lua_istable(L,-1))
|
||||
{
|
||||
tolua_function(L, "setIgnoreMovementBoneData", lua_cocos2dx_extension_Bone_setIgnoreMovementBoneData);
|
||||
tolua_function(L, "getIgnoreMovementBoneData", lua_cocos2dx_extension_Bone_getIgnoreMovementBoneData);
|
||||
}
|
||||
}
|
||||
|
||||
int register_all_cocos2dx_extension_manual(lua_State* tolua_S)
|
||||
{
|
||||
extendScrollView(tolua_S);
|
||||
|
@ -1337,5 +1433,6 @@ int register_all_cocos2dx_extension_manual(lua_State* tolua_S)
|
|||
extendCCBReader(tolua_S);
|
||||
extendCCBAnimationManager(tolua_S);
|
||||
extendTableView(tolua_S);
|
||||
extendBone(tolua_S);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ headers = %(cocosdir)s/extensions/cocos-ext.h
|
|||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||
classes = CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$
|
||||
classes = CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$ Armature ArmatureAnimation Skin Bone ArmatureDataManager \w+Data$
|
||||
|
||||
# what should we skip? in the format ClassName::[function function]
|
||||
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||
|
@ -45,9 +45,16 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC
|
|||
TableView::[create (g|s)etDataSource$ (g|s)etDelegate],
|
||||
Control::[removeHandleOfControlEvent addHandleOfControlEvent],
|
||||
ControlUtils::[*],
|
||||
ControlSwitchSprite::[*]
|
||||
ControlSwitchSprite::[*],
|
||||
ArmatureDataManager::[CCArmatureDataManager ~CCArmatureDataManager],
|
||||
Armature::[createBone updateBlendType getCPBody setCPBody (s|g)etBlendFunc],
|
||||
Skin::[getSkinData setSkinData],
|
||||
ArmatureAnimation::[updateHandler updateFrameData frameEvent],
|
||||
Bone::[(s|g)etIgnoreMovementBoneData]
|
||||
|
||||
rename_functions = CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager]
|
||||
|
||||
rename_functions = CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager],
|
||||
ArmatureDataManager::[sharedArmatureDataManager=getInstance]
|
||||
|
||||
rename_classes = CCBReader::_Reader,
|
||||
CCBAnimationManager::AnimationManager
|
||||
|
@ -59,11 +66,11 @@ remove_prefix =
|
|||
classes_have_no_parents =
|
||||
|
||||
# base classes which will be skipped when their sub-classes found them.
|
||||
base_classes_to_skip = Object
|
||||
base_classes_to_skip = Object ProcessBase
|
||||
|
||||
# classes that create no constructor
|
||||
# Set is special and we will use a hand-written constructor
|
||||
abstract_classes =
|
||||
abstract_classes = ArmatureDataManager
|
||||
|
||||
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
|
||||
script_control_cpp = no
|
||||
|
|
Loading…
Reference in New Issue