1111
1212IntervalLayer::IntervalLayer ()
1313{
14- m_time1 = m_time2 = m_time3 = 0 .0f ;
14+ m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0 .0f ;
1515
1616 CGSize s = CCDirector::getSharedDirector ()->getWinSize ();
1717 // sun
@@ -24,27 +24,35 @@ IntervalLayer::IntervalLayer()
2424 this ->addChild (sun);
2525
2626 // timers
27+ m_label0 = CCBitmapFontAtlas::bitmapFontAtlasWithString (" 0" , " fonts/bitmapFontTest4.fnt" );
2728 m_label1 = CCBitmapFontAtlas::bitmapFontAtlasWithString (" 0" , " fonts/bitmapFontTest4.fnt" );
2829 m_label2 = CCBitmapFontAtlas::bitmapFontAtlasWithString (" 0" , " fonts/bitmapFontTest4.fnt" );
2930 m_label3 = CCBitmapFontAtlas::bitmapFontAtlasWithString (" 0" , " fonts/bitmapFontTest4.fnt" );
30-
31- schedule (schedule_selector (IntervalLayer::step1), 0 .5f );
32- schedule (schedule_selector (IntervalLayer::step2), 1 .0f );
33- schedule (schedule_selector (IntervalLayer::step3), 1 .5f );
34-
35- m_label1->setPosition ( CGPointMake (80 ,s.width /2 ) );
36- m_label2->setPosition ( CGPointMake (240 ,s.width /2 ) );
37- m_label3->setPosition ( CGPointMake (400 ,s.width /2 ) );
38-
31+ m_label4 = CCBitmapFontAtlas::bitmapFontAtlasWithString (" 0" , " fonts/bitmapFontTest4.fnt" );
32+
33+ scheduleUpdate ();
34+ schedule (schedule_selector (IntervalLayer::step1));
35+ schedule (schedule_selector (IntervalLayer::step2), 0 );
36+ schedule (schedule_selector (IntervalLayer::step3), 1 .0f );
37+ schedule (schedule_selector (IntervalLayer::step4), 2 .0f );
38+
39+ m_label0->setPosition (CGPointMake (s.width *1 /6 , s.height /2 ));
40+ m_label1->setPosition (CGPointMake (s.width *2 /6 , s.height /2 ));
41+ m_label2->setPosition (CGPointMake (s.width *3 /6 , s.height /2 ));
42+ m_label3->setPosition (CGPointMake (s.width *4 /6 , s.height /2 ));
43+ m_label4->setPosition (CGPointMake (s.width *5 /6 , s.height /2 ));
44+
45+ addChild (m_label0);
3946 addChild (m_label1);
4047 addChild (m_label2);
4148 addChild (m_label3);
42-
49+ addChild (m_label4);
50+
4351 // Sprite
4452 CCSprite* sprite = CCSprite::spriteWithFile (s_pPathGrossini);
4553 sprite->setPosition ( CGPointMake (40 ,50 ) );
4654
47- CCJumpBy* jump = CCJumpBy::actionWithDuration (3 , CGPointMake (400 ,0 ), 50 , 4 );
55+ CCJumpBy* jump = CCJumpBy::actionWithDuration (3 , CGPointMake (s. width - 80 ,0 ), 50 , 4 );
4856
4957 addChild (sprite);
5058 sprite->runAction ( CCRepeatForever::actionWithAction (
@@ -54,11 +62,19 @@ IntervalLayer::IntervalLayer()
5462 // pause button
5563 CCMenuItem* item1 = CCMenuItemFont::itemFromString (" Pause" , this , menu_selector (IntervalLayer::onPause) );
5664 CCMenu* menu = CCMenu::menuWithItems (item1, NULL );
57- menu->setPosition ( CGPointMake (s.height -50 , 270 ) );
65+ menu->setPosition ( CGPointMake (s.width / 2 , s. height -50 ) );
5866
5967 addChild ( menu );
6068}
6169
70+ void IntervalLayer::update (ccTime dt)
71+ {
72+ m_time0 +=dt;
73+ char time[10 ] = {0 };
74+ sprintf (time, " %2.1f" , m_time0);
75+ m_label0->setString (time);
76+ }
77+
6278void IntervalLayer::onPause (NSObject* pSender)
6379{
6480 if (CCDirector::getSharedDirector ()->isPaused ())
@@ -70,7 +86,7 @@ void IntervalLayer::onPause(NSObject* pSender)
7086
7187void IntervalLayer::step1 (ccTime dt)
7288{
73- m_time1 +=1 ;
89+ m_time1 +=dt ;
7490
7591 char str[10 ] = {0 };
7692 sprintf (str, " %2.1f" , m_time1);
@@ -79,7 +95,7 @@ void IntervalLayer::step1(ccTime dt)
7995
8096void IntervalLayer::step2 (ccTime dt)
8197{
82- m_time2 +=1 ;
98+ m_time2 +=dt ;
8399
84100 char str[10 ] = {0 };
85101 sprintf (str, " %2.1f" , m_time2);
@@ -88,13 +104,22 @@ void IntervalLayer::step2(ccTime dt)
88104
89105void IntervalLayer::step3 (ccTime dt)
90106{
91- m_time3 +=1 ;
107+ m_time3 +=dt ;
92108
93109 char str[10 ] = {0 };
94110 sprintf (str, " %2.1f" , m_time3);
95111 m_label3->setString ( str );
96112}
97113
114+ void IntervalLayer::step4 (ccTime dt)
115+ {
116+ m_time4 +=dt;
117+
118+ char str[10 ] = {0 };
119+ sprintf (str, " %2.1f" , m_time4);
120+ m_label4->setString ( str );
121+ }
122+
98123void IntervalTestScene::runThisTest ()
99124{
100125 CCLayer* pLayer = new IntervalLayer ();
0 commit comments