mirror of https://github.com/axmolengine/axmol.git
131 lines
3.5 KiB
C++
131 lines
3.5 KiB
C++
#include "IntervalTest.h"
|
|
#include "../testResource.h"
|
|
|
|
#define SID_STEP1 100
|
|
#define SID_STEP2 101
|
|
#define SID_STEP3 102
|
|
|
|
#define IDC_PAUSE 200
|
|
|
|
|
|
|
|
IntervalLayer::IntervalLayer()
|
|
{
|
|
m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f;
|
|
|
|
CGSize s = CCDirector::getSharedDirector()->getWinSize();
|
|
// sun
|
|
CCParticleSystem* sun = CCParticleSun::node();
|
|
sun->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png"));
|
|
sun->setPosition( CGPointMake(s.width-32,s.height-32) );
|
|
|
|
sun->setTotalParticles(130);
|
|
sun->setLife(0.6f);
|
|
this->addChild(sun);
|
|
|
|
// timers
|
|
m_label0 = CCBitmapFontAtlas::bitmapFontAtlasWithString("0", "fonts/bitmapFontTest4.fnt");
|
|
m_label1 = CCBitmapFontAtlas::bitmapFontAtlasWithString("0", "fonts/bitmapFontTest4.fnt");
|
|
m_label2 = CCBitmapFontAtlas::bitmapFontAtlasWithString("0", "fonts/bitmapFontTest4.fnt");
|
|
m_label3 = CCBitmapFontAtlas::bitmapFontAtlasWithString("0", "fonts/bitmapFontTest4.fnt");
|
|
m_label4 = CCBitmapFontAtlas::bitmapFontAtlasWithString("0", "fonts/bitmapFontTest4.fnt");
|
|
|
|
scheduleUpdate();
|
|
schedule(schedule_selector(IntervalLayer::step1));
|
|
schedule(schedule_selector(IntervalLayer::step2), 0);
|
|
schedule(schedule_selector(IntervalLayer::step3), 1.0f);
|
|
schedule(schedule_selector(IntervalLayer::step4), 2.0f);
|
|
|
|
m_label0->setPosition(CGPointMake(s.width*1/6, s.height/2));
|
|
m_label1->setPosition(CGPointMake(s.width*2/6, s.height/2));
|
|
m_label2->setPosition(CGPointMake(s.width*3/6, s.height/2));
|
|
m_label3->setPosition(CGPointMake(s.width*4/6, s.height/2));
|
|
m_label4->setPosition(CGPointMake(s.width*5/6, s.height/2));
|
|
|
|
addChild(m_label0);
|
|
addChild(m_label1);
|
|
addChild(m_label2);
|
|
addChild(m_label3);
|
|
addChild(m_label4);
|
|
|
|
// Sprite
|
|
CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
|
|
sprite->setPosition( CGPointMake(40,50) );
|
|
|
|
CCJumpBy* jump = CCJumpBy::actionWithDuration(3, CGPointMake(s.width-80,0), 50, 4);
|
|
|
|
addChild(sprite);
|
|
sprite->runAction( CCRepeatForever::actionWithAction(
|
|
(CCIntervalAction*)(CCSequence::actions(jump, jump->reverse(), NULL ))
|
|
)
|
|
);
|
|
// pause button
|
|
CCMenuItem* item1 = CCMenuItemFont::itemFromString("Pause", this, menu_selector(IntervalLayer::onPause) );
|
|
CCMenu* menu = CCMenu::menuWithItems(item1, NULL);
|
|
menu->setPosition( CGPointMake(s.width/2, s.height-50) );
|
|
|
|
addChild( menu );
|
|
}
|
|
|
|
void IntervalLayer::update(ccTime dt)
|
|
{
|
|
m_time0 +=dt;
|
|
char time[10] = {0};
|
|
sprintf(time, "%2.1f", m_time0);
|
|
m_label0->setString(time);
|
|
}
|
|
|
|
void IntervalLayer::onPause(NSObject* pSender)
|
|
{
|
|
if(CCDirector::getSharedDirector()->isPaused())
|
|
CCDirector::getSharedDirector()->resume();
|
|
else
|
|
CCDirector::getSharedDirector()->pause();
|
|
|
|
}
|
|
|
|
void IntervalLayer::step1(ccTime dt)
|
|
{
|
|
m_time1 +=dt;
|
|
|
|
char str[10] = {0};
|
|
sprintf(str, "%2.1f", m_time1);
|
|
m_label1->setString( str );
|
|
}
|
|
|
|
void IntervalLayer::step2(ccTime dt)
|
|
{
|
|
m_time2 +=dt;
|
|
|
|
char str[10] = {0};
|
|
sprintf(str, "%2.1f", m_time2);
|
|
m_label2->setString( str );
|
|
}
|
|
|
|
void IntervalLayer::step3(ccTime dt)
|
|
{
|
|
m_time3 +=dt;
|
|
|
|
char str[10] = {0};
|
|
sprintf(str, "%2.1f", m_time3);
|
|
m_label3->setString( str );
|
|
}
|
|
|
|
void IntervalLayer::step4(ccTime dt)
|
|
{
|
|
m_time4 +=dt;
|
|
|
|
char str[10] = {0};
|
|
sprintf(str, "%2.1f", m_time4);
|
|
m_label4->setString( str );
|
|
}
|
|
|
|
void IntervalTestScene::runThisTest()
|
|
{
|
|
CCLayer* pLayer = new IntervalLayer();
|
|
addChild(pLayer);
|
|
pLayer->release();
|
|
|
|
CCDirector::getSharedDirector()->replaceScene(this);
|
|
}
|