2012-04-19 14:35:52 +08:00
|
|
|
#include "IntervalTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
|
|
|
#define SID_STEP1 100
|
|
|
|
#define SID_STEP2 101
|
|
|
|
#define SID_STEP3 102
|
|
|
|
|
|
|
|
#define IDC_PAUSE 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IntervalLayer::IntervalLayer()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_time0 = _time1 = _time2 = _time3 = _time4 = 0.0f;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
// sun
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sun = ParticleSun::create();
|
2013-11-07 21:48:39 +08:00
|
|
|
sun->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
|
2014-04-15 18:23:40 +08:00
|
|
|
sun->setPosition( Vector2(VisibleRect::rightTop().x-32,VisibleRect::rightTop().y-32) );
|
2010-09-06 17:14:41 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
sun->setTotalParticles(130);
|
|
|
|
sun->setLife(0.6f);
|
|
|
|
this->addChild(sun);
|
2010-09-06 17:14:41 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// timers
|
2014-03-28 10:28:44 +08:00
|
|
|
_label0 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
|
|
|
_label1 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
|
|
|
_label2 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
|
|
|
_label3 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
|
|
|
_label4 = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "0");
|
2010-09-25 11:54:33 +08:00
|
|
|
|
|
|
|
scheduleUpdate();
|
2012-04-19 14:35:52 +08:00
|
|
|
schedule(schedule_selector(IntervalLayer::step1));
|
|
|
|
schedule(schedule_selector(IntervalLayer::step2), 0);
|
|
|
|
schedule(schedule_selector(IntervalLayer::step3), 1.0f);
|
2010-09-25 11:54:33 +08:00
|
|
|
schedule(schedule_selector(IntervalLayer::step4), 2.0f);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_label0->setPosition(Vector2(s.width*1/6, s.height/2));
|
|
|
|
_label1->setPosition(Vector2(s.width*2/6, s.height/2));
|
|
|
|
_label2->setPosition(Vector2(s.width*3/6, s.height/2));
|
|
|
|
_label3->setPosition(Vector2(s.width*4/6, s.height/2));
|
|
|
|
_label4->setPosition(Vector2(s.width*5/6, s.height/2));
|
2010-09-25 11:54:33 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_label0);
|
|
|
|
addChild(_label1);
|
|
|
|
addChild(_label2);
|
|
|
|
addChild(_label3);
|
|
|
|
addChild(_label4);
|
2010-09-25 11:54:33 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Sprite
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create(s_pathGrossini);
|
2014-04-15 18:23:40 +08:00
|
|
|
sprite->setPosition( Vector2(VisibleRect::left().x + 40, VisibleRect::bottom().y + 50) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto jump = JumpBy::create(3, Vector2(s.width-80,0), 50, 4);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(sprite);
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite->runAction( RepeatForever::create(Sequence::create(jump, jump->reverse(), NULL) ));
|
2012-04-19 14:35:52 +08:00
|
|
|
// pause button
|
2014-02-20 10:53:49 +08:00
|
|
|
auto item1 = MenuItemFont::create("Pause", [&](Ref* sender) {
|
2013-07-12 06:24:23 +08:00
|
|
|
if(Director::getInstance()->isPaused())
|
|
|
|
Director::getInstance()->resume();
|
2013-06-08 08:21:11 +08:00
|
|
|
else
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->pause();
|
2013-06-08 08:21:11 +08:00
|
|
|
});
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menu = Menu::create(item1, NULL);
|
2014-04-15 18:23:40 +08:00
|
|
|
menu->setPosition( Vector2(s.width/2, s.height-50) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild( menu );
|
|
|
|
}
|
|
|
|
|
|
|
|
IntervalLayer::~IntervalLayer()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
if(Director::getInstance()->isPaused())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->resume();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void IntervalLayer::update(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_time0 +=dt;
|
2012-04-19 14:35:52 +08:00
|
|
|
char time[10] = {0};
|
2013-06-15 14:03:30 +08:00
|
|
|
sprintf(time, "%2.1f", _time0);
|
|
|
|
_label0->setString(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void IntervalLayer::step1(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_time1 +=dt;
|
2010-09-06 17:14:41 +08:00
|
|
|
|
2010-09-10 14:49:22 +08:00
|
|
|
char str[10] = {0};
|
2013-06-15 14:03:30 +08:00
|
|
|
sprintf(str, "%2.1f", _time1);
|
|
|
|
_label1->setString( str );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void IntervalLayer::step2(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_time2 +=dt;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-09-10 14:49:22 +08:00
|
|
|
char str[10] = {0};
|
2013-06-15 14:03:30 +08:00
|
|
|
sprintf(str, "%2.1f", _time2);
|
|
|
|
_label2->setString( str );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void IntervalLayer::step3(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_time3 +=dt;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-09-10 14:49:22 +08:00
|
|
|
char str[10] = {0};
|
2013-06-15 14:03:30 +08:00
|
|
|
sprintf(str, "%2.1f", _time3);
|
|
|
|
_label3->setString( str );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void IntervalLayer::step4(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_time4 +=dt;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
char str[10] = {0};
|
2013-06-15 14:03:30 +08:00
|
|
|
sprintf(str, "%2.1f", _time4);
|
|
|
|
_label4->setString( str );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntervalTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new IntervalLayer();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
|
|
|
layer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|