Merge pull request #2265 from dumganhar/master

Adding LabelTest.lua. Three tests in LabelTest works ok.
This commit is contained in:
James Chen 2013-03-26 03:19:28 -07:00
commit dccaedd20d
4 changed files with 318 additions and 4 deletions

View File

@ -0,0 +1,312 @@
local size = CCDirector:sharedDirector():getWinSize()
local scheduler = CCDirector:sharedDirector():getScheduler()
local kTagTileMap = 1
local kTagSpriteManager = 1
local kTagAnimation1 = 1
local kTagBitmapAtlas1 = 1
local kTagBitmapAtlas2 = 2
local kTagBitmapAtlas3 = 3
local kTagSprite1 = 0
local kTagSprite2 = 1
local kTagSprite3 = 2
local kTagSprite4 = 3
local kTagSprite5 = 4
local kTagSprite6 = 5
local kTagSprite7 = 6
local kTagSprite8 = 7
--------------------------------------------------------------------
--
-- LabelAtlasTest
--
--------------------------------------------------------------------
local LabelAtlasTest = {}
LabelAtlasTest.__index = LabelAtlasTest
local m_time = 0
function LabelAtlasTest.step(dt)
if tolua.isnull(Helper.currentLayer) == true then
return
end
m_time = m_time + dt
local string = string.format("%2.2f Test", m_time)
local label1_origin = Helper.currentLayer:getChildByTag(kTagSprite1)
local label1 = tolua.cast(label1_origin, "CCLabelAtlas")
label1:setString(string)
local label2_origin = Helper.currentLayer:getChildByTag(kTagSprite2)
local label2 = tolua.cast(label2_origin, "CCLabelAtlas")
string = string.format("%d", m_time)
label2:setString(string)
end
function LabelAtlasTest.create()
m_time = 0
local layer = CCLayer:create()
Helper.initWithLayer(layer)
local label1 = CCLabelAtlas:create("123 Test", "fonts/tuffy_bold_italic-charmap.plist")
layer:addChild(label1, 0, kTagSprite1)
label1:setPosition( ccp(10,100) )
label1:setOpacity( 200 )
local label2 = CCLabelAtlas:create("0123456789", "fonts/tuffy_bold_italic-charmap.plist")
layer:addChild(label2, 0, kTagSprite2)
label2:setPosition( ccp(10,200) )
label2:setOpacity( 32 )
layer:scheduleUpdateWithPriorityLua(LabelAtlasTest.step, 0)
Helper.titleLabel:setString("LabelAtlas")
Helper.subtitleLabel:setString("Updating label should be fast")
return layer
end
--------------------------------------------------------------------
--
-- LabelAtlasColorTest
--
--------------------------------------------------------------------
local LabelAtlasColorTest = {}
LabelAtlasColorTest.__index = LabelAtlasColorTest
local m_time = 0
function LabelAtlasColorTest.step(dt)
if tolua.isnull(Helper.currentLayer) == true then
return
end
m_time = m_time + dt
local string = string.format("%2.2f Test", m_time)
local label1_origin = Helper.currentLayer:getChildByTag(kTagSprite1)
local label1 = tolua.cast(label1_origin, "CCLabelAtlas")
label1:setString(string)
local label2_origin = Helper.currentLayer:getChildByTag(kTagSprite2)
local label2 = tolua.cast(label2_origin, "CCLabelAtlas")
string = string.format("%d", m_time)
label2:setString(string)
end
function LabelAtlasColorTest.create()
m_time = 0
local layer = CCLayer:create()
Helper.initWithLayer(layer)
local label1 = CCLabelAtlas:create("123 Test", "fonts/tuffy_bold_italic-charmap.plist")
layer:addChild(label1, 0, kTagSprite1)
label1:setPosition( ccp(10,100) )
label1:setOpacity( 200 )
local label2 = CCLabelAtlas:create("0123456789", "fonts/tuffy_bold_italic-charmap.plist")
layer:addChild(label2, 0, kTagSprite2)
label2:setPosition( ccp(10,200) )
label2:setOpacity( 32 )
layer:scheduleUpdateWithPriorityLua(LabelAtlasColorTest.step, 0)
Helper.titleLabel:setString("LabelAtlas")
Helper.subtitleLabel:setString("Updating label should be fast")
return layer
end
--------------------------------------------------------------------
--
-- LabelAtlasColorTest
--
--------------------------------------------------------------------
local LabelAtlasColorTest = {}
LabelAtlasColorTest.__index = LabelAtlasColorTest
local m_time = 0
function LabelAtlasColorTest.step(dt)
if tolua.isnull(Helper.currentLayer) == true then
return
end
m_time = m_time + dt
local string = string.format("%2.2f Test", m_time)
local label1_origin = Helper.currentLayer:getChildByTag(kTagSprite1)
local label1 = tolua.cast(label1_origin, "CCLabelAtlas")
label1:setString(string)
local label2_origin = Helper.currentLayer:getChildByTag(kTagSprite2)
local label2 = tolua.cast(label2_origin, "CCLabelAtlas")
string = string.format("%d", m_time)
label2:setString(string)
end
function LabelAtlasColorTest.actionFinishCallback()
cclog("Action finished")
end
function LabelAtlasColorTest.create()
m_time = 0
local layer = CCLayer:create()
Helper.initWithLayer(layer)
local label1 = CCLabelAtlas:create("123 Test", "fonts/tuffy_bold_italic-charmap.plist")
layer:addChild(label1, 0, kTagSprite1)
label1:setPosition( ccp(10,100) )
label1:setOpacity( 200 )
local label2 = CCLabelAtlas:create("0123456789", "fonts/tuffy_bold_italic-charmap.plist")
layer:addChild(label2, 0, kTagSprite2)
label2:setPosition( ccp(10,200) )
label2:setColor(ccc3(255, 0, 0))
local fade = CCFadeOut:create(1.0)
local fade_in = fade:reverse()
local cb = CCCallFunc:create(LabelAtlasColorTest.actionFinishCallback)
local actionArr = CCArray:create()
actionArr:addObject(fade)
actionArr:addObject(fade_in)
actionArr:addObject(cb)
local seq = CCSequence:create(actionArr)
local repeatAction = CCRepeatForever:create( seq )
label2:runAction( repeatAction )
layer:scheduleUpdateWithPriorityLua(LabelAtlasColorTest.step, 0)
Helper.titleLabel:setString("LabelAtlas")
Helper.subtitleLabel:setString("Opacity + Color should work at the same time")
return layer
end
--------------------------------------------------------------------
--
-- Atlas3
--
-- Use any of these editors to generate BMFonts:
-- http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
-- http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
-- http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
-- http://www.angelcode.com/products/bmfont/ (Free, Windows only)
--
--------------------------------------------------------------------
local Atlas3 = {}
Atlas3.__index = Atlas3
function Atlas3.create()
cclog("Atlas3.create")
local layer = CCLayer:create()
Helper.initWithLayer(layer)
m_time = 0
local col = CCLayerColor:create( ccc4(128,128,128,255) )
layer:addChild(col, -10)
local label1 = CCLabelBMFont:create("Test", "fonts/bitmapFontTest2.fnt")
-- testing anchors
label1:setAnchorPoint( ccp(0,0) )
layer:addChild(label1, 0, kTagBitmapAtlas1)
local fade = CCFadeOut:create(1.0)
local fade_in = fade:reverse()
local actionArr = CCArray:create()
actionArr:addObject(fade)
actionArr:addObject(fade_in)
local seq = CCSequence:create(actionArr)
local repeatAction = CCRepeatForever:create(seq)
label1:runAction(repeatAction)
--VERY IMPORTANT
--color and opacity work OK because bitmapFontAltas2 loads a BMP image (not a PNG image)
--If you want to use both opacity and color, it is recommended to use NON premultiplied images like BMP images
--Of course, you can also tell XCode not to compress PNG images, but I think it doesn't work as expected
local label2 = CCLabelBMFont:create("Test", "fonts/bitmapFontTest2.fnt")
-- testing anchors
label2:setAnchorPoint( ccp(0.5, 0.5) )
label2:setColor(ccc3(255, 0, 0 ))
layer:addChild(label2, 0, kTagBitmapAtlas2)
label2:runAction( tolua.cast(repeatAction:copy():autorelease(), "CCAction") )
local label3 = CCLabelBMFont:create("Test", "fonts/bitmapFontTest2.fnt")
-- testing anchors
label3:setAnchorPoint( ccp(1,1) )
layer:addChild(label3, 0, kTagBitmapAtlas3)
label1:setPosition( VisibleRect:leftBottom() )
label2:setPosition( VisibleRect:center() )
label3:setPosition( VisibleRect:rightTop() )
layer:scheduleUpdateWithPriorityLua(Atlas3.step, 0)
Helper.titleLabel:setString( "CCLabelBMFont" )
Helper.subtitleLabel:setString( "Testing alignment. Testing opacity + tint" )
return layer
end
function Atlas3.step(dt)
m_time = m_time + dt
local string = string.format("%2.2f Test j", m_time)
local label1 = tolua.cast(Helper.currentLayer:getChildByTag(kTagBitmapAtlas1), "CCLabelBMFont")
label1:setString(string)
local label2 = tolua.cast(Helper.currentLayer:getChildByTag(kTagBitmapAtlas2), "CCLabelBMFont")
label2:setString(string)
local label3 = tolua.cast(Helper.currentLayer:getChildByTag(kTagBitmapAtlas3), "CCLabelBMFont")
label3:setString(string)
end
function LabelTest()
cclog("LabelTest")
m_time = 0
local scene = CCScene:create()
Helper.createFunctionTable = {
LabelAtlasTest.create,
LabelAtlasColorTest.create,
Atlas3.create
-- Atlas4,
-- Atlas5,
-- Atlas6,
-- AtlasBitmapColor,
-- AtlasFastBitmap,
-- BitmapFontMultiLine,
-- LabelsEmpty,
-- LabelBMFontHD,
-- LabelAtlasHD,
-- LabelGlyphDesigner,
-- Atlas1,
-- LabelTTFTest,
-- LabelTTFMultiline,
-- LabelTTFChinese,
-- LabelBMFontChinese,
-- BitmapFontMultiLineAlignment,
-- LabelTTFA8Test,
-- BMFontOneAtlas,
-- BMFontUnicode,
-- BMFontInit,
-- TTFFontInit,
-- Issue1343,
-- LabelTTFAlignment,
-- LabelBMFontBounds
}
scene:addChild(LabelAtlasTest.create())
scene:addChild(CreateBackMenuItem())
return scene
end

View File

@ -75,6 +75,8 @@ function Helper.newScene()
end
function Helper.initWithLayer(layer)
Helper.currentLayer = layer
local size = CCDirector:sharedDirector():getWinSize()
Helper.titleLabel = CCLabelTTF:create("", "Arial", 28)
layer:addChild(Helper.titleLabel, 1)

View File

@ -64,7 +64,7 @@ local function CreateTestScene(nIdx)
--#endif
--#endif
elseif nIdx == Test_Table.TEST_LABEL then
scene = LabelTest()
elseif nIdx == Test_Table.TEST_TEXT_INPUT then
elseif nIdx == Test_Table.TEST_SPRITE then

View File

@ -15,7 +15,7 @@ require "luaScript/TouchesTest/TouchesTest"
require "luaScript/SpriteTest/SpriteTest"
require "luaScript/PerformanceTest/PerformanceTest"
require "luaScript/LabelTest/LabelTest"
----------------------------------------------------
-- tests scene
@ -41,7 +41,7 @@ Test_Table =
-- "TEST_TILE_MAP",
-- "TEST_INTERVAL",
-- "TEST_CHIPMUNKACCELTOUCH",
-- "TEST_LABEL",
"TEST_LABEL",
-- "TEST_TEXT_INPUT",
"TEST_SPRITE",
-- "TEST_SCHEDULER",
@ -91,7 +91,7 @@ Test_Name =
-- "TileMapTest",
-- "IntervalTest",
-- "ChipmunkAccelTouchTest",
-- "LabelTest",
"LabelTest",
-- "TextInputTest",
"SpriteTest",
-- "SchdulerTest",