예제 #1
0
bool T08CCSpriteBatchNode::init()
{
	if (!BaseLayer::init())
		return false;

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	CCPoint ptCenter = ccp(winSize.width / 2, winSize.height / 2);

	/*
		CCSpriteBatchNode是一个容器,只能包容CCSprite对象,要求这些精灵来自同一个纹理
	*/

	CCSpriteBatchNode* pBatch = CCSpriteBatchNode::create("CloseNormal.png");
	addChild(pBatch);
	pBatch->setTag(10);

	CCSprite *pSprite = CCSprite::createWithTexture(pBatch->getTexture());
	pBatch->addChild(pSprite);
	pSprite->setPosition(ptCenter);

	setTouchEnabled(true);
	setTouchMode(kCCTouchesOneByOne);

	return true;
}
예제 #2
0
bool ToyLayer::init()
{

		//=================== Box2D World ========================
		b2Vec2 gravity;
		gravity.Set(0.0F, -10.0F);

		this->world = new b2World(gravity);
		world->SetAllowSleeping(true);
		world->SetContinuousPhysics(true);

		//ToyContact *contact = new ToyContact();
		//world->SetContactListener(contact);


		CCPoint tmp;
		tmp = VisibleRect::leftBottom();
		b2Vec2 lb = b2Vec2(tmp.x / PTM_RATIO, tmp.y / PTM_RATIO);
		tmp = VisibleRect::rightBottom();
		b2Vec2 rb = b2Vec2(tmp.x / PTM_RATIO, tmp.y / PTM_RATIO);
		tmp = VisibleRect::leftTop();
		b2Vec2 lt = b2Vec2(tmp.x / PTM_RATIO, tmp.y / PTM_RATIO);
		tmp = VisibleRect::rightTop();
		b2Vec2 rt = b2Vec2(tmp.x / PTM_RATIO, tmp.y / PTM_RATIO);


		b2BodyDef bodyDef;
		this->groundBody = this->world->CreateBody(&bodyDef);

		//World Edge
		b2BodyDef bd;
		b2Body* ground = this->world->CreateBody(&bd);
		{
				b2EdgeShape shape;
				shape.Set(lb, rb);
				ground->CreateFixture(&shape, 0.0f);
		}

		{
				b2EdgeShape shape;
				shape.Set(lt, rt);
				ground->CreateFixture(&shape, 0.0f);
		}

		{
				b2EdgeShape shape;
				shape.Set(lb, lt);
				ground->CreateFixture(&shape, 0.0f);
		}

		{
				b2EdgeShape shape;
				shape.Set(rb, rt);
				ground->CreateFixture(&shape, 0.0f);
		}

		//enable
		this->setTouchEnabled( true );
		this->setAccelerometerEnabled( true );

		//=================== Others =======================
		this->toyArray = CCArray::create();
		this->toyArray->retain();

		//CCSpriteBatchNode *boxBatch = CCSpriteBatchNode::create("Images/blocks.png", 100);
		CCSpriteBatchNode *boxBatch = CCSpriteBatchNode::create("Images/ToyBrick/Triangle/1.png", 100);
		boxBatch->setTag(1);
		this->addChild(boxBatch, 0);
		this->boxTexture = boxBatch->getTexture();

		//init
		this->AddRandomToyBrick(ccp(200, 200));
		this->AddRandomToyBrick(ccp(300, 300));
		this->AddRandomToyBrick(ccp(500, 500));
		
		CCSize winSize = CCDirector::sharedDirector()->getWinSize();

		//Menu -Close
		CCMenuItemImage *closeItem = CCMenuItemImage::create(
				"close.png",
				"close.png",
				this,
				menu_selector(ToyLayer::Back));
		closeItem->setAnchorPoint(CCPointZero);
		closeItem->setScale(2);
		CCSize itemSize = closeItem->getContentSize();
		closeItem->setPosition(winSize.width - (itemSize.width + 15) *  2,  winSize.height - (itemSize.height + 15) * 2);
		CCMenu* menu = CCMenu::create(closeItem, NULL);
		menu->setPosition(0, 0);
		this->addChild(menu);

		//=================== Common Setting =====================
		scheduleUpdate();

		return true;
}
예제 #3
0
void CMO_line::update( float delta )
{
    if ( !m_Connected && CGameManager::GetInstance()->IsConnected(m_Index) == MO_LINE_CONNECTED)
	{
        CAudioManager::GetInstance()->PlayLineDrawRandomSE();
        
        // 처음으로 연결되는 시점
        // 이미지를 바꿔주고, 연결상태 플래그 변경
        changeImage();
		m_Connected = true;
        m_RecentConnection = true;
        
        CGameManager::GetInstance()->SetRecentConnectedLine(m_Index);
        
        // 애니메이션 관련
        CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(LineAnimationFileList[m_ImageFileIdx % 2].c_str());
        CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
        cache->addSpriteFramesWithFile(LineAnimationFileListPlist[m_ImageFileIdx % 2].c_str());
        
        CCArray* animFrames = CCArray::createWithCapacity(48);
        
        char str[100] = {0};
        
        for(int i = 1; i < 49; i++)
        {
            if(m_ImageFileIdx % 2==0)
            {
                sprintf(str, "ani_playscene_line_recent_v_000%02d.png", i);
            }
            else
            {
                sprintf(str, "ani_playscene_line_recent_000%02d.png", i);
            }
            
            CCSpriteFrame* frame = cache->spriteFrameByName( str );
            animFrames->addObject(frame);
        }
        
        // 최근 연결 라인 강조 관련
        CCSprite*pElement;
        if(m_ImageFileIdx % 2==0)
        {
            pElement = CCSprite::createWithSpriteFrameName("ani_playscene_line_recent_v_00001.png");
            pElement->setAnchorPoint(ccp(1,0));
        }
        else
        {
            pElement = CCSprite::createWithSpriteFrameName("ani_playscene_line_recent_00001.png");
            pElement->setAnchorPoint(ccp(0,0));
        }
        
        // 강조하는 라인으로 기존 라인을 덮어버림 ??
        spritebatch->addChild(pElement);
        addChild(spritebatch,2);
        spritebatch->setTag(0);
        
        // 애니메이션 재생
        CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames,PLAYSCENE_ANIMATION_TIME/48);
        CCAction* myLine = CCAnimate::create(animation);
        pElement->runAction(myLine);
    }
    else if( m_Connected && m_RecentConnection && !(CGameManager::GetInstance()->GetRecentConnectedLine() == m_Index) )
    {
        // 연결된 상태 + 강조된 상태 + 하지만 실제로 최근어 그어진 라인은 다른 라인 = 강조 상태 되돌리기
        // 업데이트가 있어야만 진입하므로 실제로는 다른 선이 새로 그어질 때 호출
        m_RecentConnection = false;
        removeChildByTag(0);
        pLine->setVisible(true);
    }
}
예제 #4
0
void CMainMenuLayer::drawAnimation()
{
    
    CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(MAIN_MENU1_ANI.c_str());
    CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->addSpriteFramesWithFile(MAIN_MENU1_ANI_PLIST.c_str());
    
    
    CCArray* animFrames1 = CCArray::createWithCapacity(40);
    
    char str[100] = {0};
    
    for(int i = 1; i < 41; i++)
    {
        sprintf(str, "manin_menu1_000%02d.png", i);
        
        CCSpriteFrame* frame = cache->spriteFrameByName( str );
        animFrames1->addObject(frame);
    }
    
    CCSprite*pElement1 = CCSprite::createWithSpriteFrameName("manin_menu1_00001.png");
    pElement1->setAnchorPoint(ccp(0,0));
    
    spritebatch->addChild(pElement1);
    addChild(spritebatch,2);
    spritebatch->setTag(0);
    
    CCAnimation* animation1 = CCAnimation::createWithSpriteFrames(animFrames1,0.05f);
    CCRepeatForever* repeatAction1 = CCRepeatForever::create(CCAnimate::create(animation1));
    pElement1->runAction(repeatAction1);
    pElement1->setPosition(CCPoint(MAIN_MENU1_IMG_POS));
     
    
    //menu2
    spritebatch = CCSpriteBatchNode::create(MAIN_MENU2_ANI.c_str());
    //cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->addSpriteFramesWithFile(MAIN_MENU2_ANI_PLIST.c_str());
    
    
    CCArray* animFrames2 = CCArray::createWithCapacity(4);
    
    for(int i = 0; i < 4; i++)
    {
        sprintf(str, "main_img2_ani%d.PNG", i);
        
        CCSpriteFrame* frame = cache->spriteFrameByName( str );
        animFrames2->addObject(frame);
    }
    
    CCSprite*pElement2 = CCSprite::createWithSpriteFrameName("main_img2_ani0.PNG");
    pElement2->setAnchorPoint(ccp(0,0));
    
    spritebatch->addChild(pElement2);
    addChild(spritebatch,4);
    spritebatch->setTag(0);
    
    CCAnimation* animation2 = CCAnimation::createWithSpriteFrames(animFrames2,0.1f);
    CCRepeatForever* repeatAction2 = CCRepeatForever::create(CCAnimate::create(animation2));
    pElement2->runAction(repeatAction2);
    pElement2->setPosition(CCPoint(MAIN_MENU2_IMG_POS));
    
    //menu3
    spritebatch = CCSpriteBatchNode::create(MAIN_MENU3_ANI.c_str());
    //cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->addSpriteFramesWithFile(MAIN_MENU3_ANI_PLIST.c_str());
    
    
    CCArray* animFrames3 = CCArray::createWithCapacity(4);
    
    for(int i = 0; i < 4; i++)
    {
        sprintf(str, "main_img3_ani%d.PNG", i);
        
        CCSpriteFrame* frame = cache->spriteFrameByName( str );
        animFrames3->addObject(frame);
    }
    
    CCSprite*pElement3 = CCSprite::createWithSpriteFrameName("main_img3_ani0.PNG");
    pElement3->setAnchorPoint(ccp(0,0));
    
    spritebatch->addChild(pElement3);
    addChild(spritebatch,4);
    spritebatch->setTag(0);
    
    CCAnimation* animation3 = CCAnimation::createWithSpriteFrames(animFrames3,0.1f);
    CCRepeatForever* repeatAction3 = CCRepeatForever::create(CCAnimate::create(animation3));
    pElement3->runAction(repeatAction3);
    pElement3->setPosition(CCPoint(MAIN_MENU3_IMG_POS));

}
예제 #5
0
bool StoryWorld::init() {
  if ( !CCLayer::init() ) {
    return false;
  }
  char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"};
  char play[20] = SCRIPT_PATH;
  current=sGlobal->mapState->storyCnt+'0';
  play[SCRIPT_PATH_LEN] = current;
  reader.ReadFileWithFullPath(CCFileUtils::sharedFileUtils()->fullPathForFilename(play));
  this->setTouchEnabled(true);
  CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
  CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
  
  char bg_name[30] = "" ;
  char bg_num[4]="";
  sprintf(bg_num, "%c00", current);
  sprintf(bg_name, BGNAME_IMG_PATH, bg_num);
  CCSprite *pBackground = CCSprite::createWithTexture(GET_TEXTURE(bg_name));
  //CCSprite* pBackground = CCSprite::create(bg_name);
  pBackground->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
  pBackground->setScale(1);
  pBackground->setTag(108);
  addChild(pBackground, 0);
  
  CCSprite* dialogBox = CCSprite::create(DUIHUAKUANG_IMG_PATH);
  dialogBox->setPosition(ccp(visibleSize.width/2, dialogBox->getContentSize().height/2));
  dialogBox->setOpacity(220);
  addChild(dialogBox,1);
  
  CCLabelTTF* pName = CCLabelTTF::create(theName[0], "Heiti SC", 40);
  pName->setTag(101);
  pName->setPosition(ccp(pName->getContentSize().width/2, dialogBox->getContentSize().height - 2 * pName->getContentSize().height));
  pName->setAnchorPoint(CCPointZero);
  addChild(pName, 1);
  
  
  CCLabelTTF* pLabel = CCLabelTTF::create("Click to Start", "Heiti SC", 40);
  pLabel->setTag(100);
  pLabel->setPosition(ccp(40, origin.y + dialogBox->getContentSize().height - 3.4 * pLabel->getContentSize().height));
  pLabel->setAnchorPoint(CCPointZero);
  pLabel->setDimensions(CCSizeMake(1100, 0));
  pLabel->setHorizontalAlignment(kCCTextAlignmentLeft);
  addChild(pLabel, 1);
  
  
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(PLIST_IMG_PATH);
	CCSpriteBatchNode *spriteBatch = CCSpriteBatchNode::createWithTexture(GET_TEXTURE(VDRAWING_IMG_PATH));
  spriteBatch->setTag(102);
  addChild(spriteBatch, 0);
  spriteBatch->setPosition(CCPointZero);
  
  CCSprite *leftSprite=CCSprite::createWithSpriteFrameName("me_1.png");
  leftSprite->setScale(0.8);
  leftSprite->setPosition(ccp(leftSprite->getContentSize().width*0.6, leftSprite->getContentSize().height/2 *0.8));
  leftSprite->setTag(1);
  leftSprite->setOpacity(0);
  spriteBatch->addChild(leftSprite, 0);
  
  CCSprite *rightSprite=CCSprite::createWithSpriteFrameName("blank.png");
  //rightSprite->setScale(0.8);
  rightSprite->setPosition(ccp(800, 130));
  rightSprite->setTag(2);
  rightSprite->setOpacity(0);
  spriteBatch->addChild(rightSprite, 0);
  
  avgGame();
  return true;
}