issue #2433:Update lua manual binding and modify some samples

This commit is contained in:
samuele3hu 2013-08-16 10:12:46 +08:00
parent 871ed24620
commit de3335a4a9
14 changed files with 913 additions and 704 deletions

View File

@ -17,9 +17,9 @@ cclog("font count = "..fontCount)
local vAlignIdx = 1
local verticalAlignment = {
kCCVerticalTextAlignmentTop,
kCCVerticalTextAlignmentCenter,
kCCVerticalTextAlignmentBottom,
cc.VERTICAL_TEXT_ALIGNMENT_TOP,
cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM,
}
local vAlignCount = table.getn(verticalAlignment)
@ -27,9 +27,9 @@ local vAlignCount = table.getn(verticalAlignment)
local function showFont(ret, pFont)
cclog("vAlignIdx="..vAlignIdx)
local s = CCDirector:getInstance():getWinSize()
local s = cc.Director:getInstance():getWinSize()
local blockSize = CCSize(s.width/3, 200)
local blockSize = cc.size(s.width/3, 200)
local fontSize = 26
ret:removeChildByTag(kTagLabel1, true)
@ -37,36 +37,36 @@ local function showFont(ret, pFont)
ret:removeChildByTag(kTagLabel3, true)
ret:removeChildByTag(kTagLabel4, true)
local top = CCLabelTTF:create(pFont, pFont, 24)
local left = CCLabelTTF:create("alignment left", pFont, fontSize,
blockSize, kCCTextAlignmentLeft, verticalAlignment[vAlignIdx])
local center = CCLabelTTF:create("alignment center", pFont, fontSize,
blockSize, kCCTextAlignmentCenter, verticalAlignment[vAlignIdx])
local right = CCLabelTTF:create("alignment right", pFont, fontSize,
blockSize, kCCTextAlignmentRight, verticalAlignment[vAlignIdx])
local top = cc.LabelTTF:create(pFont, pFont, 24)
local left = cc.LabelTTF:create("alignment left", pFont, fontSize,
blockSize, cc.TEXT_ALIGNMENT_LEFT, verticalAlignment[vAlignIdx])
local center = cc.LabelTTF:create("alignment center", pFont, fontSize,
blockSize, cc.TEXT_ALIGNMENT_CENTER, verticalAlignment[vAlignIdx])
local right = cc.LabelTTF:create("alignment right", pFont, fontSize,
blockSize, cc.TEXT_ALIGNMENT_RIGHT, verticalAlignment[vAlignIdx])
local leftColor = CCLayerColor:create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height)
local centerColor = CCLayerColor:create(Color4B(200, 100, 100, 255), blockSize.width, blockSize.height)
local rightColor = CCLayerColor:create(Color4B(100, 100, 200, 255), blockSize.width, blockSize.height)
local leftColor = cc.LayerColor:create(cc.c4b(100, 100, 100, 255), blockSize.width, blockSize.height)
local centerColor = cc.LayerColor:create(cc.c4b(200, 100, 100, 255), blockSize.width, blockSize.height)
local rightColor = cc.LayerColor:create(cc.c4b(100, 100, 200, 255), blockSize.width, blockSize.height)
leftColor:ignoreAnchorPointForPosition(false)
centerColor:ignoreAnchorPointForPosition(false)
rightColor:ignoreAnchorPointForPosition(false)
top:setAnchorPoint(CCPoint(0.5, 1))
left:setAnchorPoint(CCPoint(0,0.5))
leftColor:setAnchorPoint(CCPoint(0,0.5))
center:setAnchorPoint(CCPoint(0,0.5))
centerColor:setAnchorPoint(CCPoint(0,0.5))
right:setAnchorPoint(CCPoint(0,0.5))
rightColor:setAnchorPoint(CCPoint(0,0.5))
top:setAnchorPoint(cc.p(0.5, 1))
left:setAnchorPoint(cc.p(0,0.5))
leftColor:setAnchorPoint(cc.p(0,0.5))
center:setAnchorPoint(cc.p(0,0.5))
centerColor:setAnchorPoint(cc.p(0,0.5))
right:setAnchorPoint(cc.p(0,0.5))
rightColor:setAnchorPoint(cc.p(0,0.5))
top:setPosition(CCPoint(s.width/2,s.height-20))
left:setPosition(CCPoint(0,s.height/2))
top:setPosition(cc.p(s.width/2,s.height-20))
left:setPosition(cc.p(0,s.height/2))
leftColor:setPosition(left:getPosition())
center:setPosition(CCPoint(blockSize.width, s.height/2))
center:setPosition(cc.p(blockSize.width, s.height/2))
centerColor:setPosition(center:getPosition())
right:setPosition(CCPoint(blockSize.width*2, s.height/2))
right:setPosition(cc.p(blockSize.width*2, s.height/2))
rightColor:setPosition(right:getPosition())
ret:addChild(leftColor, -1)
@ -98,7 +98,7 @@ function FontTestMain()
cclog("FontTestMain")
Helper.index = 1
vAlignIdx = 1
local scene = CCScene:create()
local scene = cc.Scene:create()
Helper.createFunctionTable = {
createTestLayer,
createTestLayer,

View File

@ -1,33 +1,33 @@
local scheduler = CCDirector:getInstance():getScheduler()
local scheduler = cc.Director:getInstance():getScheduler()
local SID_STEP1 = 100
local SID_STEP2 = 101
local SID_STEP3 = 102
local IDC_PAUSE = 200
local function IntervalLayer()
local ret = CCLayer:create()
local ret = cc.Layer:create()
local m_time0 = 0
local m_time1 = 0
local m_time2 = 0
local m_time3 = 0
local m_time4 = 0
local s = CCDirector:getInstance():getWinSize()
local s = cc.Director:getInstance():getWinSize()
-- sun
local sun = CCParticleSun:create()
sun:setTexture(CCTextureCache:getInstance():addImage("Images/fire.png"))
sun:setPosition( CCPoint(VisibleRect:rightTop().x-32,VisibleRect:rightTop().y-32) )
local sun = cc.ParticleSun:create()
sun:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
sun:setPosition( cc.p(VisibleRect:rightTop().x-32,VisibleRect:rightTop().y-32) )
sun:setTotalParticles(130)
sun:setLife(0.6)
ret:addChild(sun)
-- timers
m_label0 = CCLabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label1 = CCLabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label2 = CCLabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label3 = CCLabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label4 = CCLabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label0 = cc.LabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label1 = cc.LabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label2 = cc.LabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label3 = cc.LabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
m_label4 = cc.LabelBMFont:create("0", "fonts/bitmapFontTest4.fnt")
local function update(dt)
m_time0 = m_time0 + dt
@ -77,8 +77,8 @@ local function IntervalLayer()
scheduler:unscheduleScriptEntry(schedulerEntry2)
scheduler:unscheduleScriptEntry(schedulerEntry3)
scheduler:unscheduleScriptEntry(schedulerEntry4)
if CCDirector:getInstance():isPaused() then
CCDirector:getInstance():resume()
if cc.Director:getInstance():isPaused() then
cc.Director:getInstance():resume()
end
end
end
@ -86,11 +86,11 @@ local function IntervalLayer()
ret:registerScriptHandler(onNodeEvent)
m_label0:setPosition(CCPoint(s.width*1/6, s.height/2))
m_label1:setPosition(CCPoint(s.width*2/6, s.height/2))
m_label2:setPosition(CCPoint(s.width*3/6, s.height/2))
m_label3:setPosition(CCPoint(s.width*4/6, s.height/2))
m_label4:setPosition(CCPoint(s.width*5/6, s.height/2))
m_label0:setPosition(cc.p(s.width*1/6, s.height/2))
m_label1:setPosition(cc.p(s.width*2/6, s.height/2))
m_label2:setPosition(cc.p(s.width*3/6, s.height/2))
m_label3:setPosition(cc.p(s.width*4/6, s.height/2))
m_label4:setPosition(cc.p(s.width*5/6, s.height/2))
ret:addChild(m_label0)
ret:addChild(m_label1)
@ -99,29 +99,26 @@ local function IntervalLayer()
ret:addChild(m_label4)
-- Sprite
local sprite = CCSprite:create(s_pPathGrossini)
sprite:setPosition( CCPoint(VisibleRect:left().x + 40, VisibleRect:bottom().y + 50) )
local sprite = cc.Sprite:create(s_pPathGrossini)
sprite:setPosition( cc.p(VisibleRect:left().x + 40, VisibleRect:bottom().y + 50) )
local jump = CCJumpBy:create(3, CCPoint(s.width-80,0), 50, 4)
local jump = cc.JumpBy:create(3, cc.p(s.width-80,0), 50, 4)
ret:addChild(sprite)
local arr = CCArray:create()
arr:addObject(jump)
arr:addObject(jump:reverse())
sprite:runAction( CCRepeatForever:create(CCSequence:create(arr)))
sprite:runAction( cc.RepeatForever:create(cc.Sequence:create(jump, jump:reverse())))
-- pause button
local item1 = CCMenuItemFont:create("Pause")
local item1 = cc.MenuItemFont:create("Pause")
local function onPause(tag, pSender)
if CCDirector:getInstance():isPaused() then
CCDirector:getInstance():resume()
if cc.Director:getInstance():isPaused() then
cc.Director:getInstance():resume()
else
CCDirector:getInstance():pause()
cc.Director:getInstance():pause()
end
end
item1:registerScriptTapHandler(onPause)
local menu = CCMenu:createWithItem(item1)
menu:setPosition( CCPoint(s.width/2, s.height-50) )
local menu = cc.Menu:create(item1)
menu:setPosition( cc.p(s.width/2, s.height-50) )
ret:addChild( menu )
@ -131,7 +128,7 @@ end
function IntervalTestMain()
cclog("IntervalTestMain")
local scene = CCScene:create()
local scene = cc.Scene:create()
local layer = IntervalLayer()
scene:addChild(layer, 0)
scene:addChild(CreateBackMenuItem())

View File

@ -1,16 +1,16 @@
local function KeypadMainLayer()
local pLayer = CCLayer:create()
local pLayer = cc.Layer:create()
local s = CCDirector:getInstance():getWinSize()
local label = CCLabelTTF:create("Keypad Test", "Arial", 28)
local s = cc.Director:getInstance():getWinSize()
local label = cc.LabelTTF:create("Keypad Test", "Arial", 28)
pLayer:addChild(label, 0)
label:setPosition( CCPoint(s.width/2, s.height-50) )
label:setPosition( cc.p(s.width/2, s.height-50) )
pLayer:setKeypadEnabled(true)
-- create a label to display the tip string
local pLabelTip = CCLabelTTF:create("Please press any key...", "Arial", 22)
pLabelTip:setPosition(CCPoint(s.width / 2, s.height / 2))
local pLabelTip = cc.LabelTTF:create("Please press any key...", "Arial", 22)
pLabelTip:setPosition(cc.p(s.width / 2, s.height / 2))
pLayer:addChild(pLabelTip, 0)
pLabelTip:retain()
@ -31,7 +31,7 @@ end
function KeypadTestMain()
cclog("KeypadTestMain")
local scene = CCScene:create()
local scene = cc.Scene:create()
scene:addChild(KeypadMainLayer())
scene:addChild(CreateBackMenuItem())
return scene

View File

@ -1,8 +1,8 @@
local scheduler = CCDirector:getInstance():getScheduler()
local scheduler = cc.Director:getInstance():getScheduler()
local kTagLayer = 1
local function createLayerDemoLayer(title, subtitle)
local layer = CCLayer:create()
local layer = cc.Layer:create()
Helper.initWithLayer(layer)
local titleStr = title == nil and "No title" or title
local subTitleStr = subtitle == nil and "" or subtitle
@ -22,7 +22,7 @@ local function createLayerDemoLayer(title, subtitle)
-- local diffX = x - prev.x
-- local diffY = y - prev.y
-- node:setPosition( CCPoint.__add(CCPoint(newX, newY), CCPoint(diffX, diffY)) )
-- node:setPosition( cc.p.__add(cc.p(newX, newY), cc.p(diffX, diffY)) )
-- prev.x = x
-- prev.y = y
-- end
@ -53,9 +53,9 @@ local function setEnableRecursiveCascading(node, enable)
end
local i = 0
local len = children:count()
local len = table.getn(children)
for i = 0, len-1, 1 do
local child = tolua.cast(children:objectAtIndex(i), "CCNode")
local child = tolua.cast(children[i + 1], "Node")
setEnableRecursiveCascading(child, enable)
end
end
@ -63,35 +63,34 @@ end
-- LayerTestCascadingOpacityA
local function LayerTestCascadingOpacityA()
local ret = createLayerDemoLayer("LayerRGBA: cascading opacity")
local s = CCDirector:getInstance():getWinSize()
local layer1 = CCLayerRGBA:create()
local s = cc.Director:getInstance():getWinSize()
local layer1 = cc.LayerRGBA:create()
local sister1 = CCSprite:create("Images/grossinis_sister1.png")
local sister2 = CCSprite:create("Images/grossinis_sister2.png")
local label = CCLabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
local sister1 = cc.Sprite:create("Images/grossinis_sister1.png")
local sister2 = cc.Sprite:create("Images/grossinis_sister2.png")
local label = cc.LabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
layer1:addChild(sister1)
layer1:addChild(sister2)
layer1:addChild(label)
ret:addChild( layer1, 0, kTagLayer)
sister1:setPosition( CCPoint( s.width*1/3, s.height/2))
sister2:setPosition( CCPoint( s.width*2/3, s.height/2))
label:setPosition( CCPoint( s.width/2, s.height/2))
sister1:setPosition( cc.p( s.width*1/3, s.height/2))
sister2:setPosition( cc.p( s.width*2/3, s.height/2))
label:setPosition( cc.p( s.width/2, s.height/2))
local arr = CCArray:create()
arr:addObject(CCFadeTo:create(4, 0))
arr:addObject(CCFadeTo:create(4, 255))
arr:addObject(CCDelayTime:create(1))
layer1:runAction(CCRepeatForever:create(CCSequence:create(arr)))
layer1:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeTo:create(4, 0),
cc.FadeTo:create(4, 255),
cc.DelayTime:create(1)
)))
arr = CCArray:create()
arr:addObject(CCFadeTo:create(2, 0))
arr:addObject(CCFadeTo:create(2, 255))
arr:addObject(CCFadeTo:create(2, 0))
arr:addObject(CCFadeTo:create(2, 255))
arr:addObject(CCDelayTime:create(1))
sister1:runAction(CCRepeatForever:create(CCSequence:create(arr)))
sister1:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeTo:create(2, 0),
cc.FadeTo:create(2, 255),
cc.FadeTo:create(2, 0),
cc.FadeTo:create(2, 255),
cc.DelayTime:create(1)
)))
-- Enable cascading in scene
setEnableRecursiveCascading(ret, true)
@ -102,40 +101,28 @@ end
local function LayerTestCascadingOpacityB()
local ret = createLayerDemoLayer("CCLayerColor: cascading opacity")
local s = CCDirector:getInstance():getWinSize()
local layer1 = CCLayerColor:create(Color4B(192, 0, 0, 255), s.width, s.height/2)
local s = cc.Director:getInstance():getWinSize()
local layer1 = cc.LayerColor:create(cc.c4b(192, 0, 0, 255), s.width, s.height/2)
layer1:setCascadeColorEnabled(false)
layer1:setPosition( CCPoint(0, s.height/2))
layer1:setPosition( cc.p(0, s.height/2))
local sister1 = CCSprite:create("Images/grossinis_sister1.png")
local sister2 = CCSprite:create("Images/grossinis_sister2.png")
local label = CCLabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
local sister1 = cc.Sprite:create("Images/grossinis_sister1.png")
local sister2 = cc.Sprite:create("Images/grossinis_sister2.png")
local label = cc.LabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
layer1:addChild(sister1)
layer1:addChild(sister2)
layer1:addChild(label)
ret:addChild( layer1, 0, kTagLayer)
sister1:setPosition( CCPoint( s.width*1/3, 0))
sister2:setPosition( CCPoint( s.width*2/3, 0))
label:setPosition( CCPoint( s.width/2, 0))
sister1:setPosition( cc.p( s.width*1/3, 0))
sister2:setPosition( cc.p( s.width*2/3, 0))
label:setPosition( cc.p( s.width/2, 0))
local arr = CCArray:create()
arr:addObject(CCFadeTo:create(4, 0))
arr:addObject(CCFadeTo:create(4, 255))
arr:addObject(CCDelayTime:create(1))
layer1:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeTo:create(4, 0),cc.FadeTo:create(4, 255),cc.DelayTime:create(1))))
layer1:runAction(CCRepeatForever:create(CCSequence:create(arr)))
arr = CCArray:create()
arr:addObject(CCFadeTo:create(2, 0))
arr:addObject(CCFadeTo:create(2, 255))
arr:addObject(CCFadeTo:create(2, 0))
arr:addObject(CCFadeTo:create(2, 255))
arr:addObject(CCDelayTime:create(1))
sister1:runAction(CCRepeatForever:create(CCSequence:create(arr)))
sister1:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeTo:create(2, 0),cc.FadeTo:create(2, 255),cc.FadeTo:create(2, 0),cc.FadeTo:create(2, 255),cc.DelayTime:create(1))))
-- Enable cascading in scene
setEnableRecursiveCascading(ret, true)
@ -144,48 +131,33 @@ end
-- LayerTestCascadingOpacityC
local function LayerTestCascadingOpacityC()
local ret = createLayerDemoLayer("CCLayerColor: non-cascading opacity")
local ret = createLayerDemoLayer("LayerColor: non-cascading opacity")
local s = CCDirector:getInstance():getWinSize()
local layer1 = CCLayerColor:create(Color4B(192, 0, 0, 255), s.width, s.height/2)
local s = cc.Director:getInstance():getWinSize()
local layer1 = cc.LayerColor:create(cc.c4b(192, 0, 0, 255), s.width, s.height/2)
layer1:setCascadeColorEnabled(false)
layer1:setCascadeOpacityEnabled(false)
layer1:setPosition( CCPoint(0, s.height/2))
layer1:setPosition( cc.p(0, s.height/2))
local sister1 = CCSprite:create("Images/grossinis_sister1.png")
local sister2 = CCSprite:create("Images/grossinis_sister2.png")
local label = CCLabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
local sister1 = cc.Sprite:create("Images/grossinis_sister1.png")
local sister2 = cc.Sprite:create("Images/grossinis_sister2.png")
local label = cc.LabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
layer1:addChild(sister1)
layer1:addChild(sister2)
layer1:addChild(label)
ret:addChild( layer1, 0, kTagLayer)
sister1:setPosition( CCPoint( s.width*1/3, 0))
sister2:setPosition( CCPoint( s.width*2/3, 0))
label:setPosition( CCPoint( s.width/2, 0))
sister1:setPosition( cc.p( s.width*1/3, 0))
sister2:setPosition( cc.p( s.width*2/3, 0))
label:setPosition( cc.p( s.width/2, 0))
local arr = CCArray:create()
arr:addObject(CCFadeTo:create(4, 0))
arr:addObject(CCFadeTo:create(4, 255))
arr:addObject(CCDelayTime:create(1))
layer1:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeTo:create(4, 0),
cc.FadeTo:create(4, 255),cc.DelayTime:create(1))))
layer1:runAction(
CCRepeatForever:create(
CCSequence:create(arr
)))
arr = CCArray:create()
arr:addObject(CCFadeTo:create(2, 0))
arr:addObject(CCFadeTo:create(2, 255))
arr:addObject(CCFadeTo:create(2, 0))
arr:addObject(CCFadeTo:create(2, 255))
arr:addObject(CCDelayTime:create(1))
sister1:runAction(
CCRepeatForever:create(
CCSequence:create(arr)))
sister1:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeTo:create(2, 0),cc.FadeTo:create(2, 255),
cc.FadeTo:create(2, 0),cc.FadeTo:create(2, 255),cc.DelayTime:create(1))))
return ret
end
@ -195,45 +167,40 @@ end
local function LayerTestCascadingColorA()
local ret = createLayerDemoLayer("LayerRGBA: cascading color")
local s = CCDirector:getInstance():getWinSize()
local layer1 = CCLayerRGBA:create()
local s = cc.Director:getInstance():getWinSize()
local layer1 = cc.LayerRGBA:create()
local sister1 = CCSprite:create("Images/grossinis_sister1.png")
local sister2 = CCSprite:create("Images/grossinis_sister2.png")
local label = CCLabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
local sister1 = cc.Sprite:create("Images/grossinis_sister1.png")
local sister2 = cc.Sprite:create("Images/grossinis_sister2.png")
local label = cc.LabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
layer1:addChild(sister1)
layer1:addChild(sister2)
layer1:addChild(label)
ret:addChild( layer1, 0, kTagLayer)
sister1:setPosition( CCPoint( s.width*1/3, s.height/2))
sister2:setPosition( CCPoint( s.width*2/3, s.height/2))
label:setPosition( CCPoint( s.width/2, s.height/2))
local arr = CCArray:create()
arr:addObject(CCTintTo:create(6, 255, 0, 255))
arr:addObject(CCTintTo:create(6, 255, 255, 255))
arr:addObject(CCDelayTime:create(1))
sister1:setPosition( cc.p( s.width*1/3, s.height/2))
sister2:setPosition( cc.p( s.width*2/3, s.height/2))
label:setPosition( cc.p( s.width/2, s.height/2))
layer1:runAction(
CCRepeatForever:create(
CCSequence:create(arr
cc.RepeatForever:create(
cc.Sequence:create(cc.TintTo:create(6, 255, 0, 255),
cc.TintTo:create(6, 255, 255, 255),
cc.DelayTime:create(1)
)))
arr = CCArray:create()
arr:addObject(CCTintTo:create(2, 255, 255, 0))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCTintTo:create(2, 0, 255, 255))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCTintTo:create(2, 255, 0, 255))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCDelayTime:create(1))
sister1:runAction(
CCRepeatForever:create(
CCSequence:create(
arr)))
cc.RepeatForever:create(
cc.Sequence:create(cc.TintTo:create(2, 255, 255, 0),
cc.TintTo:create(2, 255, 255, 255),
cc.TintTo:create(2, 0, 255, 255),
cc.TintTo:create(2, 255, 255, 255),
cc.TintTo:create(2, 255, 0, 255),
cc.TintTo:create(2, 255, 255, 255),
cc.DelayTime:create(1)
)))
-- Enable cascading in scene
setEnableRecursiveCascading(ret, true)
@ -242,49 +209,43 @@ end
-- LayerTestCascadingColorB
local function LayerTestCascadingColorB()
local ret = createLayerDemoLayer("CCLayerColor: cascading color")
local ret = createLayerDemoLayer("LayerColor: cascading color")
local s = CCDirector:getInstance():getWinSize()
local layer1 = CCLayerColor:create(Color4B(255, 255, 255, 255), s.width, s.height/2)
local s = cc.Director:getInstance():getWinSize()
local layer1 = cc.LayerColor:create(cc.c4b(255, 255, 255, 255), s.width, s.height/2)
layer1:setPosition( CCPoint(0, s.height/2))
layer1:setPosition( cc.p(0, s.height/2))
local sister1 = CCSprite:create("Images/grossinis_sister1.png")
local sister2 = CCSprite:create("Images/grossinis_sister2.png")
local label = CCLabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
local sister1 = cc.Sprite:create("Images/grossinis_sister1.png")
local sister2 = cc.Sprite:create("Images/grossinis_sister2.png")
local label = cc.LabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
layer1:addChild(sister1)
layer1:addChild(sister2)
layer1:addChild(label)
ret:addChild( layer1, 0, kTagLayer)
sister1:setPosition( CCPoint( s.width*1/3, 0))
sister2:setPosition( CCPoint( s.width*2/3, 0))
label:setPosition( CCPoint( s.width/2, 0))
local arr = CCArray:create()
arr:addObject(CCTintTo:create(6, 255, 0, 255))
arr:addObject(CCTintTo:create(6, 255, 255, 255))
arr:addObject(CCDelayTime:create(1))
sister1:setPosition( cc.p( s.width*1/3, 0))
sister2:setPosition( cc.p( s.width*2/3, 0))
label:setPosition( cc.p( s.width/2, 0))
layer1:runAction(
CCRepeatForever:create(
CCSequence:create(
arr)))
arr = CCArray:create()
arr:addObject(CCTintTo:create(2, 255, 255, 0))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCTintTo:create(2, 0, 255, 255))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCTintTo:create(2, 255, 0, 255))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCDelayTime:create(1))
cc.RepeatForever:create(
cc.Sequence:create(cc.TintTo:create(6, 255, 0, 255),
cc.TintTo:create(6, 255, 255, 255),
cc.DelayTime:create(1)
)))
sister1:runAction(
CCRepeatForever:create(
CCSequence:create(
arr)))
cc.RepeatForever:create(
cc.Sequence:create(cc.TintTo:create(2, 255, 255, 0),
cc.TintTo:create(2, 255, 255, 255),
cc.TintTo:create(2, 0, 255, 255),
cc.TintTo:create(2, 255, 255, 255),
cc.TintTo:create(2, 255, 0, 255),
cc.TintTo:create(2, 255, 255, 255),
cc.DelayTime:create(1)
)))
-- Enable cascading in scene
setEnableRecursiveCascading(ret, true)
@ -293,49 +254,43 @@ end
-- LayerTestCascadingColorC
local function LayerTestCascadingColorC()
local ret = createLayerDemoLayer("CCLayerColor: non-cascading color")
local ret = createLayerDemoLayer("LayerColor: non-cascading color")
local s = CCDirector:getInstance():getWinSize()
local layer1 = CCLayerColor:create(Color4B(255, 255, 255, 255), s.width, s.height/2)
local s = cc.Director:getInstance():getWinSize()
local layer1 = cc.LayerColor:create(cc.c4b(255, 255, 255, 255), s.width, s.height/2)
layer1:setCascadeColorEnabled(false)
layer1:setPosition( CCPoint(0, s.height/2))
layer1:setPosition( cc.p(0, s.height/2))
local sister1 = CCSprite:create("Images/grossinis_sister1.png")
local sister2 = CCSprite:create("Images/grossinis_sister2.png")
local label = CCLabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
local sister1 = cc.Sprite:create("Images/grossinis_sister1.png")
local sister2 = cc.Sprite:create("Images/grossinis_sister2.png")
local label = cc.LabelBMFont:create("Test", "fonts/bitmapFontTest.fnt")
layer1:addChild(sister1)
layer1:addChild(sister2)
layer1:addChild(label)
ret:addChild( layer1, 0, kTagLayer)
sister1:setPosition( CCPoint( s.width*1/3, 0))
sister2:setPosition( CCPoint( s.width*2/3, 0))
label:setPosition( CCPoint( s.width/2, 0))
local arr = CCArray:create()
arr:addObject(CCTintTo:create(6, 255, 0, 255))
arr:addObject(CCTintTo:create(6, 255, 255, 255))
arr:addObject(CCDelayTime:create(1))
sister1:setPosition( cc.p( s.width*1/3, 0))
sister2:setPosition( cc.p( s.width*2/3, 0))
label:setPosition( cc.p( s.width/2, 0))
layer1:runAction(
CCRepeatForever:create(
CCSequence:create(
arr)))
arr = CCArray:create()
arr:addObject(CCTintTo:create(2, 255, 255, 0))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCTintTo:create(2, 0, 255, 255))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCTintTo:create(2, 255, 0, 255))
arr:addObject(CCTintTo:create(2, 255, 255, 255))
arr:addObject(CCDelayTime:create(1))
cc.RepeatForever:create(
cc.Sequence:create(cc.TintTo:create(6, 255, 0, 255),
cc.TintTo:create(6, 255, 255, 255),
cc.DelayTime:create(1)
)))
sister1:runAction(
CCRepeatForever:create(
CCSequence:create(
arr)))
cc.RepeatForever:create(
cc.Sequence:create(cc.TintTo:create(2, 255, 255, 0),
cc.TintTo:create(2, 255, 255, 255),
cc.TintTo:create(2, 0, 255, 255),
cc.TintTo:create(2, 255, 255, 255),
cc.TintTo:create(2, 255, 0, 255),
cc.TintTo:create(2, 255, 255, 255),
cc.DelayTime:create(1)
)))
return ret
end
@ -349,19 +304,19 @@ local function LayerTest1()
ret:setTouchEnabled(true)
local s = CCDirector:getInstance():getWinSize()
local layer = CCLayerColor:create( Color4B(0xFF, 0x00, 0x00, 0x80), 200, 200)
local s = cc.Director:getInstance():getWinSize()
local layer = cc.LayerColor:create( cc.c4b(0xFF, 0x00, 0x00, 0x80), 200, 200)
layer:ignoreAnchorPointForPosition(false)
layer:setPosition( CCPoint(s.width/2, s.height/2) )
layer:setPosition( cc.p(s.width/2, s.height/2) )
ret:addChild(layer, 1, kTagLayer)
local function updateSize(x, y)
local s = CCDirector:getInstance():getWinSize()
local s = cc.Director:getInstance():getWinSize()
local newSize = CCSize( math.abs(x - s.width/2)*2, math.abs(y - s.height/2)*2)
local newSize = cc.size( math.abs(x - s.width/2)*2, math.abs(y - s.height/2)*2)
local l = tolua.cast(ret:getChildByTag(kTagLayer), "CCLayerColor")
local l = tolua.cast(ret:getChildByTag(kTagLayer), "LayerColor")
l:setContentSize( newSize )
end
@ -386,31 +341,25 @@ end
local function LayerTest2()
local ret = createLayerDemoLayer("ColorLayer: fade and tint")
local s = CCDirector:getInstance():getWinSize()
local layer1 = CCLayerColor:create( Color4B(255, 255, 0, 80), 100, 300)
layer1:setPosition(CCPoint(s.width/3, s.height/2))
local s = cc.Director:getInstance():getWinSize()
local layer1 = cc.LayerColor:create( cc.c4b(255, 255, 0, 80), 100, 300)
layer1:setPosition(cc.p(s.width/3, s.height/2))
layer1:ignoreAnchorPointForPosition(false)
ret:addChild(layer1, 1)
local layer2 = CCLayerColor:create( Color4B(0, 0, 255, 255), 100, 300)
layer2:setPosition(CCPoint((s.width/3)*2, s.height/2))
local layer2 = cc.LayerColor:create( cc.c4b(0, 0, 255, 255), 100, 300)
layer2:setPosition(cc.p((s.width/3)*2, s.height/2))
layer2:ignoreAnchorPointForPosition(false)
ret:addChild(layer2, 1)
local actionTint = CCTintBy:create(2, -255, -127, 0)
local actionTint = cc.TintBy:create(2, -255, -127, 0)
local actionTintBack = actionTint:reverse()
local arr = CCArray:create()
arr:addObject(actionTint)
arr:addObject(actionTintBack)
local seq1 = CCSequence:create(arr)
local seq1 = cc.Sequence:create(actionTint,actionTintBack)
layer1:runAction(seq1)
local actionFade = CCFadeOut:create(2.0)
local actionFade = cc.FadeOut:create(2.0)
local actionFadeBack = actionFade:reverse()
arr = CCArray:create()
arr:addObject(actionFade)
arr:addObject(actionFadeBack)
local seq2 = CCSequence:create(arr)
local seq2 = cc.Sequence:create(actionFade,actionFadeBack)
layer2:runAction(seq2)
return ret
@ -424,37 +373,37 @@ end
local function LayerTestBlend()
local ret = createLayerDemoLayer("ColorLayer: blend")
local s = CCDirector:getInstance():getWinSize()
local layer1 = CCLayerColor:create( Color4B(255, 255, 255, 80) )
local s = cc.Director:getInstance():getWinSize()
local layer1 = cc.LayerColor:create( cc.c4b(255, 255, 255, 80) )
local sister1 = CCSprite:create(s_pPathSister1)
local sister2 = CCSprite:create(s_pPathSister2)
local sister1 = cc.Sprite:create(s_pPathSister1)
local sister2 = cc.Sprite:create(s_pPathSister2)
ret:addChild(sister1)
ret:addChild(sister2)
ret:addChild(layer1, 100, kTagLayer)
sister1:setPosition( CCPoint( s.width*1/3, s.height/2) )
sister2:setPosition( CCPoint( s.width*2/3, s.height/2) )
sister1:setPosition( cc.p( s.width*1/3, s.height/2) )
sister2:setPosition( cc.p( s.width*2/3, s.height/2) )
local blend = true
local function newBlend(dt)
local layer = tolua.cast(ret:getChildByTag(kTagLayer), "CCLayerColor")
local layer = tolua.cast(ret:getChildByTag(kTagLayer), "LayerColor")
local src = 0
local dst = 0
if layer:getBlendFunc().dst == GL_ZERO then
src = GL_SRC_ALPHA
dst = GL_ONE_MINUS_SRC_ALPHA
if blend then
src = gl.SRC_ALPHA
dst = gl.ONE_MINUS_SRC_ALPHA
else
src = GL_ONE_MINUS_DST_COLOR
dst = GL_ZERO
src = gl.ONE_MINUS_DST_COLOR
dst = gl.ZERO
end
local bf = BlendFunc()
bf.src = src
bf.dst = dst
layer:setBlendFunc( bf )
layer:setBlendFunc(src, dst)
blend = not blend
end
@ -478,42 +427,42 @@ end
--------------------------------------------------------------------
local function LayerGradient()
local ret = createLayerDemoLayer("LayerGradient", "Touch the screen and move your finger")
local layer1 = CCLayerGradient:create(Color4B(255,0,0,255), Color4B(0,255,0,255), CCPoint(0.9, 0.9))
local layer1 = cc.LayerGradient:create(cc.c4b(255,0,0,255), cc.c4b(0,255,0,255), cc.p(0.9, 0.9))
ret:addChild(layer1, 0, kTagLayer)
ret:setTouchEnabled(true)
local label1 = CCLabelTTF:create("Compressed Interpolation: Enabled", "Marker Felt", 26)
local label2 = CCLabelTTF:create("Compressed Interpolation: Disabled", "Marker Felt", 26)
local item1 = CCMenuItemLabel:create(label1)
local item2 = CCMenuItemLabel:create(label2)
local item = CCMenuItemToggle:create(item1)
local label1 = cc.LabelTTF:create("Compressed Interpolation: Enabled", "Marker Felt", 26)
local label2 = cc.LabelTTF:create("Compressed Interpolation: Disabled", "Marker Felt", 26)
local item1 = cc.MenuItemLabel:create(label1)
local item2 = cc.MenuItemLabel:create(label2)
local item = cc.MenuItemToggle:create(item1)
item:addSubItem(item2)
local function toggleItem(sender)
-- cclog("toggleItem")
local gradient = tolua.cast(ret:getChildByTag(kTagLayer), "CCLayerGradient")
local gradient = tolua.cast(ret:getChildByTag(kTagLayer), "LayerGradient")
gradient:setCompressedInterpolation(not gradient:isCompressedInterpolation())
end
item:registerScriptTapHandler(toggleItem)
local menu = CCMenu:createWithItem(item)
local menu = cc.Menu:create(item)
ret:addChild(menu)
local s = CCDirector:getInstance():getWinSize()
menu:setPosition(CCPoint(s.width / 2, 100))
local s = cc.Director:getInstance():getWinSize()
menu:setPosition(cc.p(s.width / 2, 100))
local function onTouchEvent(eventType, x, y)
if eventType == "began" then
return true
elseif eventType == "moved" then
local s = CCDirector:getInstance():getWinSize()
local start = CCPoint(x, y)
local s = cc.Director:getInstance():getWinSize()
local start = cc.p(x, y)
local movingPos = cc.p(s.width/2,s.height/2)
local diff = cc.p(movingPos.x - start.x, movingPos.y - start.y)
diff = cc.pNormalize(diff)
local diff = CCPoint.__sub( CCPoint(s.width/2,s.height/2), start)
diff = diff:normalize()
local gradient = tolua.cast(ret:getChildByTag(1), "CCLayerGradient")
local gradient = tolua.cast(ret:getChildByTag(1), "LayerGradient")
gradient:setVector(diff)
end
end
@ -530,26 +479,23 @@ local kLayerIgnoreAnchorPoint = 1000
local function LayerIgnoreAnchorPointPos()
local ret = createLayerDemoLayer("IgnoreAnchorPoint - Position", "Ignoring Anchor Point for position")
local s = CCDirector:getInstance():getWinSize()
local s = cc.Director:getInstance():getWinSize()
local l = CCLayerColor:create(Color4B(255, 0, 0, 255), 150, 150)
local l = cc.LayerColor:create(cc.c4b(255, 0, 0, 255), 150, 150)
l:setAnchorPoint(CCPoint(0.5, 0.5))
l:setPosition(CCPoint( s.width/2, s.height/2))
l:setAnchorPoint(cc.p(0.5, 0.5))
l:setPosition(cc.p( s.width/2, s.height/2))
local move = CCMoveBy:create(2, CCPoint(100,2))
local back = tolua.cast(move:reverse(), "CCMoveBy")
local arr = CCArray:create()
arr:addObject(move)
arr:addObject(back)
local seq = CCSequence:create(arr)
l:runAction(CCRepeatForever:create(seq))
local move = cc.MoveBy:create(2, cc.p(100,2))
local back = tolua.cast(move:reverse(), "MoveBy")
local seq = cc.Sequence:create(move, back)
l:runAction(cc.RepeatForever:create(seq))
ret:addChild(l, 0, kLayerIgnoreAnchorPoint)
local child = CCSprite:create("Images/grossini.png")
local child = cc.Sprite:create("Images/grossini.png")
l:addChild(child)
local lsize = l:getContentSize()
child:setPosition(CCPoint(lsize.width/2, lsize.height/2))
child:setPosition(cc.p(lsize.width/2, lsize.height/2))
local function onToggle(pObject)
local pLayer = ret:getChildByTag(kLayerIgnoreAnchorPoint)
@ -557,13 +503,13 @@ local function LayerIgnoreAnchorPointPos()
pLayer:ignoreAnchorPointForPosition(not ignore)
end
local item = CCMenuItemFont:create("Toggle ignore anchor point")
local item = cc.MenuItemFont:create("Toggle ignore anchor point")
item:registerScriptTapHandler(onToggle)
local menu = CCMenu:createWithItem(item)
local menu = cc.Menu:create(item)
ret:addChild(menu)
menu:setPosition(CCPoint(s.width/2, s.height/2))
menu:setPosition(cc.p(s.width/2, s.height/2))
return ret
end
@ -572,23 +518,23 @@ end
local function LayerIgnoreAnchorPointRot()
local ret = createLayerDemoLayer("IgnoreAnchorPoint - Rotation", "Ignoring Anchor Point for rotations")
local s = CCDirector:getInstance():getWinSize()
local s = cc.Director:getInstance():getWinSize()
local l = CCLayerColor:create(Color4B(255, 0, 0, 255), 200, 200)
local l = cc.LayerColor:create(cc.c4b(255, 0, 0, 255), 200, 200)
l:setAnchorPoint(CCPoint(0.5, 0.5))
l:setPosition(CCPoint( s.width/2, s.height/2))
l:setAnchorPoint(cc.p(0.5, 0.5))
l:setPosition(cc.p( s.width/2, s.height/2))
ret:addChild(l, 0, kLayerIgnoreAnchorPoint)
local rot = CCRotateBy:create(2, 360)
l:runAction(CCRepeatForever:create(rot))
local rot = cc.RotateBy:create(2, 360)
l:runAction(cc.RepeatForever:create(rot))
local child = CCSprite:create("Images/grossini.png")
local child = cc.Sprite:create("Images/grossini.png")
l:addChild(child)
local lsize = l:getContentSize()
child:setPosition(CCPoint(lsize.width/2, lsize.height/2))
child:setPosition(cc.p(lsize.width/2, lsize.height/2))
local function onToggle(pObject)
local pLayer = ret:getChildByTag(kLayerIgnoreAnchorPoint)
@ -596,42 +542,39 @@ local function LayerIgnoreAnchorPointRot()
pLayer:ignoreAnchorPointForPosition(not ignore)
end
local item = CCMenuItemFont:create("Toogle ignore anchor point")
local item = cc.MenuItemFont:create("Toogle ignore anchor point")
item:registerScriptTapHandler(onToggle)
local menu = CCMenu:createWithItem(item)
local menu = cc.Menu:create(item)
ret:addChild(menu)
menu:setPosition(CCPoint(s.width/2, s.height/2))
menu:setPosition(cc.p(s.width/2, s.height/2))
return ret
end
-- LayerIgnoreAnchorPointScale
local function LayerIgnoreAnchorPointScale()
local ret = createLayerDemoLayer("IgnoreAnchorPoint - Scale", "Ignoring Anchor Point for scale")
local s = CCDirector:getInstance():getWinSize()
local s = cc.Director:getInstance():getWinSize()
local l = CCLayerColor:create(Color4B(255, 0, 0, 255), 200, 200)
local l = cc.LayerColor:create(cc.c4b(255, 0, 0, 255), 200, 200)
l:setAnchorPoint(CCPoint(0.5, 1.0))
l:setPosition(CCPoint( s.width/2, s.height/2))
l:setAnchorPoint(cc.p(0.5, 1.0))
l:setPosition(cc.p( s.width/2, s.height/2))
local scale = CCScaleBy:create(2, 2)
local back = tolua.cast(scale:reverse(), "CCScaleBy")
local arr = CCArray:create()
arr:addObject(scale)
arr:addObject(back)
local seq = CCSequence:create(arr)
local scale = cc.ScaleBy:create(2, 2)
local back = tolua.cast(scale:reverse(), "ScaleBy")
local seq = cc.Sequence:create(scale, back)
l:runAction(CCRepeatForever:create(seq))
l:runAction(cc.RepeatForever:create(seq))
ret:addChild(l, 0, kLayerIgnoreAnchorPoint)
local child = CCSprite:create("Images/grossini.png")
local child = cc.Sprite:create("Images/grossini.png")
l:addChild(child)
local lsize = l:getContentSize()
child:setPosition(CCPoint(lsize.width/2, lsize.height/2))
child:setPosition(cc.p(lsize.width/2, lsize.height/2))
local function onToggle(pObject)
local pLayer = ret:getChildByTag(kLayerIgnoreAnchorPoint)
@ -640,40 +583,37 @@ local function LayerIgnoreAnchorPointScale()
return ret
end
local item = CCMenuItemFont:create("Toogle ignore anchor point")
local item = cc.MenuItemFont:create("Toogle ignore anchor point")
item:registerScriptTapHandler(onToggle)
local menu = CCMenu:createWithItem(item)
local menu = cc.Menu:create(item)
ret:addChild(menu)
menu:setPosition(CCPoint(s.width/2, s.height/2))
menu:setPosition(cc.p(s.width/2, s.height/2))
return ret
end
local function LayerExtendedBlendOpacityTest()
local ret = createLayerDemoLayer("Extended Blend & Opacity", "You should see 3 layers")
local layer1 = CCLayerGradient:create(Color4B(255, 0, 0, 255), Color4B(255, 0, 255, 255))
layer1:setContentSize(CCSize(80, 80))
layer1:setPosition(CCPoint(50,50))
local layer1 = cc.LayerGradient:create(cc.c4b(255, 0, 0, 255), cc.c4b(255, 0, 255, 255))
layer1:setContentSize(cc.size(80, 80))
layer1:setPosition(cc.p(50,50))
ret:addChild(layer1)
local layer2 = CCLayerGradient:create(Color4B(0, 0, 0, 127), Color4B(255, 255, 255, 127))
layer2:setContentSize(CCSize(80, 80))
layer2:setPosition(CCPoint(100,90))
local layer2 = cc.LayerGradient:create(cc.c4b(0, 0, 0, 127), cc.c4b(255, 255, 255, 127))
layer2:setContentSize(cc.size(80, 80))
layer2:setPosition(cc.p(100,90))
ret:addChild(layer2)
local layer3 = CCLayerGradient:create()
layer3:setContentSize(CCSize(80, 80))
layer3:setPosition(CCPoint(150,140))
layer3:setStartColor(Color3B(255, 0, 0))
layer3:setEndColor(Color3B(255, 0, 255))
local layer3 = cc.LayerGradient:create()
layer3:setContentSize(cc.size(80, 80))
layer3:setPosition(cc.p(150,140))
layer3:setStartColor(cc.c3b(255, 0, 0))
layer3:setEndColor(cc.c3b(255, 0, 255))
layer3:setStartOpacity(255)
layer3:setEndOpacity(255)
local blend = BlendFunc()
blend.src = GL_SRC_ALPHA
blend.dst = GL_ONE_MINUS_SRC_ALPHA
layer3:setBlendFunc(blend)
layer3:setBlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
ret:addChild(layer3)
return ret
end
@ -681,8 +621,8 @@ end
function LayerTestMain()
cclog("LayerTestMain")
Helper.index = 1
CCDirector:getInstance():setDepthTest(true)
local scene = CCScene:create()
cc.Director:getInstance():setDepthTest(true)
local scene = cc.Scene:create()
Helper.createFunctionTable = {
LayerTestCascadingOpacityA,

View File

@ -19,6 +19,11 @@ require "luaScript/CurrentLanguageTest/CurrentLanguageTest"
require "luaScript/DrawPrimitivesTest/DrawPrimitivesTest"
require "luaScript/EffectsTest/EffectsTest"
require "luaScript/EffectsAdvancedTest/EffectsAdvancedTest"
require "luaScript/FontTest/FontTest"
require "luaScript/IntervalTest/IntervalTest"
require "luaScript/KeypadTest/KeypadTest"
require "luaScript/LabelTest/LabelTest"
require "luaScript/LayerTest/LayerTest"
--[[
require "luaScript/TransitionsTest/TransitionsTest"
@ -28,23 +33,19 @@ require "luaScript/MotionStreakTest/MotionStreakTest"
require "luaScript/NodeTest/NodeTest"
require "luaScript/TouchesTest/TouchesTest"
require "luaScript/SpriteTest/SpriteTest"
require "luaScript/LayerTest/LayerTest"
require "luaScript/PerformanceTest/PerformanceTest"
require "luaScript/LabelTest/LabelTest"
require "luaScript/ParallaxTest/ParallaxTest"
require "luaScript/TileMapTest/TileMapTest"
require "luaScript/MenuTest/MenuTest"
require "luaScript/IntervalTest/IntervalTest"
require "luaScript/SceneTest/SceneTest"
require "luaScript/Texture2dTest/Texture2dTest"
require "luaScript/RenderTextureTest/RenderTextureTest"
require "luaScript/ZwoptexTest/ZwoptexTest"
require "luaScript/FontTest/FontTest"
require "luaScript/UserDefaultTest/UserDefaultTest"
require "luaScript/ExtensionTest/ExtensionTest"
require "luaScript/AccelerometerTest/AccelerometerTest"
require "luaScript/KeypadTest/KeypadTest"
require "luaScript/OpenGLTest/OpenGLTest"
]]--

View File

@ -1 +1 @@
8115474f6f2838b3226e1075c612086088005bbd
2a962b5abd27e8a47e73534fe2e521e181cc64be

View File

@ -2000,6 +2000,7 @@ int register_all_cocos2dx(lua_State* tolua_S);
#endif // __cocos2dx_h__

View File

@ -1 +1 @@
1df451e47e5e21c6430adcd93e76253dac5dcb14
4b98d069e4cc8f6af4dc2c64c6ec3fa2590bd927

View File

@ -1 +1 @@
9febc607103481a54085d37c4779c1d04bcf457c
a63246415c81d091a2eb88c4ba396b6d3c80c027

View File

@ -262,6 +262,8 @@ int register_all_cocos2dx_extension(lua_State* tolua_S);

View File

@ -1168,6 +1168,13 @@ getRootNode : function () {},
*/
addDocumentOutletNode : function () {},
/**
* @method getSequenceDuration
* @return A value converted from C/C++ "float"
* @param {const char*}
*/
getSequenceDuration : function () {},
/**
* @method addDocumentCallbackNode
* @param {cocos2d::Node*}
@ -1187,6 +1194,13 @@ setCallFunc : function () {},
*/
runAnimationsForSequenceNamed : function () {},
/**
* @method getSequenceId
* @return A value converted from C/C++ "int"
* @param {const char*}
*/
getSequenceId : function () {},
/**
* @method getDocumentCallbackNodes
* @return A value converted from C/C++ "cocos2d::Array*"

View File

@ -290,7 +290,47 @@ tolua_lerror:
#endif
return 0;
}
//tolua_cocos2d_Menu_create
static int tolua_cocos2d_MenuItemToggle_create(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
int argc = 0;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertable(tolua_S,1,"MenuItemToggle",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if(1 == argc)
{
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,2,"MenuItem",0,&tolua_err) )
{
goto tolua_lerror;
}
#endif
MenuItem* item = (MenuItem*) tolua_tousertype(tolua_S,2,0);
MenuItemToggle* tolua_ret = (MenuItemToggle*) MenuItemToggle::create(item);
int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1;
int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"MenuItemToggle");
return 1;
}
CCLOG("wrong number of arguments: %d, was expecting %d\n", argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err);
return 0;
#endif
}
static int tolua_cocos2d_MenuItem_registerScriptTapHandler(lua_State* tolua_S)
{
if (NULL == tolua_S)
@ -494,6 +534,90 @@ tolua_lerror:
#endif
}
int tolua_cocos2d_Layer_registerScriptKeypadHandler(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
int argc = 0;
Layer* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"Layer",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<cocos2d::Layer*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self)
{
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_Layer_registerScriptKeypadHandler'\n", NULL);
return 0;
}
#endif
if (1 == argc)
{
#if COCOS2D_DEBUG >= 1
if (!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) {
goto tolua_lerror;
}
#endif
LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0));
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::kKeypadHandler);
return 0;
}
CCLOG("wrong number of arguments: %d, was expecting %d\n", argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'registerScriptKeypadHandler'.",&tolua_err);
return 0;
#endif
}
int tolua_cocos2d_Layer_unregisterScriptKeypadHandler(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
int argc = 0;
Layer* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"Layer",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<cocos2d::Layer*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self)
{
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_Layer_unregisterScriptKeypadHandler'\n", NULL);
return 0;
}
#endif
if (0 == argc)
{
ScriptHandlerMgr::getInstance()->removeObjectHandler(self, ScriptHandlerMgr::kKeypadHandler);
return 0;
}
CCLOG("wrong number of arguments: %d, was expecting %d\n", argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'unregisterScriptKeypadHandler'.",&tolua_err);
return 0;
#endif
}
int tolua_cocos2d_Layer_registerScriptAccelerateHandler(lua_State* tolua_S)
{
if (NULL == tolua_S)
@ -778,14 +902,20 @@ static int tolua_cocos2d_Node_registerScriptHandler(lua_State* tolua_S)
return 0;
int argc = 0;
Node* node = nullptr;
Node* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"Node",0,&tolua_err)) goto tolua_lerror;
#endif
node = static_cast<cocos2d::Node*>(tolua_tousertype(tolua_S,1,0));
self = static_cast<cocos2d::Node*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_Node_registerScriptHandler'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S) - 1;
@ -797,7 +927,7 @@ static int tolua_cocos2d_Node_registerScriptHandler(lua_State* tolua_S)
#endif
LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0));
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)node, handler, ScriptHandlerMgr::kNodeHandler);
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::kNodeHandler);
return 0;
}
@ -818,20 +948,26 @@ static int tolua_cocos2d_Node_unregisterScriptHandler(lua_State* tolua_S)
return 0;
int argc = 0;
Node* node = nullptr;
Node* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"Node",0,&tolua_err)) goto tolua_lerror;
#endif
node = static_cast<cocos2d::Node*>(tolua_tousertype(tolua_S,1,0));
self = static_cast<cocos2d::Node*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_Node_unregisterScriptHandler'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 0)
{
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)node, ScriptHandlerMgr::kNodeHandler);
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, ScriptHandlerMgr::kNodeHandler);
return 0;
}
@ -845,6 +981,95 @@ tolua_lerror:
#endif
}
static int tolua_Cocos2d_Node_scheduleUpdateWithPriorityLua(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
int argc = 0;
Node* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"Node",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<cocos2d::Node*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(tolua_S,"invalid 'self' in function 'tolua_Cocos2d_Node_scheduleUpdateWithPriorityLua'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 2)
{
#if COCOS2D_DEBUG >= 1
if(!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err))
goto tolua_lerror;
#endif
LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0));
int priority = 0;
if (luaval_to_int32(tolua_S, 3, &priority))
{
self->scheduleUpdateWithPriorityLua(handler,priority);
}
return 0;
}
CCLOG("wrong number of arguments: %d, was expecting %d\n", argc, 2);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'scheduleUpdateWithPriorityLua'.",&tolua_err);
return 0;
#endif
}
static int tolua_cocos2d_Node_unscheduleUpdate(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
int argc = 0;
Node* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"Node",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<cocos2d::Node*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_Node_unscheduleUpdate'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S) - 1;
if (0 == argc)
{
self->unscheduleUpdate();
return 0;
}
CCLOG("wrong number of arguments: %d, was expecting %d\n", argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'unscheduleUpdate'.",&tolua_err);
return 0;
#endif
}
static int tolua_cocos2d_Spawn_create(lua_State* tolua_S)
{
if (NULL == tolua_S)
@ -1360,6 +1585,10 @@ static int tolua_cocos2dx_Sprite_setBlendFunc(lua_State* tolua_S)
return tolua_cocos2dx_setBlendFunc<Sprite>(tolua_S,"Sprite");
}
static int tolua_cocos2dx_LayerColor_setBlendFunc(lua_State* tolua_S)
{
return tolua_cocos2dx_setBlendFunc<LayerColor>(tolua_S,"LayerColor");
}
int register_all_cocos2dx_manual(lua_State* tolua_S)
{
@ -1413,6 +1642,15 @@ int register_all_cocos2dx_manual(lua_State* tolua_S)
lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItemSprite_create);
lua_rawset(tolua_S,-3);
}
lua_pushstring(tolua_S, "MenuItemToggle");
lua_rawget(tolua_S,LUA_REGISTRYINDEX);
if (lua_istable(tolua_S,-1))
{
lua_pushstring(tolua_S,"create");
lua_pushcfunction(tolua_S,tolua_cocos2d_MenuItemToggle_create);
lua_rawset(tolua_S,-3);
}
lua_pushstring(tolua_S, "Menu");
lua_rawget(tolua_S, LUA_REGISTRYINDEX);
@ -1433,6 +1671,12 @@ int register_all_cocos2dx_manual(lua_State* tolua_S)
lua_pushstring(tolua_S,"unregisterScriptHandler");
lua_pushcfunction(tolua_S,tolua_cocos2d_Node_unregisterScriptHandler);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S,"scheduleUpdateWithPriorityLua");
lua_pushcfunction(tolua_S,tolua_Cocos2d_Node_scheduleUpdateWithPriorityLua);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S,"unscheduleUpdate");
lua_pushcfunction(tolua_S,tolua_cocos2d_Node_unscheduleUpdate);
lua_rawset(tolua_S, -3);
}
lua_pushstring(tolua_S,"Layer");
@ -1445,12 +1689,12 @@ int register_all_cocos2dx_manual(lua_State* tolua_S)
lua_pushstring(tolua_S, "unregisterScriptTouchHandler");
lua_pushcfunction(tolua_S,tolua_cocos2d_Layer_unregisterScriptTouchHandler);
lua_rawset(tolua_S, -3);
// lua_pushstring(lua_S, "registerScriptKeypadHandler");
// lua_pushcfunction(lua_S, tolua_Cocos2d_registerScriptKeypadHandler00);
// lua_rawset(lua_S, -3);
// lua_pushstring(lua_S, "unregisterScriptKeypadHandler");
// lua_pushcfunction(lua_S, tolua_Cocos2d_unregisterScriptKeypadHandler00);
// lua_rawset(lua_S, -3);
lua_pushstring(tolua_S, "registerScriptKeypadHandler");
lua_pushcfunction(tolua_S, tolua_cocos2d_Layer_registerScriptKeypadHandler);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S, "unregisterScriptKeypadHandler");
lua_pushcfunction(tolua_S, tolua_cocos2d_Layer_unregisterScriptKeypadHandler);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S, "registerScriptAccelerateHandler");
lua_pushcfunction(tolua_S, tolua_cocos2d_Layer_registerScriptAccelerateHandler);
lua_rawset(tolua_S, -3);
@ -1561,5 +1805,14 @@ int register_all_cocos2dx_manual(lua_State* tolua_S)
lua_rawset(tolua_S,-3);
}
lua_pushstring(tolua_S,"LayerColor");
lua_rawget(tolua_S,LUA_REGISTRYINDEX);
if (lua_istable(tolua_S,-1))
{
lua_pushstring(tolua_S,"setBlendFunc");
lua_pushcfunction(tolua_S,tolua_cocos2dx_LayerColor_setBlendFunc);
lua_rawset(tolua_S,-3);
}
return 0;
}

View File

@ -8,6 +8,19 @@ function cc.p(_x,_y)
return { x = _x, y = _y }
end
function cc.getPLength(pt)
return math.sqrt( pt.x * pt.x + pt.y * pt.y );
end
function cc.pNormalize(pt)
local length = cc.getPointLength(pt)
if 0 == length then
return { x = 1.0,y = 0.0 }
end
return { x = pt.x / length, y = pt.y / length }
end
--Size
function cc.size( _width,_height )
return { width = _width, height = _height }
@ -33,4 +46,15 @@ function cc.c4f( _r,_g,_b,_a )
return { r = _r, g = _g, b = _b, a = _a }
end
function cc.rectContainsPoint( rect, point )
local ret = false
if (point.x >= rect.x) and (point.x <= rect.x + rect.width) and
(point.y >= rect.y) and (point.y <= rect.y + rect.height) then
ret = true
end
return ret;
end