#include "HelloWorldScene.h"
#include "cocos/ui/CocosGUI.h"
#include "cocos2d.h" 
#include "CunDangScene.h"
#include "AppDelegate.h"
#include "first.h"
using namespace cocos2d;
using namespace ui;
USING_NS_CC;
Scene* first::createScene()
{
    return first::create();
}

bool first::init()
{

    if ( !Scene::init() )
    {
        return false;
    }    
	
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();


	CunDangScene asd;
	asd.ttt1(1);

	auto btn1 = Button::create("small_exit.png", "small_exit.png");
	btn1->setScale9Enabled(true);
	//btn->setTitleText("Jump");
	btn1->setTitleFontSize(35);
	btn1->setContentSize(Size(400, 133));
	btn1->setPosition(Vec2(3340, 500));
	btn1->addTouchEventListener([this, visibleSize](Ref* senderButton, ui::Widget::TouchEventType eventType) {
		auto button = static_cast<ui::Button*>(senderButton);
		switch (eventType) {
		case ui::Widget::TouchEventType::BEGAN: { CCLOG("Button Touch Began"); break; }
		case ui::Widget::TouchEventType::MOVED: { CCLOG("Button Touch Moved"); break; }
		case ui::Widget::TouchEventType::CANCELED: { CCLOG("Button Touch Cancelled"); break; }
		case ui::Widget::TouchEventType::ENDED: {
			CCLOG("Button Touch Ended");
			CCLOG("do action:");
			auto actionGrow = ScaleTo::create(.1f, 2.0f);
			auto actionShrink = ScaleTo::create(.1f, 1.0f);
			button->runAction(Sequence::createWithTwoActions(actionGrow, actionShrink));
			Scene* pScene = HelloWorld::createScene();
			Director::getInstance()->replaceScene(pScene);
			break;
		}
		}
	});
	this->addChild(btn1, 3);

	Sprite* node5 = Sprite::create("ww.png");
	node5->setPosition(Vec2(3840, 1280));
	this->addChild(node5, 1);

	
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("protagonist_move/aaaa.plist");
	auto pSprite2 = Sprite::create();
	pSprite2->setPosition(500, 600);
	this->addChild(pSprite2,2);
	Vector<SpriteFrame*>list;
	list.reserve(2);
	list.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("protagonist_move/10020.png"));
	list.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("protagonist_move/10021.png"));
	auto pAnimation = Animation::createWithSpriteFrames(list, 0.2f, 1000);
	auto pAnimate = Animate::create(pAnimation);
	pSprite2->runAction(pAnimate);
	



    return true;
}








