2013-08-16 10:12:46 +08:00
local size = cc.Director : getInstance ( ) : getWinSize ( )
local scheduler = cc.Director : getInstance ( ) : getScheduler ( )
2013-03-26 18:14:14 +08:00
local kTagTileMap = 1
local kTagSpriteManager = 1
local kTagAnimation1 = 1
local kTagBitmapAtlas1 = 1
local kTagBitmapAtlas2 = 2
local kTagBitmapAtlas3 = 3
local kTagSprite1 = 0
local kTagSprite2 = 1
2013-03-28 15:47:37 +08:00
local kTagSprite3 = 2
local kTagSprite4 = 3
local kTagSprite5 = 4
local kTagSprite6 = 5
local kTagSprite7 = 6
local kTagSprite8 = 7
2013-03-26 18:14:14 +08:00
--------------------------------------------------------------------
2013-03-28 15:47:37 +08:00
--
2013-03-26 18:14:14 +08:00
-- LabelAtlasTest
2013-03-28 15:47:37 +08:00
--
2013-03-26 18:14:14 +08:00
--------------------------------------------------------------------
local LabelAtlasTest = { }
2013-03-28 15:47:37 +08:00
LabelAtlasTest.layer = nil
2013-03-26 18:14:14 +08:00
LabelAtlasTest.__index = LabelAtlasTest
local m_time = 0
function LabelAtlasTest . step ( dt )
2013-04-01 17:34:07 +08:00
m_time = m_time + dt
local string = string.format ( " %2.2f Test " , m_time )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
local label1_origin = LabelAtlasTest.layer : getChildByTag ( kTagSprite1 )
2014-01-15 23:31:00 +08:00
local label1 = tolua.cast ( label1_origin , " cc.LabelAtlas " )
2013-04-01 17:34:07 +08:00
label1 : setString ( string ) --
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
local label2_origin = LabelAtlasTest.layer : getChildByTag ( kTagSprite2 )
2014-01-15 23:31:00 +08:00
local label2 = tolua.cast ( label2_origin , " cc.LabelAtlas " )
2013-04-01 17:34:07 +08:00
string = string.format ( " %d " , m_time )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
label2 : setString ( string )
2013-03-28 15:47:37 +08:00
end
2013-03-26 18:14:14 +08:00
2013-03-28 15:47:37 +08:00
function LabelAtlasTest . onNodeEvent ( tag )
2013-04-01 17:34:07 +08:00
if tag == " exit " then
LabelAtlasTest.layer : unscheduleUpdate ( )
end
2013-03-26 18:14:14 +08:00
end
function LabelAtlasTest . create ( )
m_time = 0
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
LabelAtlasTest.layer = layer
2013-03-26 18:14:14 +08:00
2013-08-16 10:12:46 +08:00
local label1 = cc.LabelAtlas : _create ( " 123 Test " , " fonts/tuffy_bold_italic-charmap.plist " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label1 , 0 , kTagSprite1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( 10 , 100 ) )
2013-04-01 17:34:07 +08:00
label1 : setOpacity ( 200 )
2013-03-26 18:14:14 +08:00
2013-08-16 10:12:46 +08:00
local label2 = cc.LabelAtlas : _create ( " 0123456789 " , " fonts/tuffy_bold_italic-charmap.plist " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label2 , 0 , kTagSprite2 )
2013-08-16 10:12:46 +08:00
label2 : setPosition ( cc.p ( 10 , 200 ) )
2013-04-01 17:34:07 +08:00
label2 : setOpacity ( 32 )
2013-03-28 15:47:37 +08:00
2013-04-01 17:34:07 +08:00
layer : scheduleUpdateWithPriorityLua ( LabelAtlasTest.step , 0 )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
Helper.titleLabel : setString ( " LabelAtlas " )
Helper.subtitleLabel : setString ( " Updating label should be fast " )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
layer : registerScriptHandler ( LabelAtlasTest.onNodeEvent )
return layer
2013-03-26 18:14:14 +08:00
end
--------------------------------------------------------------------
2013-03-28 15:47:37 +08:00
--
2013-03-26 18:14:14 +08:00
-- LabelAtlasColorTest
2013-03-28 15:47:37 +08:00
--
2013-03-26 18:14:14 +08:00
--------------------------------------------------------------------
local LabelAtlasColorTest = { }
2013-03-28 15:47:37 +08:00
LabelAtlasColorTest.layer = nil
2013-03-26 18:14:14 +08:00
LabelAtlasColorTest.__index = LabelAtlasColorTest
local m_time = 0
function LabelAtlasColorTest . step ( dt )
2013-04-01 17:34:07 +08:00
m_time = m_time + dt
local string = string.format ( " %2.2f Test " , m_time )
local label1_origin = LabelAtlasColorTest.layer : getChildByTag ( kTagSprite1 )
2014-01-15 23:31:00 +08:00
local label1 = tolua.cast ( label1_origin , " cc.LabelAtlas " )
2013-04-01 17:34:07 +08:00
label1 : setString ( string )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
local label2_origin = LabelAtlasColorTest.layer : getChildByTag ( kTagSprite2 )
2014-01-15 23:31:00 +08:00
local label2 = tolua.cast ( label2_origin , " cc.LabelAtlas " )
2013-04-01 17:34:07 +08:00
string = string.format ( " %d " , m_time )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
label2 : setString ( string )
2013-03-26 18:14:14 +08:00
end
2013-03-28 15:47:37 +08:00
function LabelAtlasColorTest . actionFinishCallback ( )
2013-04-01 17:34:07 +08:00
cclog ( " Action finished " )
2013-03-26 18:14:14 +08:00
end
2013-03-28 15:47:37 +08:00
function LabelAtlasColorTest . onNodeEvent ( tag )
2013-04-01 17:34:07 +08:00
if tag == " exit " then
LabelAtlasColorTest.layer : unscheduleUpdate ( )
end
2013-03-26 18:14:14 +08:00
end
function LabelAtlasColorTest . create ( )
m_time = 0
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
LabelAtlasColorTest.layer = layer
2013-03-26 18:14:14 +08:00
2013-08-16 10:12:46 +08:00
local label1 = cc.LabelAtlas : _create ( " 123 Test " , " fonts/tuffy_bold_italic-charmap.plist " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label1 , 0 , kTagSprite1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( 10 , 100 ) )
2013-04-01 17:34:07 +08:00
label1 : setOpacity ( 200 )
2013-03-26 18:14:14 +08:00
2013-08-16 10:12:46 +08:00
local label2 = cc.LabelAtlas : _create ( " 0123456789 " , " fonts/tuffy_bold_italic-charmap.plist " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label2 , 0 , kTagSprite2 )
2013-08-16 10:12:46 +08:00
label2 : setPosition ( cc.p ( 10 , 200 ) )
label2 : setColor ( cc.c3b ( 255 , 0 , 0 ) )
2013-03-26 18:14:14 +08:00
2013-08-16 10:12:46 +08:00
local fade = cc.FadeOut : create ( 1.0 )
2013-04-01 17:34:07 +08:00
local fade_in = fade : reverse ( )
2013-03-26 18:14:14 +08:00
2013-08-16 10:12:46 +08:00
local cb = cc.CallFunc : create ( LabelAtlasColorTest.actionFinishCallback )
2013-03-26 18:14:14 +08:00
2013-08-16 10:12:46 +08:00
local seq = cc.Sequence : create ( fade , fade_in , cb )
local repeatAction = cc.RepeatForever : create ( seq )
2013-03-28 15:47:37 +08:00
label2 : runAction ( repeatAction )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
layer : registerScriptHandler ( LabelAtlasColorTest.onNodeEvent )
layer : scheduleUpdateWithPriorityLua ( LabelAtlasColorTest.step , 0 )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
Helper.titleLabel : setString ( " LabelAtlas " )
Helper.subtitleLabel : setString ( " Opacity + Color should work at the same time " )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
return layer
2013-03-26 18:14:14 +08:00
end
--------------------------------------------------------------------
2013-03-28 15:47:37 +08:00
--
2013-03-26 18:14:14 +08:00
-- Atlas3
2013-03-28 15:47:37 +08:00
--
2013-03-26 18:14:14 +08:00
-- 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)
2013-03-28 15:47:37 +08:00
--
2013-03-26 18:14:14 +08:00
--------------------------------------------------------------------
local Atlas3 = { }
2013-03-28 15:47:37 +08:00
Atlas3.layer = nil
2013-03-26 18:14:14 +08:00
Atlas3.__index = Atlas3
2013-03-28 15:47:37 +08:00
function Atlas3 . onNodeEvent ( tag )
2013-04-01 17:34:07 +08:00
if tag == " exit " then
Atlas3.layer : unscheduleUpdate ( )
end
2013-03-28 15:47:37 +08:00
end
2013-03-26 18:14:14 +08:00
function Atlas3 . create ( )
cclog ( " Atlas3.create " )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
Atlas3.layer = layer
2013-03-26 18:14:14 +08:00
m_time = 0
2013-08-16 10:12:46 +08:00
local col = cc.LayerColor : create ( cc.c4b ( 128 , 128 , 128 , 255 ) )
2013-03-26 18:14:14 +08:00
layer : addChild ( col , - 10 )
2013-08-16 10:12:46 +08:00
local label1 = cc.LabelBMFont : create ( " Test " , " fonts/bitmapFontTest2.fnt " )
2013-03-28 15:47:37 +08:00
2013-03-26 18:14:14 +08:00
-- testing anchors
2013-08-16 10:12:46 +08:00
label1 : setAnchorPoint ( cc.p ( 0 , 0 ) )
2013-03-26 18:14:14 +08:00
layer : addChild ( label1 , 0 , kTagBitmapAtlas1 )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local fade = cc.FadeOut : create ( 1.0 )
2013-03-26 18:14:14 +08:00
local fade_in = fade : reverse ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local seq = cc.Sequence : create ( fade , fade_in )
local repeatAction = cc.RepeatForever : create ( seq )
2013-03-26 18:14:14 +08:00
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
2013-08-16 10:12:46 +08:00
local label2 = cc.LabelBMFont : create ( " Test " , " fonts/bitmapFontTest2.fnt " )
2013-03-26 18:14:14 +08:00
-- testing anchors
2013-08-16 10:12:46 +08:00
label2 : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
label2 : setColor ( cc.c3b ( 255 , 0 , 0 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( label2 , 0 , kTagBitmapAtlas2 )
2013-03-28 15:47:37 +08:00
2014-01-15 23:31:00 +08:00
label2 : runAction ( tolua.cast ( repeatAction : clone ( ) , " cc.Action " ) )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local label3 = cc.LabelBMFont : create ( " Test " , " fonts/bitmapFontTest2.fnt " )
2013-03-26 18:14:14 +08:00
-- testing anchors
2013-08-16 10:12:46 +08:00
label3 : setAnchorPoint ( cc.p ( 1 , 1 ) )
2013-03-26 18:14:14 +08:00
layer : addChild ( label3 , 0 , kTagBitmapAtlas3 )
2013-03-28 15:47:37 +08:00
2013-03-26 18:14:14 +08:00
label1 : setPosition ( VisibleRect : leftBottom ( ) )
label2 : setPosition ( VisibleRect : center ( ) )
label3 : setPosition ( VisibleRect : rightTop ( ) )
2013-04-01 17:34:07 +08:00
layer : registerScriptHandler ( Atlas3.onNodeEvent )
2013-03-26 18:14:14 +08:00
layer : scheduleUpdateWithPriorityLua ( Atlas3.step , 0 )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Testing alignment. Testing opacity + tint " )
2013-03-26 18:14:14 +08:00
2013-04-01 17:34:07 +08:00
return layer
2013-03-26 18:14:14 +08:00
end
function Atlas3 . step ( dt )
2013-04-01 17:34:07 +08:00
m_time = m_time + dt
local string = string.format ( " %2.2f Test j " , m_time )
2013-03-28 15:47:37 +08:00
2014-01-15 23:31:00 +08:00
local label1 = tolua.cast ( Atlas3.layer : getChildByTag ( kTagBitmapAtlas1 ) , " cc.LabelBMFont " )
2013-04-01 17:34:07 +08:00
label1 : setString ( string )
2013-03-28 15:47:37 +08:00
2014-01-15 23:31:00 +08:00
local label2 = tolua.cast ( Atlas3.layer : getChildByTag ( kTagBitmapAtlas2 ) , " cc.LabelBMFont " )
2013-04-01 17:34:07 +08:00
label2 : setString ( string )
2013-03-28 15:47:37 +08:00
2014-01-15 23:31:00 +08:00
local label3 = tolua.cast ( Atlas3.layer : getChildByTag ( kTagBitmapAtlas3 ) , " cc.LabelBMFont " )
2013-04-01 17:34:07 +08:00
label3 : setString ( string )
2013-03-28 15:47:37 +08:00
end
--------------------------------------------------------------------
--
-- Atlas4
--
-- 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 Atlas4 = { }
Atlas4.layer = nil
Atlas4.__index = Atlas4
Atlas4.stepEntry = nil
function Atlas4 . onNodeEvent ( tag )
2013-04-01 17:34:07 +08:00
if tag == " enter " then
Atlas4.stepEntry = scheduler : scheduleScriptFunc ( Atlas4.step , 0.1 , false )
elseif tag == " exit " then
scheduler : unscheduleScriptEntry ( Atlas4.stepEntry )
end
2013-03-28 15:47:37 +08:00
end
function Atlas4 . create ( )
2013-04-01 17:34:07 +08:00
cclog ( " Atlas4.create " )
2013-03-28 15:47:37 +08:00
m_time = 0
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
Atlas4.layer = layer
2013-03-28 15:47:37 +08:00
-- Upper Label
2013-08-16 10:12:46 +08:00
local label = cc.LabelBMFont : create ( " Bitmap Font Atlas " , " fonts/bitmapFontTest.fnt " )
2013-03-28 15:47:37 +08:00
layer : addChild ( label )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
label : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-03-28 15:47:37 +08:00
local BChar = label : getChildByTag ( 0 )
local FChar = label : getChildByTag ( 7 )
local AChar = label : getChildByTag ( 12 )
2013-08-16 10:12:46 +08:00
local rotate = cc.RotateBy : create ( 2 , 360 )
local rot_4ever = cc.RepeatForever : create ( rotate )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local scale = cc.ScaleBy : create ( 2 , 1.5 )
2013-03-28 15:47:37 +08:00
local scale_back = scale : reverse ( )
2013-08-16 10:12:46 +08:00
local scale_seq = cc.Sequence : create ( scale , scale_back )
local scale_4ever = cc.RepeatForever : create ( scale_seq )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local jump = cc.JumpBy : create ( 0.5 , cc.p ( 0 , 0 ) , 60 , 1 )
local jump_4ever = cc.RepeatForever : create ( jump )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local fade_out = cc.FadeOut : create ( 1 )
local fade_in = cc.FadeIn : create ( 1 )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local seq = cc.Sequence : create ( fade_out , fade_in )
local fade_4ever = cc.RepeatForever : create ( seq )
2013-03-28 15:47:37 +08:00
BChar : runAction ( rot_4ever )
BChar : runAction ( scale_4ever )
FChar : runAction ( jump_4ever )
AChar : runAction ( fade_4ever )
-- Bottom Label
2013-08-16 10:12:46 +08:00
local label2 = cc.LabelBMFont : create ( " 00.0 " , " fonts/bitmapFontTest.fnt " )
2013-03-28 15:47:37 +08:00
layer : addChild ( label2 , 0 , kTagBitmapAtlas2 )
2013-08-16 10:12:46 +08:00
label2 : setPosition ( cc.p ( s.width / 2.0 , 80 ) )
2013-03-28 15:47:37 +08:00
local lastChar = label2 : getChildByTag ( 3 )
2014-01-15 23:31:00 +08:00
lastChar : runAction ( tolua.cast ( rot_4ever : clone ( ) , " cc.Action " ) )
2013-03-28 15:47:37 +08:00
2013-04-01 17:34:07 +08:00
layer : registerScriptHandler ( Atlas4.onNodeEvent )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont " )
Helper.subtitleLabel : setString ( " Using fonts as cc.Sprite objects. Some characters should rotate. " )
2013-04-01 17:34:07 +08:00
return layer
2013-03-28 15:47:37 +08:00
end
function Atlas4 . draw ( )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-08-30 15:06:00 +08:00
cc.DrawPrimitives . drawLine ( cc.p ( 0 , s.height / 2 ) , cc.p ( s.width , s.height / 2 ) )
cc.DrawPrimitives . drawLine ( cc.p ( s.width / 2 , 0 ) , cc.p ( s.width / 2 , s.height ) )
2013-03-28 15:47:37 +08:00
end
function Atlas4 . step ( dt )
m_time = m_time + dt
2013-04-01 17:34:07 +08:00
local string = string.format ( " %04.1f " , m_time )
2013-03-28 15:47:37 +08:00
2014-01-15 23:31:00 +08:00
local label1 = tolua.cast ( Atlas4.layer : getChildByTag ( kTagBitmapAtlas2 ) , " cc.LabelBMFont " )
2013-03-26 18:14:14 +08:00
label1 : setString ( string )
2013-03-28 15:47:37 +08:00
end
--------------------------------------------------------------------
--
-- Atlas5
--
-- 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 Atlas5 = { }
Atlas5.layer = nil
function Atlas5 : create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
Atlas5.layer = layer
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local label = cc.LabelBMFont : create ( " abcdefg " , " fonts/bitmapFontTest4.fnt " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
label : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Testing padding " )
return layer
2013-03-28 15:47:37 +08:00
end
--------------------------------------------------------------------
--
-- Atlas6
--
-- 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 Atlas6 = { }
Atlas6.layer = nil
function Atlas6 : create ( )
cclog ( " Atlas6:create " )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
Atlas6.layer = layer
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
local label = cc.LabelBMFont : create ( " FaFeFiFoFu " , " fonts/bitmapFontTest5.fnt " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label )
2013-08-16 10:12:46 +08:00
label : setPosition ( cc.p ( s.width / 2 , s.height / 2 + 50 ) )
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
label = cc.LabelBMFont : create ( " fafefifofu " , " fonts/bitmapFontTest5.fnt " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label )
2013-08-16 10:12:46 +08:00
label : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
label = cc.LabelBMFont : create ( " aeiou " , " fonts/bitmapFontTest5.fnt " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label )
2013-08-16 10:12:46 +08:00
label : setPosition ( cc.p ( s.width / 2 , s.height / 2 - 50 ) )
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Rendering should be OK. Testing offset " )
return layer
2013-03-28 15:47:37 +08:00
end
--------------------------------------------------------------------
--
-- AtlasBitmapColor
--
-- 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 AtlasBitmapColor = { layer = nil }
function AtlasBitmapColor : create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
AtlasBitmapColor.layer = layer
Helper.initWithLayer ( layer )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local label = cc.LabelBMFont : create ( " Blue " , " fonts/bitmapFontTest5.fnt " )
label : setColor ( cc.c3b ( 0 , 0 , 255 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( label )
2013-08-16 10:12:46 +08:00
label : setPosition ( cc.p ( s.width / 2 , s.height / 4 ) )
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
label = cc.LabelBMFont : create ( " Red " , " fonts/bitmapFontTest5.fnt " )
2013-03-28 15:47:37 +08:00
layer : addChild ( label )
2013-08-16 10:12:46 +08:00
label : setPosition ( cc.p ( s.width / 2 , 2 * s.height / 4 ) )
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
label : setColor ( cc.c3b ( 255 , 0 , 0 ) )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
label = cc.LabelBMFont : create ( " G " , " fonts/bitmapFontTest5.fnt " )
2013-03-28 15:47:37 +08:00
layer : addChild ( label )
2013-08-16 10:12:46 +08:00
label : setPosition ( cc.p ( s.width / 2 , 3 * s.height / 4 ) )
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
label : setColor ( cc.c3b ( 0 , 255 , 0 ) )
2013-03-28 15:47:37 +08:00
label : setString ( " Green " )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Testing color " )
return layer
2013-03-28 15:47:37 +08:00
end
--------------------------------------------------------------------
--
-- AtlasFastBitmap
--
-- 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 AtlasFastBitmap = { layer = nil }
function AtlasFastBitmap : create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
AtlasFastBitmap.layer = layer
2013-03-28 15:47:37 +08:00
2013-04-01 17:34:07 +08:00
math.randomseed ( os.time ( ) )
-- Upper Label
2013-03-28 15:47:37 +08:00
local i = 0
2013-04-01 17:34:07 +08:00
for i = 0 , 100 , 1 do
local str = string.format ( " -%d- " , i )
2013-08-16 10:12:46 +08:00
local label = cc.LabelBMFont : create ( str , " fonts/bitmapFontTest.fnt " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local p = cc.p ( math.random ( ) * s.width , math.random ( ) * s.height )
2013-04-01 17:34:07 +08:00
label : setPosition ( p )
2013-08-16 10:12:46 +08:00
label : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-04-01 17:34:07 +08:00
end
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont " )
Helper.subtitleLabel : setString ( " Creating several cc.LabelBMFont with the same .fnt file should be fast " )
2013-04-01 17:34:07 +08:00
return layer
2013-03-28 15:47:37 +08:00
end
--------------------------------------------------------------------
--
-- BitmapFontMultiLine
--
-- 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 BitmapFontMultiLine = { }
function BitmapFontMultiLine : create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
2013-03-28 15:47:37 +08:00
local s = nil
-- Left
2013-08-16 10:12:46 +08:00
local label1 = cc.LabelBMFont : create ( " Multi line \n Left " , " fonts/bitmapFontTest3.fnt " )
label1 : setAnchorPoint ( cc.p ( 0 , 0 ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( label1 , 0 , kTagBitmapAtlas1 )
s = label1 : getContentSize ( )
cclog ( " content size: %.2fx%.2f " , s.width , s.height )
-- Center
2013-08-16 10:12:46 +08:00
local label2 = cc.LabelBMFont : create ( " Multi line \n Center " , " fonts/bitmapFontTest3.fnt " )
label2 : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( label2 , 0 , kTagBitmapAtlas2 )
s = label2 : getContentSize ( )
cclog ( " content size: %.2fx%.2f " , s.width , s.height )
-- right
2013-08-16 10:12:46 +08:00
local label3 = cc.LabelBMFont : create ( " Multi line \n Right \n Three lines Three " , " fonts/bitmapFontTest3.fnt " )
label3 : setAnchorPoint ( cc.p ( 1 , 1 ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( label3 , 0 , kTagBitmapAtlas3 )
s = label3 : getContentSize ( )
cclog ( " content size: %.2fx%.2f " , s.width , s.height )
label1 : setPosition ( VisibleRect : leftBottom ( ) )
label2 : setPosition ( VisibleRect : center ( ) )
label3 : setPosition ( VisibleRect : rightTop ( ) )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Multiline + anchor point " )
return layer
2013-03-28 15:47:37 +08:00
end
--------------------------------------------------------------------
--
-- LabelsEmpty
--
--------------------------------------------------------------------
local LabelsEmpty = { }
LabelsEmpty.layer = nil
LabelsEmpty.setEmpty = false
LabelsEmpty.updateEntry = nil
function LabelsEmpty . onNodeEvent ( tag )
2013-04-01 17:34:07 +08:00
if tag == " enter " then
LabelsEmpty.updateEntry = scheduler : scheduleScriptFunc ( LabelsEmpty.updateStrings , 1.0 , false )
elseif tag == " exit " then
scheduler : unscheduleScriptEntry ( LabelsEmpty.updateEntry )
end
2013-03-28 15:47:37 +08:00
end
function LabelsEmpty . create ( )
cclog ( " LabelsEmpty.create " )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-28 15:47:37 +08:00
LabelsEmpty.layer = layer
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
-- cc.LabelBMFont
local label1 = cc.LabelBMFont : create ( " " , " fonts/bitmapFontTest3.fnt " )
2013-03-28 15:47:37 +08:00
layer : addChild ( label1 , 0 , kTagBitmapAtlas1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( s.width / 2 , s.height - 100 ) )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
-- cc.LabelTTF
local label2 = cc.LabelTTF : create ( " " , " Arial " , 24 )
2013-03-28 15:47:37 +08:00
layer : addChild ( label2 , 0 , kTagBitmapAtlas2 )
2013-08-16 10:12:46 +08:00
label2 : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
-- cc.LabelAtlas
local label3 = cc.LabelAtlas : _create ( " " , " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , string.byte ( " " ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( label3 , 0 , kTagBitmapAtlas3 )
2013-08-16 10:12:46 +08:00
label3 : setPosition ( cc.p ( s.width / 2 , 0 + 100 ) )
2013-03-28 15:47:37 +08:00
layer : registerScriptHandler ( LabelsEmpty.onNodeEvent )
LabelsEmpty.setEmpty = false
Helper.titleLabel : setString ( " Testing empty labels " )
Helper.subtitleLabel : setString ( " 3 empty labels: LabelAtlas, LabelTTF and LabelBMFont " )
return layer
end
function LabelsEmpty . updateStrings ( dt )
2014-01-15 23:31:00 +08:00
local label1 = tolua.cast ( LabelsEmpty.layer : getChildByTag ( kTagBitmapAtlas1 ) , " cc.LabelBMFont " )
local label2 = tolua.cast ( LabelsEmpty.layer : getChildByTag ( kTagBitmapAtlas2 ) , " cc.LabelTTF " )
local label3 = tolua.cast ( LabelsEmpty.layer : getChildByTag ( kTagBitmapAtlas3 ) , " cc.LabelAtlas " )
2013-03-28 15:47:37 +08:00
if ( LabelsEmpty.setEmpty == false ) then
label1 : setString ( " not empty " )
label2 : setString ( " not empty " )
label3 : setString ( " hi " )
LabelsEmpty.setEmpty = true
else
label1 : setString ( " " )
label2 : setString ( " " )
label3 : setString ( " " )
LabelsEmpty.setEmpty = false
end
end
--------------------------------------------------------------------
--
-- LabelBMFontHD
--
--------------------------------------------------------------------
local LabelBMFontHD = {
2013-04-01 17:34:07 +08:00
2013-03-28 15:47:37 +08:00
}
function LabelBMFontHD . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-28 15:47:37 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
-- cc.LabelBMFont
local label1 = cc.LabelBMFont : create ( " TESTING RETINA DISPLAY " , " fonts/konqa32.fnt " )
2013-03-28 15:47:37 +08:00
layer : addChild ( label1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
2013-03-28 15:47:37 +08:00
Helper.titleLabel : setString ( " Testing Retina Display BMFont " )
Helper.subtitleLabel : setString ( " loading arista16 or arista16-hd " )
return layer
end
--------------------------------------------------------------------
--
-- LabelAtlasHD
--
--------------------------------------------------------------------
local LabelAtlasHD = { }
function LabelAtlasHD . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-28 15:47:37 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
-- cc.LabelBMFont
local label1 = cc.LabelAtlas : _create ( " TESTING RETINA DISPLAY " , " fonts/larabie-16.plist " )
label1 : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( label1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
2013-03-28 15:47:37 +08:00
Helper.titleLabel : setString ( " LabelAtlas with Retina Display " )
Helper.subtitleLabel : setString ( " loading larabie-16 / larabie-16-hd " )
return layer
end
--------------------------------------------------------------------
--
-- LabelGlyphDesigner
--
--------------------------------------------------------------------
local LabelGlyphDesigner = { }
function LabelGlyphDesigner . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-28 15:47:37 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local colorlayer = cc.LayerColor : create ( cc.c4b ( 128 , 128 , 128 , 255 ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( colorlayer , - 10 )
2013-08-16 10:12:46 +08:00
-- cc.LabelBMFont
local label1 = cc.LabelBMFont : create ( " Testing Glyph Designer " , " fonts/futura-48.fnt " )
2013-03-28 15:47:37 +08:00
layer : addChild ( label1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
2013-03-28 15:47:37 +08:00
Helper.titleLabel : setString ( " Testing Glyph Designer " )
Helper.subtitleLabel : setString ( " You should see a font with shawdows and outline " )
return layer
end
--------------------------------------------------------------------
--
-- LabelTTFTest
--
--------------------------------------------------------------------
local LabelTTFTest = {
2013-04-01 17:34:07 +08:00
_layer = nil ,
_plabel = nil ,
2013-08-16 10:12:46 +08:00
_eHorizAlign = cc.TEXT_ALIGNMENT_LEFT ,
_eVertAlign = cc.VERTICAL_TEXT_ALIGNMENT_TOP
2013-03-28 15:47:37 +08:00
}
function LabelTTFTest . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-28 15:47:37 +08:00
Helper.initWithLayer ( layer )
2013-04-01 17:34:07 +08:00
LabelTTFTest._layer = layer
LabelTTFTest._plabel = nil
2013-08-16 10:12:46 +08:00
LabelTTFTest._eHorizAlign = cc.TEXT_ALIGNMENT_LEFT
LabelTTFTest._eVertAlign = cc.VERTICAL_TEXT_ALIGNMENT_TOP
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local blockSize = cc.size ( 200 , 160 )
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
local colorLayer = cc.LayerColor : create ( cc.c4b ( 100 , 100 , 100 , 255 ) , blockSize.width , blockSize.height )
colorLayer : setAnchorPoint ( cc.p ( 0 , 0 ) )
colorLayer : setPosition ( cc.p ( ( s.width - blockSize.width ) / 2 , ( s.height - blockSize.height ) / 2 ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( colorLayer )
2013-08-16 10:12:46 +08:00
cc.MenuItemFont : setFontSize ( 30 )
local item1 = cc.MenuItemFont : create ( " Left " )
2013-03-28 15:47:37 +08:00
item1 : registerScriptTapHandler ( LabelTTFTest.setAlignmentLeft )
2013-08-16 10:12:46 +08:00
local item2 = cc.MenuItemFont : create ( " Center " )
2013-03-28 15:47:37 +08:00
item2 : registerScriptTapHandler ( LabelTTFTest.setAlignmentCenter )
2013-08-16 10:12:46 +08:00
local item3 = cc.MenuItemFont : create ( " Right " )
2013-03-28 15:47:37 +08:00
item3 : registerScriptTapHandler ( LabelTTFTest.setAlignmentRight )
2013-08-16 10:12:46 +08:00
local menu = cc.Menu : create ( )
2013-03-28 15:47:37 +08:00
menu : addChild ( item1 )
menu : addChild ( item2 )
menu : addChild ( item3 )
menu : alignItemsVerticallyWithPadding ( 4 )
2013-08-16 10:12:46 +08:00
menu : setPosition ( cc.p ( 50 , s.height / 2 - 20 ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( menu )
2013-08-16 10:12:46 +08:00
menu = cc.Menu : create ( )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
item1 = cc.MenuItemFont : create ( " Top " )
2013-03-28 15:47:37 +08:00
item1 : registerScriptTapHandler ( LabelTTFTest.setAlignmentTop )
2013-08-16 10:12:46 +08:00
item2 = cc.MenuItemFont : create ( " Middle " )
2013-03-28 15:47:37 +08:00
item2 : registerScriptTapHandler ( LabelTTFTest.setAlignmentMiddle )
2013-08-16 10:12:46 +08:00
item3 = cc.MenuItemFont : create ( " Bottom " )
2013-03-28 15:47:37 +08:00
item3 : registerScriptTapHandler ( LabelTTFTest.setAlignmentBottom )
menu : addChild ( item1 )
menu : addChild ( item2 )
menu : addChild ( item3 )
menu : alignItemsVerticallyWithPadding ( 4 )
2013-08-16 10:12:46 +08:00
menu : setPosition ( cc.p ( s.width - 50 , s.height / 2 - 20 ) )
2013-03-28 15:47:37 +08:00
layer : addChild ( menu )
2013-03-29 15:21:21 +08:00
LabelTTFTest.updateAlignment ( )
2013-03-26 18:14:14 +08:00
2013-03-28 15:47:37 +08:00
layer : registerScriptHandler ( LabelTTFTest.onNodeEvent )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " Testing cc.LabelTTF " )
2013-03-28 15:47:37 +08:00
Helper.subtitleLabel : setString ( " Select the buttons on the sides to change alignment " )
return layer
end
function LabelTTFTest . onNodeEvent ( tag )
2013-04-01 17:34:07 +08:00
if tag == " exit " then
if LabelTTFTest._plabel ~= nil then
LabelTTFTest._plabel : release ( )
end
end
2013-03-28 15:47:37 +08:00
end
function LabelTTFTest . updateAlignment ( )
2013-08-16 10:12:46 +08:00
local blockSize = cc.size ( 200 , 160 )
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-04-01 17:34:07 +08:00
if LabelTTFTest._plabel ~= nil then
2013-08-16 10:12:46 +08:00
LabelTTFTest._plabel : removeFromParent ( true )
2013-03-28 15:47:37 +08:00
LabelTTFTest._plabel : release ( )
2013-03-29 15:21:21 +08:00
end
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
LabelTTFTest._plabel = cc.LabelTTF : create ( LabelTTFTest.getCurrentAlignment ( ) , " Marker Felt " , 32 ,
2013-04-01 17:34:07 +08:00
blockSize , LabelTTFTest._eHorizAlign , LabelTTFTest._eVertAlign )
2013-03-28 15:47:37 +08:00
LabelTTFTest._plabel : retain ( )
2013-08-16 10:12:46 +08:00
LabelTTFTest._plabel : setAnchorPoint ( cc.p ( 0 , 0 ) )
LabelTTFTest._plabel : setPosition ( cc.p ( ( s.width - blockSize.width ) / 2 , ( s.height - blockSize.height ) / 2 ) )
2013-03-28 15:47:37 +08:00
LabelTTFTest._layer : addChild ( LabelTTFTest._plabel )
2013-03-26 18:14:14 +08:00
end
2013-03-28 15:47:37 +08:00
function LabelTTFTest . setAlignmentLeft ( pSender )
2013-08-16 10:12:46 +08:00
LabelTTFTest._eHorizAlign = cc.TEXT_ALIGNMENT_LEFT
2013-03-28 15:47:37 +08:00
LabelTTFTest.updateAlignment ( )
end
function LabelTTFTest . setAlignmentCenter ( pSender )
2013-08-16 10:12:46 +08:00
LabelTTFTest._eHorizAlign = cc.TEXT_ALIGNMENT_CENTER
2013-03-28 15:47:37 +08:00
LabelTTFTest.updateAlignment ( )
end
2013-03-29 15:21:21 +08:00
function LabelTTFTest . setAlignmentRight ( pSender )
2013-08-16 10:12:46 +08:00
LabelTTFTest._eHorizAlign = cc.TEXT_ALIGNMENT_RIGHT
2013-03-29 15:21:21 +08:00
LabelTTFTest.updateAlignment ( )
end
function LabelTTFTest . setAlignmentTop ( pSender )
2013-08-16 10:12:46 +08:00
LabelTTFTest._eVertAlign = cc.VERTICAL_TEXT_ALIGNMENT_TOP
2013-03-29 15:21:21 +08:00
LabelTTFTest.updateAlignment ( )
end
function LabelTTFTest . setAlignmentMiddle ( pSender )
2013-08-16 10:12:46 +08:00
LabelTTFTest._eVertAlign = cc.VERTICAL_TEXT_ALIGNMENT_CENTER
2013-03-29 15:21:21 +08:00
LabelTTFTest.updateAlignment ( )
end
function LabelTTFTest . setAlignmentBottom ( pSender )
2013-08-16 10:12:46 +08:00
LabelTTFTest._eVertAlign = cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM
2013-03-29 15:21:21 +08:00
LabelTTFTest.updateAlignment ( )
end
function LabelTTFTest . getCurrentAlignment ( )
local vertical = nil
local horizontal = nil
2013-08-16 10:12:46 +08:00
if LabelTTFTest._eVertAlign == cc.VERTICAL_TEXT_ALIGNMENT_TOP then
2013-04-01 17:34:07 +08:00
vertical = " Top "
2013-08-16 10:12:46 +08:00
elseif LabelTTFTest._eVertAlign == cc.VERTICAL_TEXT_ALIGNMENT_CENTER then
2013-04-01 17:34:07 +08:00
vertical = " Middle "
2013-08-16 10:12:46 +08:00
elseif LabelTTFTest._eVertAlign == cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM then
2013-04-01 17:34:07 +08:00
vertical = " Bottom "
2013-03-29 15:21:21 +08:00
end
2013-08-16 10:12:46 +08:00
if LabelTTFTest._eHorizAlign == cc.TEXT_ALIGNMENT_LEFT then
2013-04-01 17:34:07 +08:00
horizontal = " Left "
2013-08-16 10:12:46 +08:00
elseif LabelTTFTest._eHorizAlign == cc.TEXT_ALIGNMENT_CENTER then
2013-04-01 17:34:07 +08:00
horizontal = " Center "
2013-08-16 10:12:46 +08:00
elseif LabelTTFTest._eHorizAlign == cc.TEXT_ALIGNMENT_RIGHT then
2013-04-01 17:34:07 +08:00
horizontal = " Right "
2013-03-29 15:21:21 +08:00
end
return string.format ( " Alignment %s %s " , vertical , horizontal )
end
--------------------------------------------------------------------
--
-- Atlas1
--
--------------------------------------------------------------------
--Atlas1:Atlas1()
--{
2013-08-16 10:12:46 +08:00
-- m_textureAtlas = cc.TextureAtlas:create(s_AtlasTest, 3); m_textureAtlas:retain();
2013-03-29 15:21:21 +08:00
--
2013-08-16 10:12:46 +08:00
-- cc.size s = cc.Director:getInstance():getWinSize();
2013-03-29 15:21:21 +08:00
--
-- --
-- -- Notice: u,v tex coordinates are inverted
-- --
2013-07-05 16:49:22 +08:00
-- V3F_C4B_T2F_Quad quads[] =
2013-03-29 15:21:21 +08:00
-- {
-- {
2013-08-16 10:12:46 +08:00
-- {{0,0,0},cc.c4b(0,0,255,255),{0.0f,1.0f},}, -- bottom left
-- {{s.width,0,0},cc.c4b(0,0,255,0),{1.0f,1.0f},}, -- bottom right
-- {{0,s.height,0},cc.c4b(0,0,255,0),{0.0f,0.0f},}, -- top left
2013-03-29 15:21:21 +08:00
-- {{s.width,s.height,0},{0,0,255,255},{1.0f,0.0f},}, -- top right
-- },
-- {
2013-08-16 10:12:46 +08:00
-- {{40,40,0},cc.c4b(255,255,255,255),{0.0f,0.2f},}, -- bottom left
-- {{120,80,0},cc.c4b(255,0,0,255),{0.5f,0.2f},}, -- bottom right
-- {{40,160,0},cc.c4b(255,255,255,255),{0.0f,0.0f},}, -- top left
-- {{160,160,0},cc.c4b(0,255,0,255),{0.5f,0.0f},}, -- top right
2013-03-29 15:21:21 +08:00
-- },
--
-- {
2013-08-16 10:12:46 +08:00
-- {{s.width/2,40,0},cc.c4b(255,0,0,255),{0.0f,1.0f},}, -- bottom left
-- {{s.width,40,0},cc.c4b(0,255,0,255),{1.0f,1.0f},}, -- bottom right
-- {{s.width/2-50,200,0},cc.c4b(0,0,255,255),{0.0f,0.0f},}, -- top left
-- {{s.width,100,0},cc.c4b(255,255,0,255),{1.0f,0.0f},}, -- top right
2013-03-29 15:21:21 +08:00
-- },
--
-- };
--
--
-- for( int i=0;i<3;i++)
-- {
-- m_textureAtlas:updateQuad(&quads[i], i);
-- }
--}
--
--Atlas1:~Atlas1()
--{
-- m_textureAtlas:release();
--}
--
--void Atlas1:draw()
--{
-- -- GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
-- -- GL_TEXTURE_2D
--
-- m_textureAtlas:drawQuads();
--
---- [textureAtlas drawNumberOfQuads:3];
--
--}
--
--std:string Atlas1:title()
--{
2013-08-16 10:12:46 +08:00
-- return "TextureAtlas";
2013-03-29 15:21:21 +08:00
--}
--
--std:string Atlas1:subtitle()
--{
2013-08-16 10:12:46 +08:00
-- return "Manual creation of cc.TextureAtlas";
2013-03-29 15:21:21 +08:00
--}
local LabelTTFMultiline = {
layer = nil
}
function LabelTTFMultiline . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-29 15:21:21 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-29 15:21:21 +08:00
2013-08-16 10:12:46 +08:00
local center = cc.LabelTTF : create ( " word wrap \" testing \" (bla0) bla1 'bla2' [bla3] (bla4) {bla5} {bla6} [bla7] (bla8) [bla9] 'bla0' \" bla1 \" " ,
2013-04-01 17:34:07 +08:00
" Paint Boy " ,
32 ,
2013-08-16 10:12:46 +08:00
cc.size ( s.width / 2 , 200 ) ,
cc.TEXT_ALIGNMENT_CENTER ,
cc.VERTICAL_TEXT_ALIGNMENT_TOP )
2013-03-29 15:21:21 +08:00
2013-08-16 10:12:46 +08:00
center : setPosition ( cc.p ( s.width / 2 , 150 ) )
2013-03-29 15:21:21 +08:00
layer : addChild ( center )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " Testing cc.LabelTTF Word Wrap " )
Helper.subtitleLabel : setString ( " Word wrap using cc.LabelTTF and a custom TTF font " )
2013-03-29 15:21:21 +08:00
return layer
end
local LabelTTFChinese = { }
function LabelTTFChinese . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-29 15:21:21 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
local size = cc.Director : getInstance ( ) : getWinSize ( )
local pLable = cc.LabelTTF : create ( " 中国 " , " Marker Felt " , 30 )
pLable : setPosition ( cc.p ( size.width / 2 , size.height / 2 ) )
2013-03-29 15:21:21 +08:00
layer : addChild ( pLable )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " Testing cc.LabelTTF with Chinese character " )
2013-03-29 15:21:21 +08:00
return layer
end
local LabelBMFontChinese = { }
function LabelBMFontChinese . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-29 15:21:21 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
local size = cc.Director : getInstance ( ) : getWinSize ( )
local pLable = cc.LabelBMFont : create ( " 中国 " , " fonts/bitmapFontChinese.fnt " )
pLable : setPosition ( cc.p ( size.width / 2 , size.height / 2 ) )
2013-03-29 15:21:21 +08:00
layer : addChild ( pLable )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " Testing cc.LabelBMFont with Chinese character " )
2013-03-29 15:21:21 +08:00
return layer
end
-- BitmapFontMultiLineAlignment
local LongSentencesExample = " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
2013-03-29 18:03:10 +08:00
local LineBreaksExample = " Lorem ipsum dolor \n sit amet \n consectetur adipisicing elit \n blah \n blah "
local MixedExample = " ABC \n Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt \n DEF "
2013-03-28 15:47:37 +08:00
2013-03-29 18:03:10 +08:00
local ArrowsMax = 0.95
local ArrowsMin = 0.7
2013-03-28 15:47:37 +08:00
2013-03-29 18:03:10 +08:00
local LeftAlign = 0
local CenterAlign = 1
local RightAlign = 2
2013-03-28 15:47:37 +08:00
2013-03-29 18:03:10 +08:00
local LongSentences = 0
local LineBreaks = 1
local Mixed = 2
2013-03-28 15:47:37 +08:00
2013-03-29 18:03:10 +08:00
local alignmentItemPadding = 50
local menuItemPaddingCenter = 50
2013-03-29 15:21:21 +08:00
2013-03-29 18:03:10 +08:00
local BitmapFontMultiLineAlignment = {
2013-04-01 17:34:07 +08:00
_pLabelShouldRetain = nil ,
_pArrowsBarShouldRetain = nil ,
_pArrowsShouldRetain = nil ,
_pLastSentenceItem = nil ,
_drag = false ,
2013-03-29 15:21:21 +08:00
}
2013-03-29 18:03:10 +08:00
function BitmapFontMultiLineAlignment . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-03-29 18:03:10 +08:00
Helper.initWithLayer ( layer )
2013-03-29 15:21:21 +08:00
2013-03-29 18:03:10 +08:00
layer : setTouchEnabled ( true )
2013-03-29 15:21:21 +08:00
2013-03-29 18:03:10 +08:00
-- ask director the the window size
2013-08-16 10:12:46 +08:00
local size = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-28 15:47:37 +08:00
2013-03-29 18:03:10 +08:00
-- create and initialize a Label
2013-08-16 10:12:46 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain = cc.LabelBMFont : create ( LongSentencesExample , " fonts/markerFelt.fnt " , size.width / 1.5 , cc.TEXT_ALIGNMENT_CENTER )
2013-03-29 18:03:10 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain : retain ( )
2013-08-16 10:12:46 +08:00
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain = cc.Sprite : create ( " Images/arrowsBar.png " )
2013-03-29 18:03:10 +08:00
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain : retain ( )
2013-08-16 10:12:46 +08:00
BitmapFontMultiLineAlignment._pArrowsShouldRetain = cc.Sprite : create ( " Images/arrows.png " )
2013-03-29 18:03:10 +08:00
BitmapFontMultiLineAlignment._pArrowsShouldRetain : retain ( )
2013-08-16 10:12:46 +08:00
cc.MenuItemFont : setFontSize ( 20 )
local longSentences = cc.MenuItemFont : create ( " Long Flowing Sentences " )
2013-03-29 18:03:10 +08:00
longSentences : registerScriptTapHandler ( BitmapFontMultiLineAlignment.stringChanged )
2013-08-16 10:12:46 +08:00
local lineBreaks = cc.MenuItemFont : create ( " Short Sentences With Intentional Line Breaks " )
2013-03-29 18:03:10 +08:00
lineBreaks : registerScriptTapHandler ( BitmapFontMultiLineAlignment.stringChanged )
2013-08-16 10:12:46 +08:00
local mixed = cc.MenuItemFont : create ( " Long Sentences Mixed With Intentional Line Breaks " )
2013-03-29 18:03:10 +08:00
mixed : registerScriptTapHandler ( BitmapFontMultiLineAlignment.stringChanged )
2013-08-16 10:12:46 +08:00
local stringMenu = cc.Menu : create ( )
2013-03-29 18:03:10 +08:00
stringMenu : addChild ( longSentences )
stringMenu : addChild ( lineBreaks )
stringMenu : addChild ( mixed )
stringMenu : alignItemsVertically ( )
2013-08-16 10:12:46 +08:00
longSentences : setColor ( cc.c3b ( 255 , 0 , 0 ) )
2013-03-29 18:03:10 +08:00
BitmapFontMultiLineAlignment._pLastSentenceItem = longSentences
longSentences : setTag ( LongSentences )
lineBreaks : setTag ( LineBreaks )
mixed : setTag ( Mixed )
2013-03-28 15:47:37 +08:00
2013-08-16 10:12:46 +08:00
cc.MenuItemFont : setFontSize ( 30 )
2013-03-29 15:21:21 +08:00
2013-08-16 10:12:46 +08:00
local left = cc.MenuItemFont : create ( " Left " )
2013-03-29 18:03:10 +08:00
left : registerScriptTapHandler ( BitmapFontMultiLineAlignment.alignmentChanged )
2013-08-16 10:12:46 +08:00
local center = cc.MenuItemFont : create ( " Center " )
2013-03-29 18:03:10 +08:00
center : registerScriptTapHandler ( BitmapFontMultiLineAlignment.alignmentChanged )
2013-08-16 10:12:46 +08:00
local right = cc.MenuItemFont : create ( " Right " )
2013-03-29 18:03:10 +08:00
right : registerScriptTapHandler ( BitmapFontMultiLineAlignment.alignmentChanged )
2013-03-29 15:21:21 +08:00
2013-08-16 10:12:46 +08:00
local alignmentMenu = cc.Menu : create ( )
2013-03-29 18:03:10 +08:00
alignmentMenu : addChild ( left )
alignmentMenu : addChild ( center )
alignmentMenu : addChild ( right )
2013-03-28 15:47:37 +08:00
2013-03-29 18:03:10 +08:00
alignmentMenu : alignItemsHorizontallyWithPadding ( alignmentItemPadding )
2013-03-29 15:21:21 +08:00
2013-08-16 10:12:46 +08:00
center : setColor ( cc.c3b ( 255 , 0 , 0 ) )
2013-03-29 18:03:10 +08:00
BitmapFontMultiLineAlignment._pLastAlignmentItem = center
left : setTag ( LeftAlign )
center : setTag ( CenterAlign )
right : setTag ( RightAlign )
2013-03-29 15:21:21 +08:00
2013-03-29 18:03:10 +08:00
-- position the label on the center of the screen
2013-08-16 10:12:46 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain : setPosition ( cc.p ( size.width / 2 , size.height / 2 ) )
2013-03-29 15:21:21 +08:00
2013-03-29 18:03:10 +08:00
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain : setVisible ( false )
local arrowsWidth = ( ArrowsMax - ArrowsMin ) * size.width
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain : setScaleX ( arrowsWidth / BitmapFontMultiLineAlignment._pArrowsBarShouldRetain : getContentSize ( ) . width )
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain : setPosition ( ( ( ArrowsMax + ArrowsMin ) / 2 ) * size.width , BitmapFontMultiLineAlignment._pLabelShouldRetain : getPositionY ( ) )
BitmapFontMultiLineAlignment.snapArrowsToEdge ( )
2013-08-16 10:12:46 +08:00
stringMenu : setPosition ( cc.p ( size.width / 2 , size.height - menuItemPaddingCenter ) )
alignmentMenu : setPosition ( cc.p ( size.width / 2 , menuItemPaddingCenter + 15 ) )
2013-03-29 18:03:10 +08:00
layer : addChild ( BitmapFontMultiLineAlignment._pLabelShouldRetain )
layer : addChild ( BitmapFontMultiLineAlignment._pArrowsBarShouldRetain )
layer : addChild ( BitmapFontMultiLineAlignment._pArrowsShouldRetain )
layer : addChild ( stringMenu )
layer : addChild ( alignmentMenu )
layer : registerScriptHandler ( BitmapFontMultiLineAlignment.onNodeEvent )
layer : registerScriptTouchHandler ( BitmapFontMultiLineAlignment.onTouchEvent )
return layer
end
function BitmapFontMultiLineAlignment . onNodeEvent ( tag )
if tag == " onexit " then
2013-04-01 17:34:07 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain : release ( )
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain : release ( )
BitmapFontMultiLineAlignment._pArrowsShouldRetain : release ( )
2013-03-29 18:03:10 +08:00
end
end
function BitmapFontMultiLineAlignment . stringChanged ( tag , sender )
2014-01-15 23:31:00 +08:00
local item = tolua.cast ( sender , " cc.MenuItemFont " )
2013-08-16 10:12:46 +08:00
item : setColor ( cc.c3b ( 255 , 0 , 0 ) )
BitmapFontMultiLineAlignment._pLastAlignmentItem : setColor ( cc.c3b ( 255 , 255 , 255 ) )
2013-03-29 18:03:10 +08:00
BitmapFontMultiLineAlignment._pLastAlignmentItem = item
if item : getTag ( ) == LongSentences then
BitmapFontMultiLineAlignment._pLabelShouldRetain : setString ( LongSentencesExample )
elseif item : getTag ( ) == LineBreaks then
BitmapFontMultiLineAlignment._pLabelShouldRetain : setString ( LineBreaksExample )
elseif item : getTag ( ) == Mixed then
BitmapFontMultiLineAlignment._pLabelShouldRetain : setString ( MixedExample )
end
BitmapFontMultiLineAlignment.snapArrowsToEdge ( )
end
function BitmapFontMultiLineAlignment . alignmentChanged ( tag , sender )
-- cclog("BitmapFontMultiLineAlignment.alignmentChanged, tag:"..tag)
2014-01-15 23:31:00 +08:00
local item = tolua.cast ( sender , " cc.MenuItemFont " )
2013-08-16 10:12:46 +08:00
item : setColor ( cc.c3b ( 255 , 0 , 0 ) )
BitmapFontMultiLineAlignment._pLastAlignmentItem : setColor ( cc.c3b ( 255 , 255 , 255 ) )
2013-03-29 18:03:10 +08:00
BitmapFontMultiLineAlignment._pLastAlignmentItem = item
if tag == LeftAlign then
2013-04-01 17:34:07 +08:00
cclog ( " LeftAlign " )
2013-08-16 10:12:46 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain : setAlignment ( cc.TEXT_ALIGNMENT_LEFT )
2013-03-29 18:03:10 +08:00
elseif tag == CenterAlign then
2013-08-16 10:12:46 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain : setAlignment ( cc.TEXT_ALIGNMENT_CENTER )
2013-03-29 18:03:10 +08:00
elseif tag == RightAlign then
2013-08-16 10:12:46 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain : setAlignment ( cc.TEXT_ALIGNMENT_RIGHT )
2013-03-29 18:03:10 +08:00
end
BitmapFontMultiLineAlignment.snapArrowsToEdge ( )
end
function BitmapFontMultiLineAlignment . onTouchEvent ( eventType , x , y )
-- cclog("type:"..eventType.."["..x..","..y.."]")
if eventType == " began " then
2013-08-16 10:12:46 +08:00
if cc.rectContainsPoint ( BitmapFontMultiLineAlignment._pArrowsShouldRetain : getBoundingBox ( ) , cc.p ( x , y ) ) then
2013-04-01 17:34:07 +08:00
BitmapFontMultiLineAlignment._drag = true
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain : setVisible ( true )
return true
end
2013-03-29 18:03:10 +08:00
elseif eventType == " ended " then
2013-04-01 17:34:07 +08:00
BitmapFontMultiLineAlignment._drag = false
BitmapFontMultiLineAlignment.snapArrowsToEdge ( )
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain : setVisible ( false )
2013-03-29 18:03:10 +08:00
elseif eventType == " moved " then
2013-04-01 17:34:07 +08:00
if BitmapFontMultiLine._drag == false then
return
end
2013-03-29 18:03:10 +08:00
2013-08-16 10:12:46 +08:00
local winSize = cc.Director : getInstance ( ) : getWinSize ( )
2013-04-01 17:34:07 +08:00
BitmapFontMultiLineAlignment._pArrowsShouldRetain : setPosition (
math.max ( math.min ( x , ArrowsMax * winSize.width ) , ArrowsMin * winSize.width ) ,
BitmapFontMultiLineAlignment._pArrowsShouldRetain : getPositionY ( ) )
2013-03-29 18:03:10 +08:00
2013-04-01 17:34:07 +08:00
local labelWidth = math.abs ( BitmapFontMultiLineAlignment._pArrowsShouldRetain : getPositionX ( ) - BitmapFontMultiLineAlignment._pLabelShouldRetain : getPositionX ( ) ) * 2
2013-03-29 18:03:10 +08:00
2013-04-01 17:34:07 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain : setWidth ( labelWidth )
2013-03-29 18:03:10 +08:00
end
end
function BitmapFontMultiLineAlignment . snapArrowsToEdge ( )
BitmapFontMultiLineAlignment._pArrowsShouldRetain : setPosition (
2013-04-01 17:34:07 +08:00
BitmapFontMultiLineAlignment._pLabelShouldRetain : getPositionX ( ) + BitmapFontMultiLineAlignment._pLabelShouldRetain : getContentSize ( ) . width / 2 , BitmapFontMultiLineAlignment._pLabelShouldRetain : getPositionY ( )
2013-03-29 18:03:10 +08:00
)
end
2013-03-28 15:47:37 +08:00
2013-03-29 19:27:49 +08:00
--/ LabelTTFA8Test
local LabelTTFA8Test = { }
2013-04-01 17:34:07 +08:00
2013-03-29 19:27:49 +08:00
function LabelTTFA8Test . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
2013-03-29 19:27:49 +08:00
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-03-29 19:27:49 +08:00
2013-08-16 10:12:46 +08:00
local colorlayer = cc.LayerColor : create ( cc.c4b ( 128 , 128 , 128 , 255 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( colorlayer , - 10 )
2013-03-29 19:27:49 +08:00
2013-08-16 10:12:46 +08:00
-- cc.LabelBMFont
local label1 = cc.LabelTTF : create ( " Testing A8 Format " , " Marker Felt " , 48 )
2013-04-01 17:34:07 +08:00
layer : addChild ( label1 )
2013-08-16 10:12:46 +08:00
label1 : setColor ( cc.c3b ( 255 , 0 , 0 ) )
label1 : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
2013-03-29 19:27:49 +08:00
2013-08-16 10:12:46 +08:00
local fadeOut = cc.FadeOut : create ( 2 )
local fadeIn = cc.FadeIn : create ( 2 )
2013-03-29 19:27:49 +08:00
2013-08-16 10:12:46 +08:00
local seq = cc.Sequence : create ( fadeOut , fadeIn )
local forever = cc.RepeatForever : create ( seq )
2013-04-01 17:34:07 +08:00
label1 : runAction ( forever )
2013-03-29 19:27:49 +08:00
2013-04-01 17:34:07 +08:00
Helper.titleLabel : setString ( " Testing A8 Format " )
Helper.subtitleLabel : setString ( " RED label, fading In and Out in the center of the screen " )
return layer
2013-03-29 19:27:49 +08:00
end
--/ BMFontOneAtlas
local BMFontOneAtlas = { }
function BMFontOneAtlas . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local label1 = cc.LabelBMFont : create ( " This is Helvetica " , " fonts/helvetica-32.fnt " , cc.LABEL_AUTOMATIC_WIDTH , cc.TEXT_ALIGNMENT_LEFT , cc.p ( 0 , 0 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( label1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( s.width / 2 , s.height / 3 * 2 ) )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local label2 = cc.LabelBMFont : create ( " And this is Geneva " , " fonts/geneva-32.fnt " , cc.LABEL_AUTOMATIC_WIDTH , cc.TEXT_ALIGNMENT_LEFT , cc.p ( 0 , 128 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( label2 )
2013-08-16 10:12:46 +08:00
label2 : setPosition ( cc.p ( s.width / 2 , s.height / 3 * 1 ) )
Helper.titleLabel : setString ( " LabelBMFont with one texture " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Using 2 .fnt definitions that share the same texture atlas. " )
return layer
2013-03-29 19:27:49 +08:00
end
2013-04-01 17:34:07 +08:00
2013-03-29 19:27:49 +08:00
--/ BMFontUnicode
local BMFontUnicode = { }
function BMFontUnicode . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont with Unicode support " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " You should see 3 differnt labels: In Spanish, Chinese and Korean " )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local label1 = cc.LabelBMFont : create ( " Buen día " , " fonts/arial-unicode-26.fnt " , 200 , cc.TEXT_ALIGNMENT_LEFT )
2013-04-01 17:34:07 +08:00
layer : addChild ( label1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( s.width / 2 , s.height / 4 * 3 ) )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local label2 = cc.LabelBMFont : create ( " 美好的一天 " , " fonts/arial-unicode-26.fnt " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label2 )
2013-08-16 10:12:46 +08:00
label2 : setPosition ( cc.p ( s.width / 2 , s.height / 4 * 2 ) )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local label3 = cc.LabelBMFont : create ( " 良い一日を " , " fonts/arial-unicode-26.fnt " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label3 )
2013-08-16 10:12:46 +08:00
label3 : setPosition ( cc.p ( s.width / 2 , s.height / 4 * 1 ) )
2013-04-01 17:34:07 +08:00
return layer
2013-03-29 19:27:49 +08:00
end
--BMFontInit
local BMFontInit = { }
function BMFontInit . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelBMFont init " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Test for support of init method without parameters. " )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
local bmFont = cc.LabelBMFont : create ( )
--cc.LabelBMFont* bmFont = [cc.LabelBMFont create:@"Foo" fntFile:@"arial-unicode-26.fnt"]
2013-04-01 17:34:07 +08:00
bmFont : setFntFile ( " fonts/helvetica-32.fnt " )
bmFont : setString ( " It is working! " )
layer : addChild ( bmFont )
2013-08-16 10:12:46 +08:00
bmFont : setPosition ( cc.p ( s.width / 2 , s.height / 4 * 2 ) )
2013-04-01 17:34:07 +08:00
return layer
2013-03-29 19:27:49 +08:00
end
2013-04-01 17:34:07 +08:00
2013-03-29 19:27:49 +08:00
-- TTFFontInit
2013-04-01 17:34:07 +08:00
2013-03-29 19:27:49 +08:00
local TTFFontInit = { }
function TTFFontInit . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelTTF init " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Test for support of init method without parameters. " )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local font = cc.LabelTTF : create ( )
2013-04-01 17:34:07 +08:00
font : setFontName ( " Marker Felt " )
font : setFontSize ( 48 )
font : setString ( " It is working! " )
layer : addChild ( font )
2013-08-16 10:12:46 +08:00
font : setPosition ( cc.p ( s.width / 2 , s.height / 4 * 2 ) )
2013-04-01 17:34:07 +08:00
return layer
2013-03-29 19:27:49 +08:00
end
2013-04-01 17:34:07 +08:00
2013-03-29 19:27:49 +08:00
-- Issue1343
2013-04-01 17:34:07 +08:00
2013-03-29 19:27:49 +08:00
local Issue1343 = { }
function Issue1343 . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
Helper.titleLabel : setString ( " Issue 1343 " )
Helper.subtitleLabel : setString ( " You should see: ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz.,' " )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local bmFont = cc.LabelBMFont : create ( )
2013-04-01 17:34:07 +08:00
bmFont : setFntFile ( " fonts/font-issue1343.fnt " )
bmFont : setString ( " ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz.,' " )
layer : addChild ( bmFont )
bmFont : setScale ( 0.3 )
2013-08-16 10:12:46 +08:00
bmFont : setPosition ( cc.p ( s.width / 2 , s.height / 4 * 2 ) )
2013-04-01 17:34:07 +08:00
return layer
2013-03-29 19:27:49 +08:00
end
2013-04-01 17:34:07 +08:00
2013-03-29 19:27:49 +08:00
local LabelBMFontBounds = { }
function LabelBMFontBounds . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
Helper.titleLabel : setString ( " Testing LabelBMFont Bounds " )
Helper.subtitleLabel : setString ( " You should see string enclosed by a box " )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local colorlayer = cc.LayerColor : create ( cc.c4b ( 128 , 128 , 128 , 255 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( colorlayer , - 10 )
2013-08-16 10:12:46 +08:00
-- cc.LabelBMFont
local label1 = cc.LabelBMFont : create ( " Testing Glyph Designer " , " fonts/boundsTestFont.fnt " )
2013-04-01 17:34:07 +08:00
layer : addChild ( label1 )
2013-08-16 10:12:46 +08:00
label1 : setPosition ( cc.p ( s.width / 2 , s.height / 2 ) )
2013-04-01 17:34:07 +08:00
return layer
2013-03-29 19:27:49 +08:00
end
2013-04-01 17:34:07 +08:00
2013-03-29 19:27:49 +08:00
function LabelBMFontBounds . draw ( )
2013-08-16 10:12:46 +08:00
-- cc.size labelSize = label1:getContentSize()
-- cc.size origin = cc.Director:getInstance():getWinSize()
2013-04-01 17:34:07 +08:00
-- origin.width = origin.width / 2 - (labelSize.width / 2)
-- origin.height = origin.height / 2 - (labelSize.height / 2)
2013-08-16 10:12:46 +08:00
-- cc.p vertices[4]=
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
-- cc.p(origin.width, origin.height),
-- cc.p(labelSize.width + origin.width, origin.height),
-- cc.p(labelSize.width + origin.width, labelSize.height + origin.height),
-- cc.p(origin.width, labelSize.height + origin.height)
2013-04-01 17:34:07 +08:00
-- end
-- ccDrawPoly(vertices, 4, true)
2013-03-29 19:27:49 +08:00
end
2013-04-01 17:34:07 +08:00
--------------------------------------------------------------------
--
-- LabelTTFAlignment
--
--------------------------------------------------------------------
local LabelTTFAlignment = { }
function LabelTTFAlignment . create ( )
2013-08-16 10:12:46 +08:00
local layer = cc.Layer : create ( )
2013-04-01 17:34:07 +08:00
Helper.initWithLayer ( layer )
2013-08-16 10:12:46 +08:00
Helper.titleLabel : setString ( " LabelTTF alignment " )
2013-04-01 17:34:07 +08:00
Helper.subtitleLabel : setString ( " Tests alignment values " )
2013-08-16 10:12:46 +08:00
local s = cc.Director : getInstance ( ) : getWinSize ( )
2013-04-01 17:34:07 +08:00
2013-08-16 10:12:46 +08:00
local ttf0 = cc.LabelTTF : create ( " Alignment 0 \n new line " , " Helvetica " , 12 ,
cc.size ( 256 , 32 ) , cc.TEXT_ALIGNMENT_LEFT )
ttf0 : setPosition ( cc.p ( s.width / 2 , ( s.height / 6 ) * 2 ) )
ttf0 : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( ttf0 )
2013-08-16 10:12:46 +08:00
local ttf1 = cc.LabelTTF : create ( " Alignment 1 \n new line " , " Helvetica " , 12 ,
cc.size ( 245 , 32 ) , cc.TEXT_ALIGNMENT_CENTER )
ttf1 : setPosition ( cc.p ( s.width / 2 , ( s.height / 6 ) * 3 ) )
ttf1 : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( ttf1 )
2013-08-16 10:12:46 +08:00
local ttf2 = cc.LabelTTF : create ( " Alignment 2 \n new line " , " Helvetica " , 12 ,
cc.size ( 245 , 32 ) , cc.TEXT_ALIGNMENT_RIGHT )
ttf2 : setPosition ( cc.p ( s.width / 2 , ( s.height / 6 ) * 4 ) )
ttf2 : setAnchorPoint ( cc.p ( 0.5 , 0.5 ) )
2013-04-01 17:34:07 +08:00
layer : addChild ( ttf2 )
return layer
end
2013-03-26 18:14:14 +08:00
function LabelTest ( )
2013-04-01 17:34:07 +08:00
cclog ( " LabelTest " )
m_time = 0
2013-08-16 10:12:46 +08:00
local scene = cc.Scene : create ( )
2013-04-01 17:34:07 +08:00
Helper.createFunctionTable = {
LabelAtlasTest.create ,
LabelAtlasColorTest.create ,
Atlas3.create ,
Atlas4.create ,
Atlas5.create ,
Atlas6.create ,
AtlasBitmapColor.create ,
AtlasFastBitmap.create ,
BitmapFontMultiLine.create ,
LabelsEmpty.create ,
LabelBMFontHD.create ,
LabelAtlasHD.create ,
LabelGlyphDesigner.create ,
-- Atlas1,
LabelTTFTest.create ,
LabelTTFMultiline.create ,
LabelTTFChinese.create ,
LabelBMFontChinese.create ,
BitmapFontMultiLineAlignment.create ,
LabelTTFA8Test.create ,
BMFontOneAtlas.create ,
BMFontUnicode.create ,
BMFontInit.create ,
TTFFontInit.create ,
Issue1343.create ,
LabelTTFAlignment.create ,
LabelBMFontBounds.create
}
scene : addChild ( LabelAtlasTest.create ( ) )
scene : addChild ( CreateBackMenuItem ( ) )
return scene
2013-03-26 18:14:14 +08:00
end