11
11
12
12
IntervalLayer::IntervalLayer ()
13
13
{
14
- m_time1 = m_time2 = m_time3 = 0 .0f ;
14
+ m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0 .0f ;
15
15
16
16
CGSize s = CCDirector::getSharedDirector ()->getWinSize ();
17
17
// sun
@@ -24,27 +24,35 @@ IntervalLayer::IntervalLayer()
24
24
this ->addChild (sun);
25
25
26
26
// timers
27
+ m_label0 = CCBitmapFontAtlas::bitmapFontAtlasWithString (" 0" , " fonts/bitmapFontTest4.fnt" );
27
28
m_label1 = CCBitmapFontAtlas::bitmapFontAtlasWithString (" 0" , " fonts/bitmapFontTest4.fnt" );
28
29
m_label2 = CCBitmapFontAtlas::bitmapFontAtlasWithString (" 0" , " fonts/bitmapFontTest4.fnt" );
29
30
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);
39
46
addChild (m_label1);
40
47
addChild (m_label2);
41
48
addChild (m_label3);
42
-
49
+ addChild (m_label4);
50
+
43
51
// Sprite
44
52
CCSprite* sprite = CCSprite::spriteWithFile (s_pPathGrossini);
45
53
sprite->setPosition ( CGPointMake (40 ,50 ) );
46
54
47
- CCJumpBy* jump = CCJumpBy::actionWithDuration (3 , CGPointMake (400 ,0 ), 50 , 4 );
55
+ CCJumpBy* jump = CCJumpBy::actionWithDuration (3 , CGPointMake (s. width - 80 ,0 ), 50 , 4 );
48
56
49
57
addChild (sprite);
50
58
sprite->runAction ( CCRepeatForever::actionWithAction (
@@ -54,11 +62,19 @@ IntervalLayer::IntervalLayer()
54
62
// pause button
55
63
CCMenuItem* item1 = CCMenuItemFont::itemFromString (" Pause" , this , menu_selector (IntervalLayer::onPause) );
56
64
CCMenu* menu = CCMenu::menuWithItems (item1, NULL );
57
- menu->setPosition ( CGPointMake (s.height -50 , 270 ) );
65
+ menu->setPosition ( CGPointMake (s.width / 2 , s. height -50 ) );
58
66
59
67
addChild ( menu );
60
68
}
61
69
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
+
62
78
void IntervalLayer::onPause (NSObject* pSender)
63
79
{
64
80
if (CCDirector::getSharedDirector ()->isPaused ())
@@ -70,7 +86,7 @@ void IntervalLayer::onPause(NSObject* pSender)
70
86
71
87
void IntervalLayer::step1 (ccTime dt)
72
88
{
73
- m_time1 +=1 ;
89
+ m_time1 +=dt ;
74
90
75
91
char str[10 ] = {0 };
76
92
sprintf (str, " %2.1f" , m_time1);
@@ -79,7 +95,7 @@ void IntervalLayer::step1(ccTime dt)
79
95
80
96
void IntervalLayer::step2 (ccTime dt)
81
97
{
82
- m_time2 +=1 ;
98
+ m_time2 +=dt ;
83
99
84
100
char str[10 ] = {0 };
85
101
sprintf (str, " %2.1f" , m_time2);
@@ -88,13 +104,22 @@ void IntervalLayer::step2(ccTime dt)
88
104
89
105
void IntervalLayer::step3 (ccTime dt)
90
106
{
91
- m_time3 +=1 ;
107
+ m_time3 +=dt ;
92
108
93
109
char str[10 ] = {0 };
94
110
sprintf (str, " %2.1f" , m_time3);
95
111
m_label3->setString ( str );
96
112
}
97
113
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
+
98
123
void IntervalTestScene::runThisTest ()
99
124
{
100
125
CCLayer* pLayer = new IntervalLayer ();
0 commit comments