예제 #1
0
void SettingsScene::createGameTitle()
{
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	/// Colocar la imagen estatica con el titulo o nombre del juego en la pantalla
	auto gameTitle = Sprite::create("Settings_menu/Settings_title1.png");
	gameTitle->setPosition(Point(visibleSize.width/2 * 1 + origin.x, visibleSize.height - gameTitle->getContentSize().height +30.0f));
	this->addChild(gameTitle, 0);

	auto animation = Animation::create();
	for ( int i = 0; i < 3; ++i )
		animation->addSpriteFrameWithFile( String::createWithFormat("Settings_menu/Settings_title%i.png", i)->getCString() );

	/// Y luego regresarla a su estado inicial
	for ( int i = 2; i >= 0; --i )
		animation->addSpriteFrameWithFile( String::createWithFormat("Settings_menu/Settings_title%i.png", i)->getCString() );

	/// Indicarle que muestre cada una de las imagenes que la componen por 0.1333 segundos
	animation->setDelayPerUnit( 0.1333f );

	/// Lo anterior construye una unica animacion, repetirla siempre y cuando la pantalla de
	/// menu del juego este visible
	auto repeatAnimation = RepeatForever::create( Animate::create(animation) );
	gameTitle->runAction(repeatAnimation);

}
예제 #2
0
파일: Shell.cpp 프로젝트: 1994/AvoidTuitle
Sprite * Shell::createShell(){
    
    auto shellBg  = Sprite::create("res/shell/shell-bg.png");
    auto panel = Sprite::create("res/shell/panel.png");
    
    auto shellUp = Sprite::create("res/shell/shell1-up.png");
    auto shellDown = Sprite::create("res/shell/shell-d.png");
    
    Size size = shellBg->getContentSize();
    
    auto animationOne = Animation::create();
    for( int i=1;i<=6;i++)
    {
        char szName[100] = {0};
        sprintf(szName, "res/shell/shell%d-up.png", i);
        animationOne->addSpriteFrameWithFile(szName);
    }
    // should last 2.8 seconds. And there are 14 frames.
    animationOne->setDelayPerUnit(0.2);
  //  animationOne->setRestoreOriginalFrame(true);
    
    auto animationTwo = Animation::create();
    
    for(int i=7;i<=11;i++){
        char szName[100] = {0};
        sprintf(szName, "res/shell/shell%d-up.png", i);
        animationTwo->addSpriteFrameWithFile(szName);
    }
    
    
    animationTwo->setDelayPerUnit(0.2);
  //  animationTwo->setRestoreOriginalFrame(true);
    
    auto actionOne = Animate::create(animationOne);
    
    auto actionTwo = Animate::create(animationTwo);
    
    
    shellUp->runAction(RepeatForever::create(Sequence::create(actionOne,DelayTime::create(2),actionTwo,DelayTime::create(2),NULL)));
    
    panel->setPosition(Vec2(size.width/2,size.height/2));
    shellUp->setPosition(Vec2(size.width/2,size.height/2));
    shellDown->setPosition(Vec2(size.width/2,size.height/2));
    panel->setScale(0.65);
    shellBg->addChild(shellUp,2);
    shellBg->addChild(shellDown,1);
    shellBg->addChild(panel,1);
    
    
    return shellBg;

}
예제 #3
0
bool LoadingInterface::init()
{
	if (!Layer::init())
	{
		return false;
	}
	m_LoadingPanel = (Layout *)cocostudio::GUIReader::getInstance()->widgetFromJsonFile("res/LoadingRes/Loading_1.json");
	m_LoadingMain = (Layout *)m_LoadingPanel->getChildByName("LoadingMain");
	addChild(m_LoadingPanel);
	m_Animation = (ImageView *)m_LoadingMain->getChildByName("Animation");
	//loading de dong hua 
	Sprite* frame = Sprite::create();
	frame->setPosition(Director::getInstance()->getWinSize()/2);
	auto animation = Animation::create();
	for( int i=1;i<12;i++)
	{
		char szName[100] = {0};
		sprintf(szName, "res/PictureRes/loding/loading%d.png", i);
		animation->addSpriteFrameWithFile(szName);
	}

	animation->setDelayPerUnit(0.05f);
	animation->setRestoreOriginalFrame(true);

	auto action = Animate::create(animation);
	frame->runAction(RepeatForever::create(action));

	m_LoadingMain->addChild(frame);
	//ark_musicCommon::instance()->StartMusic();
	PopLoginInterFace();
	return true;
}
예제 #4
0
파일: guy.cpp 프로젝트: mokena/NoOneDie
bool Guy::init() {
	Sprite::init();

	auto animation = Animation::create();
	for (int i = 1; i <= 5; i++)
	{
		char szName[20] = { 0 };
		sprintf(szName, "guy0%d.png", i);
		animation->addSpriteFrameWithFile(szName);
	}

	animation->setDelayPerUnit(0.25f / 5.0f);
	animation->setRestoreOriginalFrame(true);
	auto action = Animate::create(animation);
	runAction(RepeatForever::create(action));

	Size size = Size(44, 52);
	setContentSize(size);
	setPhysicsBody(PhysicsBody::createBox(size));

	getPhysicsBody()->setRotationEnable(false);
	getPhysicsBody()->setContactTestBitmask(CONTACT_MASK);

	return true;
}
예제 #5
0
bool TowerStar::init()
{
	if (!Tower::init())
		return false;

	auto spriteTD = Sprite::create();
	auto aniTower = Animation::create();

	for (int i = 0; i <= 4; i++)
	{
		char szName[100];
		sprintf(szName, "Star/Star Tower/Star_Tower_%02d.png", i);
		aniTower->addSpriteFrameWithFile(szName);
	}

	//设置帧序列间隔
	aniTower->setDelayPerUnit(0.1);

	//创建帧动画
	auto ani = Animate::create(aniTower);
	auto repeatT = RepeatForever::create(ani);
	spriteTD->runAction(repeatT);
	spriteTD->setScale(0.6);
	this->addChild(spriteTD);

	return true;
}
예제 #6
0
void BillBoardTest::addNewAniBillBoradWithCoords(Vec3 p)
{
    for (unsigned int i = 0; i < 10; ++i)
    {
        auto billboardAni = BillBoard::create("Images/grossini.png");
        billboardAni->setScale(0.5f);
        billboardAni->setPosition3D(Vec3(p.x, p.y,  -150.0f + 30 * i));
        _layerBillBorad->addChild(billboardAni);

        auto animation = Animation::create();
        for( int i=1; i<15; i++)
        {
            char szName1[100] = {0};
            sprintf(szName1, "Images/grossini_dance_%02d.png", i);
            animation->addSpriteFrameWithFile(szName1);
        }
        // should last 2.8 seconds. And there are 14 frames.
        animation->setDelayPerUnit(2.8f / 14.0f);
        animation->setRestoreOriginalFrame(true);

        auto action = Animate::create(animation);
        billboardAni->runAction(RepeatForever::create(action));
        billboardAni->setOpacity(CCRANDOM_0_1() * 128 + 128);
        _billboards.push_back(billboardAni);
    }
}
예제 #7
0
void CrushNode::setFireState(bool isTrue)
{
	if (!m_pFireSprite)
	{
		m_isBecomeFire = false;
		m_isFireState = isTrue;
		m_pFireSprite = Sprite::create();
		auto animation = Animation::create(); 
		for( int i=1;i<3;i++) 
		{ 
			char szName[100] = {0}; 
			sprintf(szName, "jm_dongxiao_%d.png", i); 
			animation->addSpriteFrameWithFile(szName); 
		} 
		m_pFireSprite->setScale(0.5f);
		m_pFireSprite->setAnchorPoint(Vec2(0,0));
		m_pFireSprite->setPosition(Vec2(-25,-20));
		animation->setDelayPerUnit(0.1f); 
		animation->setRestoreOriginalFrame(true); 
		auto action = Animate::create(animation); 
		auto doAction = RepeatForever::create(Sequence::create(action, action->reverse(),NULL));
		m_pFireSprite->runAction(doAction);
		m_pFireSprite->setZOrder(-1);
		addChild(m_pFireSprite);
		//m_pFireSprite->retain();
	}

}
예제 #8
0
void GameObjHero::onEnter()
{
    Layer::onEnter();
    
    this->setContentSize(Size(85, 90));
    
    // cat body
    auto mainsprite = Sprite::create("catBody1.png");
    auto ani = Animation::create();
    ani->addSpriteFrameWithFile("catBody1.png");
    ani->addSpriteFrameWithFile("catBody2-4.png");
    ani->addSpriteFrameWithFile("catBody3.png");
    ani->addSpriteFrameWithFile("catBody2-4.png");
    ani->setDelayPerUnit(0.1f);
    ani->setRestoreOriginalFrame(true);
    
    mainsprite->runAction(RepeatForever::create(Animate::create(ani)));
    
    addChild(mainsprite);
    
    
    // cat tail
    auto tail= Sprite::create("catTail.png");
    tail->setAnchorPoint(Vec2(0.5, 1));
    tail->setPosition(Vec2(-5, -29));
    tail->setScale(0.5, 0.5);
    tail->setRotation(20);
    
    tail->runAction(RepeatForever::create(Sequence::create(RotateBy::create(0.5, -40), RotateBy::create(0.5, 40), NULL)));
    
    addChild(tail);
    
    // cat left hand
    auto lefthand = Sprite::create("catHand1.png");
    lefthand->setAnchorPoint(Vec2(1, 0.5));
    lefthand->setPosition(Vec2(-18, -20));
    addChild(lefthand);
    
    
    // cat right hand
    auto righthand = Sprite::create("catHand2.png");
    righthand->setAnchorPoint(Vec2(0, 0.5));
    righthand->setPosition(Vec2(18,-20));
    addChild(righthand);
    
    schedule(CC_SCHEDULE_SELECTOR(GameObjHero::releaseBullet), 1.0f , CC_REPEAT_FOREVER, 0.0f);
}
예제 #9
0
Animation* HelloWorld::createAnimationWithName(std::string name, float delay, int num)
{
    auto animation = Animation::create();
    for (unsigned int i=1; i<=num; i++) {
        std::string frameName = name;
        frameName.append(StringUtils::format("%d",i)).append(".png");
        animation->addSpriteFrameWithFile(frameName.c_str());
    }
    animation->setDelayPerUnit(delay);
    animation->setRestoreOriginalFrame(true);
    return animation;
}
Animation* Character::createAnimationMultiSprite(const char* spriteLocation, int numberOfSprites, float delay)
{
	char str[100];

	auto animation = Animation::create();
	animation->setDelayPerUnit(delay);

	for (int i = 1; i < numberOfSprites + 1; i++)
	{
		sprintf(str, spriteLocation, i);

		animation->addSpriteFrameWithFile(str);
	}

	return animation;
}
예제 #11
0
void PlayRunLayer::loadFrame(){
    //节奏线碰撞时的动画效果
    auto animation = Animation::create();
    animation->addSpriteFrameWithFile("game/play/hitline_blink.png");
    animation->setDelayPerUnit(0.3f);
    animation->setRestoreOriginalFrame(true);
    AnimationCache::getInstance()->addAnimation(animation, "hitline_blink");
    
    //增加撞线
    auto mRhythm = ui::Scale9Sprite::create("game/play/hitline.png");
    mRhythm->setAnchorPoint(Vec2(0.5,0));
    mRhythm->setPosition(Vec2(gameConfig->impactLine, 0));
    mRhythm->setPreferredSize(Size(mRhythm->getContentSize().width,gameConfig->contentHeight-gameConfig->chordHeight));
    mRhythm->setTag(8001);
    this->addChild(mRhythm,3);

    //和弦区域的底图
    if(gameConfig->musicModel->getType()==MUSICMODEL_TYPE_CHORD){
        auto chordBanner = Sprite::create("game/play/chordbanner.png");
        chordBanner->setPosition(Vec2(0,gameConfig->contentWidth-gameConfig->chordHeight));
        this->addChild(chordBanner);
    }

    //弦间的高度
    int stringCount = 5;
    for (int i=0; i<6; i++) {
        float stringHeight = gameConfig->stringUnitHeight*stringCount;
        stringMap[i+1]=Value(stringHeight);
        
        ui::Scale9Sprite *mString = ui::Scale9Sprite::create("game/play/string.png");
        mString->setPreferredSize(Size(Vec2(gameConfig->contentWidth, mString->getContentSize().height)));
        //设置弦的位置 Y轴:距离下边界的位置+弦的位置
        mString->setPosition(Vec2(gameConfig->contentWidth/2,gameConfig->stringSideHeight+stringHeight));
        this->addChild(mString,1);
        
        stringCount-=1;
    }
}
예제 #12
0
bool Thunder::init()
{
    if (!Entity::init())
        return false;

    auto animation = Animation::create();

    //auto anisprite = Sprite::create("Thunder/Thunder_Picture.png");
    //SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Sprite/Thunder/Thunder_Picture.plist", anisprite->getTexture());

    char szName[100];
    for (int i = 1; i <= 10; ++i)
    {
        sprintf(szName, "Thunder/thunder%02d.png", i);
        animation->addSpriteFrameWithFile(szName);
    }

    animation->setDelayPerUnit(0.05);
    animation->setLoops(1);

    auto sprite = Sprite::create();
    auto animate = Animate::create(animation);
    auto deadFunc = CallFunc::create([this]() {
        this->removeFromParent();
    });
    auto sequence = Sequence::create(animate, deadFunc, NULL);
    sprite->setScale(0.2);
    sprite->setAnchorPoint(Vec2(0.5, 0.05));
    sprite->setPositionY(-20.0);
    sprite->runAction(sequence);

    this->addChild(sprite);

    this->scheduleUpdate();

    return true;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.
    
    auto lbl_title = LabelTTF::create("じゃんけんゲーム", "HiraKakuProN-W6", 30);
    lbl_title->setPosition(Point(origin.x +visibleSize.width/2,
                                 origin.y +visibleSize.height - lbl_title->getContentSize().height ));
    this->addChild(lbl_title);
    
    // グーだけの単一スプライトを表示する
    jangken_aite = Sprite::create("goo.png");
    jangken_aite->setPosition(Point(origin.x+visibleSize.width/2,
                                    origin.y+visibleSize.height
                                    - lbl_title->getContentSize().height
                                    - jangken_aite->getContentSize().height
                                    -20));
    this->addChild(jangken_aite);
    
    // アニメーションを生成する
    auto jangken_anime = Animation::create();
    jangken_anime->addSpriteFrameWithFile("choki.png");
    jangken_anime->addSpriteFrameWithFile("par.png");
    jangken_anime->addSpriteFrameWithFile("goo.png");
    jangken_anime->setDelayPerUnit(0.1f);
    jangken_anime->setLoops(-1);
    jangken_anime->setRestoreOriginalFrame(true);
    jangken_anime_run = (CCAnimate*)CCSequence::create(
                                                CCAnimate::create(jangken_anime),
                                                NULL);
    // アニメーション実行
    jangken_aite->runAction(jangken_anime_run);
    
    
    
    // じゃんけんボタンを追加
    auto btn_goo = MenuItemImage::create("goo.png", "goo.png", CC_CALLBACK_1(HelloWorld::pushGoo, this));
    auto btn_choki = MenuItemImage::create("choki.png", "choki.png", CC_CALLBACK_1(HelloWorld::pushChoki, this));
    auto btn_par = MenuItemImage::create("par.png", "par.png", CC_CALLBACK_1(HelloWorld::pushPar, this));
    
    btn_goo->setPosition(Point(origin.x + btn_goo->getContentSize().width/2 + 10,
                               origin.y + visibleSize.height/2 - 20));
    
    btn_choki->setPosition(Point(btn_goo->getPosition().x + btn_choki->getContentSize().width + 10,
                               origin.y + visibleSize.height/2 - 20));
    
    btn_par->setPosition(Point(btn_choki->getPosition().x + btn_par->getContentSize().width + 10,
                               origin.y + visibleSize.height/2 - 20));
    
    
    auto btns = Menu::create(btn_goo, btn_choki, btn_par, NULL);
    btns->setPosition(Point::ZERO);
    this->addChild(btns);
    
    
    
    // 乱数を初期化
    srand((unsigned)time(NULL));
    
    lbl_dis = LabelTTF::create("", "HiraKakuProN-W6", 30);
    lbl_dis->setPosition(Point(origin.x + visibleSize.width/2,
                               origin.y + 200));
    addChild(lbl_dis);
    
    
    return true;
}