Skip to content

Commit c4c81db

Browse files
author
natural-law
committed
issue #165
Update the tests code to 0.99.4 release version
1 parent 8de5442 commit c4c81db

File tree

8 files changed

+442
-27
lines changed

8 files changed

+442
-27
lines changed

cocos2dx/platform/uphone/CCXApplication_uphone.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ namespace cocos2d {
5151

5252
case EVENT_AppStopNotify:
5353

54+
break;
55+
case EVENT_AppActiveNotify:
56+
if (pEvent->sParam1 == 0)
57+
{
58+
applicationDidEnterBackground(this);
59+
}
60+
else if (pEvent->sParam1 > 0)
61+
{
62+
applicationWillEnterForeground(this);
63+
}
5464
break;
5565
}
5666

cocos2dx/platform/uphone/CCXApplication_uphone.h

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ class CCX_DLL CCXApplication : public TApplication
5858
*/
5959
CGRect statusBarFrame();
6060

61+
/**
62+
@brief The function be called when the application enter background
63+
@param the pointer of the application
64+
*/
65+
virtual void applicationDidEnterBackground(TApplication* pApp) {}
66+
67+
/**
68+
@brief The function be called when the application enter foreground
69+
@param the pointer of the application
70+
*/
71+
virtual void applicationWillEnterForeground(TApplication* pApp) {}
72+
6173
/**
6274
@brief Get current applicaiton instance.
6375
@return Current application instance pointer.

test_uphone/test_uphoneApp.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ Boolean Ttest_uphoneApp::EventHandler(EventType* pEvent)
105105
return bHandled;
106106
}
107107

108+
void Ttest_uphoneApp::applicationDidEnterBackground(TApplication* pApp)
109+
{
110+
CCDirector::getSharedDirector()->stopAnimation();
111+
}
112+
113+
void Ttest_uphoneApp::applicationWillEnterForeground(TApplication* pApp)
114+
{
115+
CCDirector::getSharedDirector()->startAnimation();
116+
}
117+
108118
static void TimerCallback1(Int32 nTimerId, UInt32 uUserData)
109119
{
110120
CCScene * pScene = CCScene::node();

test_uphone/test_uphoneApp.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class Ttest_uphoneApp : public cocos2d::CCXApplication
2121
public:
2222
virtual Boolean EventHandler(EventType * pEvent);
2323

24+
virtual void applicationDidEnterBackground(TApplication* pApp);
25+
virtual void applicationWillEnterForeground(TApplication* pApp);
26+
2427
protected:
2528
cocos2d::CCXEGLView * m_pMainWnd;
2629

test_uphone/tests/IntervalTest/IntervalTest.cpp

+41-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
IntervalLayer::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+
6278
void IntervalLayer::onPause(NSObject* pSender)
6379
{
6480
if(CCDirector::getSharedDirector()->isPaused())
@@ -70,7 +86,7 @@ void IntervalLayer::onPause(NSObject* pSender)
7086

7187
void 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

8096
void 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

89105
void 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+
98123
void IntervalTestScene::runThisTest()
99124
{
100125
CCLayer* pLayer = new IntervalLayer();

test_uphone/tests/IntervalTest/IntervalTest.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
class IntervalLayer : public CCLayer
77
{
88
protected:
9+
CCBitmapFontAtlas* m_label0;
910
CCBitmapFontAtlas* m_label1;
1011
CCBitmapFontAtlas* m_label2;
1112
CCBitmapFontAtlas* m_label3;
13+
CCBitmapFontAtlas* m_label4;
1214

13-
ccTime m_time1, m_time2, m_time3;
15+
ccTime m_time0, m_time1, m_time2, m_time3, m_time4;
1416

1517
public:
1618
IntervalLayer(void);
@@ -21,6 +23,8 @@ class IntervalLayer : public CCLayer
2123
void step1(ccTime dt);
2224
void step2(ccTime dt);
2325
void step3(ccTime dt);
26+
void step4(ccTime dt);
27+
void update(ccTime dt);
2428

2529
//CREATE_NODE(IntervalLayer);
2630
};

0 commit comments

Comments
 (0)