Example #1
0
//******************************************************************************
// showSkillAnimtion
//******************************************************************************
void Card::showSkillAnimation() {
    CCAnimation *skillAnim = CCAnimation::animation();
    char skillAnimName[100] = {0};
    for (int i = 2; i <= 13 ; i++) {
        sprintf(skillAnimName, "skill00%02d.png", i);
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(skillAnimName);
        skillAnim->addFrame(frame);
    }
    CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("blank.png");
    skillAnim->addFrame(frame);

    skillAnim->setDelay(0.5f / 14);
    CCAnimate* skillAction = CCAnimate::actionWithAnimation(skillAnim, true);
    
    CCSprite *spSkillAnim = CCSprite::spriteWithSpriteFrameName("skill0001.png");
    spSkillAnim->setPositionInPixels(CCPointMake(55 + 106 * m_idx, 615));
    spSkillAnim->setScale(2.0f);
    addChild(spSkillAnim, 1, kToBeDeleteTag);
    
    spSkillAnim->runAction(CCSequence::actions(skillAction,
                                               CCCallFunc::actionWithTarget(this, callfunc_selector(Card::delUnusedObj)),
                                               NULL));
}
JS_STATIC_FUNC_IMP(S_CCAnimation, jsAddFrame)
{
	//		void addFrame(CCSpriteFrame *pFrame);

	if (argumentCount == 1) {
		CCAnimation* self = (CCAnimation *)JSObjectGetPrivate(thisObject);
		JSStringRef str = JSValueToStringCopy(ctx, arguments[0], NULL);
		int len = JSStringGetLength(str);
		char *buff = (char *)malloc(len+1);
		JSStringGetUTF8CString(str, buff, len+1);
		
		CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(buff);
		if (frame) {
			self->addFrame(frame);
		}

		JSStringRelease(str);
		free(buff);
	}
	return JSValueMakeUndefined(ctx);
}
Example #3
0
//******************************************************************************
// initConnecting
//******************************************************************************
void CommDlg::initConnecting()
{
    CCSprite* sp = CCSprite::spriteWithSpriteFrameName("commdlg.png");
    if(sp){
        addChild(sp);
    }
    
    char buf[100];
    
    CCSprite *temSp = CCSprite::spriteWithSpriteFrameName("loading0001.png");
    temSp->setPosition(CCPointMake(-120 - 15, 30));
    addChild(temSp);
    
    CCAnimation *loadingAnim = CCAnimation::animation();
    char loadingAnimName[100] = {0};
    for (int i = 1; i <= 8 ; i++) {
        sprintf(loadingAnimName, "loading00%02d.png", i);
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName( loadingAnimName );
        loadingAnim->addFrame(frame);
    }
    loadingAnim->setDelay(1.0f / 8);
    CCAnimate* loadingAction = CCAnimate::actionWithAnimation(loadingAnim, true);
    temSp->runAction(CCRepeatForever::actionWithAction(loadingAction));
    
    snprintf(buf, 99, "%s",OcProxy::Inst()->localizedStringStatic("loading_title"));
    TextNode* lbText = TextNode::textWithString(buf, CCSizeMake(200, 45), CCTextAlignmentCenter,45);
    lbText->setColor(ccWHITE);
    lbText->setShadowColor(ccBLACK);
    lbText->setPosition(CCPointMake(60 - 45, 20));
    addChild(lbText, 2);
    
    CCLabelTTF* ttfText = CCLabelTTF::labelWithString(OcProxy::Inst()->localizedStringStatic("loading_prompt"), CCSizeMake(360, 60), CCTextAlignmentCenter, "default.ttf", 20);
    ttfText->setColor(ccc3(233, 183, 72));
    ttfText->setPosition(CCPointMake(0, -80));
    addChild(ttfText);
}
Example #4
0
CCSprite* WordPuzzleLayer::getImageWithIndex(CCArray* wordIdxArray, int index)
{
	CCString* idxString = (CCString*)wordIdxArray->objectAtIndex(index);
	// 태호씨 워드스키마를 DBController로 대체
	DBController* wordSchema = DBController::sharedDB();
	char buf[100];
	sprintf(buf, "WHERE words.idx=%s", idxString->m_sString.c_str());
#if (defined PD_IPHONE) || (defined ANDROID_PHONE)    
	wordSchema->queryWithWhereStatementDBWordsSchema(buf);
	if (wordSchema->fetchDBWordsSchema()) 
#else
        wordSchema->queryWithWhereStatement(buf);
	if (wordSchema->fetch()) 
#endif
	{
		// handle data from database record
	
		SqlQuery query( *DBController::sharedDB()->getDB() );
		
		std::ostringstream strStream;
		CCString *ccStr = (CCString*)wordIdxArray->objectAtIndex(index);
		strStream << "SELECT soundName,imageName FROM words WHERE words.idx=" <<  ccStr->toStdString();
		SqlResult r = query( strStream.str() );
		
		if (r.empty()) 
			return NULL;
		
		
#if (defined PD_IPHONE) || (defined ANDROID_PHONE)
		soundPath = "sound/voice/" + r.fetch();
#else
		soundPath = "voice/" + r.fetch();
#endif
		
		
		string imageName = r.fetch();
		
		//프레임 애니메이션 생성 코드
		CCAnimation *ani = CCAnimation::animation();
		char buf[200];
		int count = 0;
		
		// picturecard/ani/a/abacus_ca_img00.png 형식으로 넘어온다. 뒤에 6글자 잘라서 번호 다시 붙여사용
		// 이미지가 존재할 경우에만 화면에 추가
		if ( imageName.length() != 0 && imageName != " ")
		{
			// DB에는 파일명만저장, 경로 붙여줄것
#if (defined PD_IPHONE) || (defined ANDROID_PHONE)
			imageName = __CONFIG_IMAGE_PATH_ANIMATION_ "350/" + imageName.substr(0,1) +"/" + imageName;
#else
			imageName = "ani/350/" + imageName.substr(0,1) +"/" + imageName;
#endif
			imageName = imageName.substr(0, imageName.length()-6);
		}
		
		while (1) 
		{
			sprintf(buf,"%s%02d.png",imageName.c_str(),count);
			// 첫프레임 대표스프라이트는 직접 add
			if (count == 0) 
			{
				sprImage = CCSprite::spriteWithFile(buf);
				if (sprImage) 
				{
					sprImage->setAnchorPoint(imageAnchor);	
					sprImage->setScale(imageOriginalScale);
					sprImage->setPosition(imagePosition);
				}
			}
			
			// 아이폰의 경우 bundle에 접근하면 되고
			// 안드로이드는 zip으로 패키징된 apk에 접근해야한다
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
			if( LCUtil::isFileExistAtBundle(buf) )
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)	
				if( CCFileUtils::isFileExistInAPK(buf) )
#endif 
				{
					CCSprite *sprFrame = CCSprite::spriteWithFile(buf);
					ani->addFrame(CCSpriteFrame::frameWithTexture(sprFrame->getTexture(),sprFrame->getTextureRect()));
					count++;
				}
				else
					break;
		}
		// 프레임이 한장 이상일경우에만 애니 실행
		if (count > 1) 
		{
			ani->setDelay(0.25);
			aniAction = CCAnimate::actionWithAnimation(ani, true);
			aniAction->retain();
		}
		else 
		{
			aniAction = NULL;
		}	
		
		return sprImage;
	}
	return NULL;
}
Example #5
0
// *************************************************************************************************
// Layer Init
// *************************************************************************************************
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}
    this->setIsTouchEnabled(true);
    this->setIsKeypadEnabled(true);
    
    Depth = 0;
    // LayerColor 初始化
    this->initWithColor(ccc4f(0,0,0,150));
    this->setContentSize(CCSizeMake(WorkSize_W, WorkSize_H));
    this->setIsVisible(true);
    
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Common.plist");
	CCSpriteBatchNode *spriteCommon = CCSpriteBatchNode::batchNodeWithFile("Common.png");
	spriteCommon->getTextureAtlas()->resizeCapacity(50);
	addChild(spriteCommon);
    
	/////////////////////////////
	// 2. add a menu item with "X" image, which is clicked to quit the program
	//    you may modify it.

	// add a "close" icon to exit the progress. it's an autorelease object
	CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
										"CloseNormal.png",
										"CloseSelected.png",
										this,
										menu_selector(HelloWorld::menuCloseCallback) );
	pCloseItem->setPosition( ccp(WorkSize_W - 20, 20) );
	CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
	pMenu->setPosition( CCPointZero );
	this->addChild(pMenu);
    

	CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 50);
	pLabel->setPosition( ccp(WorkSize_W/ 2, WorkSize_H - 20) );
	this->addChild(pLabel);

    // 商店進入鈕
    CCMenuItemImage *StoreItem = CCMenuItemImage::itemFromNormalImage(
                                                   "HelloWorld.png",
                                                   "HelloWorld.png",
                                                   this,
                                                   menu_selector(HelloWorld::StoreButtonCallback));
	StoreItem->setPosition( ccp(WorkSize_W/2, WorkSize_H/2) );
	StoreMenu = CCMenu::menuWithItems(StoreItem, NULL);
	StoreMenu->setPosition( CCPointZero );
	this->addChild(StoreMenu);
    
    // 商店介面
    spriteStoreBG = CCSprite::spriteWithSpriteFrameName("ui_shop_01.png");
    spriteStoreBG->setPosition(fcp(Rectx, Recty));
    spriteStoreBG->setIsVisible(false);
    this->addChild(spriteStoreBG, Depth++);
    
    
    // 商店離開鈕
    CCMenuItem *StoreExitItem = CCMenuItemSprite::itemFromNormalSprite(
                                   CCSprite::spriteWithSpriteFrameName("ui_shop_04.png"), CCSprite::spriteWithSpriteFrameName("ui_shop_04.png"), this, menu_selector(HelloWorld::StoreExitBtnCallback));
    CCMenu *StoreExitMenu = CCMenu::menuWithItem(StoreExitItem);
    StoreExitMenu->setPosition(ccp(StoreExitx, StoreExity));
    spriteStoreBG->addChild(StoreExitMenu);
    
    // 準備商店項目素材
    frameStoreItems[0] = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("ui_shop_02.png"); // 金幣
    frameStoreItems[1] = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("ui_shop_03.png"); // 籌碼
    // 商店項目
    for(int a = 0; a < MAX_IAP_NUM; a++)
    {
        // 商品項目
        spriteStoreItems[a] = CCSprite::spriteWithSpriteFrame(frameStoreItems[0]);
        spriteStoreItems[a]->setPosition(ccp(StoreItemx[a], StoreItemy[a]));
        spriteStoreItems[a]->setOpacity(255);
        spriteStoreItems[a]->setIsVisible(false);
        spriteStoreBG->addChild(spriteStoreItems[a], a);
        
        // 商品內容
        labelItemContent[a] = CCLabelTTF::labelWithString("------", "arial", ItemContentFrontSize);
        labelItemContent[a]->setColor(ccWHITE);
        labelItemContent[a]->setPosition(ccp(ItemContentx[a],ItemContenty[a]));
        spriteStoreItems[a]->addChild(labelItemContent[a]);
        
        // 商項目購買金額初始化
        labelItemPrice[a] = CCLabelTTF::labelWithString("------", "arial", ItemPriceFrontSize);
        labelItemPrice[a]->setColor(ccWHITE);
        labelItemPrice[a]->setPosition(ccp(ItemPricex[a],ItemPricey[a]));
        spriteStoreItems[a]->addChild(labelItemPrice[a]);
    }
    
    // 商店Loading背景
    spriteLoadingBG = CCSprite::spriteWithSpriteFrameName("loading10.png");
    spriteLoadingBG->setPosition(fcp(LoadingBGx, LoadingBGy));
    spriteLoadingBG->setIsVisible(false);
    spriteLoadingBG->setScale(0.3f);
    this->addChild(spriteLoadingBG, Depth++);
    // 商店Loading背景動畫
    spriteLoadingBG->runAction(CCRepeatForever::actionWithAction(CCRotateBy::actionWithDuration(1.0f, 360.0f)));
    
    // 商店Loading文字(讀取中...)
    spriteLoading = CCSprite::spriteWithSpriteFrameName("loading01.png");
    spriteLoading->setPosition(fcp(Loadingx, Loadingy));
    spriteLoading->setIsVisible(false);
    this->addChild(spriteLoading, Depth++);
    // 商店Loading文字字(讀取中...)動畫
    CCAnimation* animation = CCAnimation::animation();
    animation->setDelay(0.1f);
    for(int a = 0; a < 8; a++)
    {
        a < 1 ?
        sprintf(ResourceName, "loading%02d.png", 1):
        sprintf(ResourceName, "loading%02d.png", a);
        
        animation->addFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(ResourceName));
        spriteLoading->runAction(CCRepeatForever::actionWithAction(CCAnimate::actionWithAnimation(animation, true)));
    }
	
	return true;
}