Exemplo n.º 1
0
void ActionNode::initWithDictionary(const rapidjson::Value& dic,CCObject* root)
{
	setActionTag(DICTOOL->getIntValue_json(dic, "ActionTag"));
	int actionFrameCount = DICTOOL->getArrayCount_json(dic, "actionframelist");
	for (int i=0; i<actionFrameCount; i++) {

		const rapidjson::Value& actionFrameDic = DICTOOL->getDictionaryFromArray_json(dic, "actionframelist", i);
		int frameInex = DICTOOL->getIntValue_json(actionFrameDic,"frameid");

		bool existPosition = DICTOOL->checkObjectExist_json(actionFrameDic,"positionx");
		if (existPosition)
		{
			float positionX = DICTOOL->getFloatValue_json(actionFrameDic, "positionx");
			float positionY = DICTOOL->getFloatValue_json(actionFrameDic, "positiony");
			ActionMoveFrame* actionFrame = new ActionMoveFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setPosition(CCPointMake(positionX, positionY));
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeMove);
			cActionArray->addObject(actionFrame);
		}

		bool existScale = DICTOOL->checkObjectExist_json(actionFrameDic,"scalex");
		if (existScale)
		{
			float scaleX = DICTOOL->getFloatValue_json(actionFrameDic, "scalex");
			float scaleY = DICTOOL->getFloatValue_json(actionFrameDic, "scaley");
			ActionScaleFrame* actionFrame = new ActionScaleFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setScaleX(scaleX);
			actionFrame->setScaleY(scaleY);
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeScale);
			cActionArray->addObject(actionFrame);
		}

		bool existRotation = DICTOOL->checkObjectExist_json(actionFrameDic,"rotation");
		if (existRotation)
		{
			float rotation = DICTOOL->getFloatValue_json(actionFrameDic, "rotation");
			ActionRotationFrame* actionFrame = new ActionRotationFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setRotation(rotation);
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeRotate);
			cActionArray->addObject(actionFrame);
		}

		bool existOpacity = DICTOOL->checkObjectExist_json(actionFrameDic,"opacity");
		if (existOpacity)
		{
			int opacity = DICTOOL->getIntValue_json(actionFrameDic, "opacity");
			ActionFadeFrame* actionFrame = new ActionFadeFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setOpacity(opacity);
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeFade);
			cActionArray->addObject(actionFrame);
		}

		bool existColor = DICTOOL->checkObjectExist_json(actionFrameDic,"colorr");
		if (existColor)
		{
			int colorR = DICTOOL->getIntValue_json(actionFrameDic, "colorr");
			int colorG = DICTOOL->getIntValue_json(actionFrameDic, "colorg");
			int colorB = DICTOOL->getIntValue_json(actionFrameDic, "colorb");
			ActionTintFrame* actionFrame = new ActionTintFrame();
			actionFrame->autorelease();
			actionFrame->setFrameIndex(frameInex);
			actionFrame->setColor(ccc3(colorR,colorG,colorB));
			CCArray* cActionArray = (CCArray*)m_FrameArray->objectAtIndex((int)kKeyframeTint);
			cActionArray->addObject(actionFrame);
		}

	}
	initActionNodeFromRoot(root);
}
Exemplo n.º 2
0
	static CCActionInterval* actionWithDuration(ccTime t)
	{
		CCSize size = CCDirector::sharedDirector()->getWinSize();
		return CCRipple3D::actionWithPosition(CCPointMake(size.width/2,size.height/2), 240, 4, 160, ccg(32,24), t);
	}
Exemplo n.º 3
0
void TextureCacheTest::addSprite()
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();

    // create sprites

    CCSprite *bg = CCSprite::create("Images/HelloWorld.png");
    bg->setPosition(CCPointMake(size.width / 2, size.height / 2));

    CCSprite *s1 = CCSprite::create("Images/grossini.png");
    CCSprite *s2 = CCSprite::create("Images/grossini_dance_01.png");
    CCSprite *s3 = CCSprite::create("Images/grossini_dance_02.png");
    CCSprite *s4 = CCSprite::create("Images/grossini_dance_03.png");
    CCSprite *s5 = CCSprite::create("Images/grossini_dance_04.png");
    CCSprite *s6 = CCSprite::create("Images/grossini_dance_05.png");
    CCSprite *s7 = CCSprite::create("Images/grossini_dance_06.png");
    CCSprite *s8 = CCSprite::create("Images/grossini_dance_07.png");
    CCSprite *s9 = CCSprite::create("Images/grossini_dance_08.png");
    CCSprite *s10 = CCSprite::create("Images/grossini_dance_09.png");
    CCSprite *s11 = CCSprite::create("Images/grossini_dance_10.png");
    CCSprite *s12 = CCSprite::create("Images/grossini_dance_11.png");
    CCSprite *s13 = CCSprite::create("Images/grossini_dance_12.png");
    CCSprite *s14 = CCSprite::create("Images/grossini_dance_13.png");
    CCSprite *s15 = CCSprite::create("Images/grossini_dance_14.png");

    // just loading textures to slow down
    CCSprite::create("Images/background1.png");
    CCSprite::create("Images/background2.png");
    CCSprite::create("Images/background3.png");
    CCSprite::create("Images/blocks.png");

    s1->setPosition(CCPointMake(50, 50));
    s2->setPosition(CCPointMake(60, 50));
    s3->setPosition(CCPointMake(70, 50));
    s4->setPosition(CCPointMake(80, 50));
    s5->setPosition(CCPointMake(90, 50));
    s6->setPosition(CCPointMake(100, 50));

    s7->setPosition(CCPointMake(50, 180));
    s8->setPosition(CCPointMake(60, 180));
    s9->setPosition(CCPointMake(70, 180));
    s10->setPosition(CCPointMake(80, 180));
    s11->setPosition(CCPointMake(90, 180));
    s12->setPosition(CCPointMake(100, 180));

    s13->setPosition(CCPointMake(50, 270));
    s14->setPosition(CCPointMake(60, 270));
    s15->setPosition(CCPointMake(70, 270));

    this->addChild(bg);

    this->addChild(s1);
    this->addChild(s2);
    this->addChild(s3);
    this->addChild(s4);
    this->addChild(s5);
    this->addChild(s6);
    this->addChild(s7);
    this->addChild(s8);
    this->addChild(s9);
    this->addChild(s10);
    this->addChild(s11);
    this->addChild(s12);
    this->addChild(s13);
    this->addChild(s14);
    this->addChild(s15);
}
Exemplo n.º 4
0
MapHud::MapHud(int x, int y, float width, float height, Game * game, Layer * layer): HudItem(x,y,CCSprite::create(),HudItem::mapButtonType,game,layer) {
	int width_map = getGame()->get_display_layer()->get_map_width();
	int height_map = getGame()->get_display_layer()->get_map_height();
	int bytes = width_map * height_map * 4;
	void* textureData = malloc(bytes);
	memset(textureData, INT32_MAX, bytes);

	_texture = new CCTexture2DMutable();
	_texture->initWithData(textureData, kCCTexture2DPixelFormat_RGBA8888, width_map, height_map, CCSize(width_map,height_map));

	std::string id;
	for(x=0;x<width_map;x++) {
		for(y=0;y<height_map;y++) {
			_texture->setPixelAt(CCPointMake(x,height_map-y-1),ccc4(0,0,0,255));
		}
	}
	_texture->apply();
	_texture->setAliasTexParameters();
	getSprite()->initWithTexture(_texture);
	_texture->autorelease();

	float scale = fminf( width/getSprite()->getTextureRect().size.width,height/getSprite()->getTextureRect().size.height )*1.1;
	getSprite()->setScale(scale);

	textureData = malloc(bytes);
	memset(textureData, INT32_MAX, bytes);
	_texture_screen_edge = new CCTexture2DMutable();
	_texture_screen_edge->initWithData(textureData, kCCTexture2DPixelFormat_RGBA8888, width_map, height_map, CCSize(width_map,height_map));

	for(x=0;x<width_map;x++) {
		for(y=0;y<height_map;y++) {
			_texture_screen_edge->setPixelAt(CCPointMake(x,height_map-y-1),ccc4(0,0,0,0));
		}
	}
	_texture_screen_edge->apply();
	_texture_screen_edge->setAliasTexParameters();
	_sprite_screen_edge = CCSprite::createWithTexture(_texture_screen_edge);
	getSprite()->addChild(_sprite_screen_edge);
	_sprite_screen_edge->setPositionX(getSprite()->getTextureRect().size.width/2.0);
	_sprite_screen_edge->setPositionY(getSprite()->getTextureRect().size.height/2.0);
	_texture_screen_edge->autorelease();

	update_screen_edge();

	textureData = malloc(bytes);
	memset(textureData, INT32_MAX, bytes);
	_texture_unit = new CCTexture2DMutable();
	_texture_unit->initWithData(textureData, kCCTexture2DPixelFormat_RGBA8888, width_map, height_map, CCSize(width_map,height_map));

	for(x=0;x<width_map;x++) {
		for(y=0;y<height_map;y++) {
			_texture_unit->setPixelAt(CCPointMake(x,height_map-y-1),ccc4(0,0,0,0));
		}
	}
	_texture_unit->apply();
	_texture_unit->setAliasTexParameters();
	_sprite_unit = CCSprite::createWithTexture(_texture_unit);
	getSprite()->addChild(_sprite_unit);
	_sprite_unit->setPositionX(getSprite()->getTextureRect().size.width/2.0);
	_sprite_unit->setPositionY(getSprite()->getTextureRect().size.height/2.0);
	_texture_unit->autorelease();

	update_unit();
}
Exemplo n.º 5
0
//******************************************************************************
// initBtn
//******************************************************************************
void CommDlg::initBtn()
{
    char buf[100];
    //如果还未登录,只显示一个按钮,即要求一定要重试, //付费失败必须重试
    if( ((m_iRc == kReqConnectErr) || (m_iRc == 100) || (m_iRc == 401)) 
        && ((CGameData::Inst()->chkLogin() == false) || (CGameData::Inst()->isPaying() ))){
        //ok
        CCSprite* sp = CCSprite::spriteWithSpriteFrameName("fr_button.png");
        if(sp){
            sp->setPosition(CCPointMake(0, -78));
            addChild(sp, 0, kCommBtnTagOk);
        }
            
        snprintf(buf, 99, "%s", OcProxy::Inst()->localizedStringStatic("sureTip"));
        TextNode* lbText = TextNode::textWithString(buf, CCSizeMake(100, 36), CCTextAlignmentCenter,kBtnTitleHeight);
        lbText->setPosition(CCPointMake(-4, -74));
        lbText->setColor(ccWHITE);
        lbText->setShadowColor(ccBLACK);
        addChild(lbText, 1);
        lbText->setTag(kCommTextTagOk);
    }
    else if((m_iRc == kReqConnectErr) || (m_iRc == 100) || (m_iRc == 401)){
        //ok
        CCSprite* sp = CCSprite::spriteWithSpriteFrameName("fr_button.png");
        if(sp){
            sp->setPosition(CCPointMake(-104, -78));
            addChild(sp, 0, kCommBtnTagOk);
        }
        
        snprintf(buf, 99, "%s", OcProxy::Inst()->localizedStringStatic("sureTip"));
        TextNode* lbText = TextNode::textWithString(buf, CCSizeMake(100, 36), CCTextAlignmentCenter,kBtnTitleHeight);
        lbText->setPosition(CCPointMake(-108, -74));
        lbText->setColor(ccWHITE);
        lbText->setShadowColor(ccBLACK);
        addChild(lbText, 1);
        lbText->setTag(kCommTextTagOk);
        
        //cancel
        sp = CCSprite::spriteWithSpriteFrameName("fr_button.png");
        if(sp){
            sp->setPosition(CCPointMake(104, -78));
            addChild(sp, 0, kCommBtnTagCancel);
        }
        
        snprintf(buf, 99, "%s", CGameData::Inst()->getLanguageValue("cancelTip"));
        lbText = TextNode::textWithString(buf, CCSizeMake(100, 36), CCTextAlignmentCenter,kBtnTitleHeight);
        lbText->setPosition(CCPointMake(100, -74));
        lbText->setColor(ccWHITE);
        lbText->setShadowColor(ccBLACK);
        addChild(lbText, 1);
        lbText->setTag(kCommTextTagCancel);
    }
    else if((m_iRc == 502) || (HttpComm::Inst()->getMaintenance() != 0)){
        //ok
        CCSprite* sp = CCSprite::spriteWithSpriteFrameName("fr_button.png");
        if(sp){
            sp->setPosition(CCPointMake(0, -78));
            addChild(sp, 0, kCommBtnTagOk);
        }
        
        snprintf(buf, 99, "%s", OcProxy::Inst()->localizedStringStatic("sureTip"));
        TextNode* lbText = TextNode::textWithString(buf, CCSizeMake(100, 36), CCTextAlignmentCenter,kBtnTitleHeight);
        lbText->setPosition(CCPointMake(-4, -74));
        lbText->setColor(ccWHITE);
        lbText->setShadowColor(ccBLACK);
        addChild(lbText, 1);
        lbText->setTag(kCommTextTagOk);
    }
    //服务器返回的提示,无需重试,仅显示取消按钮(文字显示为确定)
    else{
        const char* errMsg = CGameData::Inst()->getErrMsg();
        if(errMsg != NULL){
            string eMsg = errMsg;
            if (eMsg.find("武将不存在")!=string::npos) {
                //ok
                CCSprite* sp = CCSprite::spriteWithSpriteFrameName("fr_button.png");
                if(sp){
                    sp->setPosition(CCPointMake(-104, -78));
                    addChild(sp, 0, kCommBtnTagOk);
                }
                
                snprintf(buf, 99, "%s", CGameData::Inst()->getLanguageValue("re_login"));
                TextNode* lbText = TextNode::textWithString(buf, CCSizeMake(100, 36), CCTextAlignmentCenter,kBtnTitleHeight);
                lbText->setPosition(CCPointMake(-108, -74));
                lbText->setColor(ccWHITE);
                lbText->setShadowColor(ccBLACK);
                addChild(lbText, 1);
                lbText->setTag(kCommTextTagOk);
                
                //cancel
                sp = CCSprite::spriteWithSpriteFrameName("fr_button.png");
                if(sp){
                    sp->setPosition(CCPointMake(104, -78));
                    addChild(sp, 0, kCommBtnTagCancel);
                }
                
                snprintf(buf, 99, "%s", CGameData::Inst()->getLanguageValue("cancelTip"));
                lbText = TextNode::textWithString(buf, CCSizeMake(100, 36), CCTextAlignmentCenter,kBtnTitleHeight);
                lbText->setPosition(CCPointMake(100, -74));
                lbText->setColor(ccWHITE);
                lbText->setShadowColor(ccBLACK);
                addChild(lbText, 1);
                lbText->setTag(kCommTextTagCancel);
                return;
            }
        }
        
        CCSprite* sp = CCSprite::spriteWithSpriteFrameName("fr_button.png");
        if(sp){
            sp->setPosition(CCPointMake(0, -78));
            addChild(sp, 0, kCommBtnTagCancel);
        }
        
        snprintf(buf, 99, "%s", OcProxy::Inst()->localizedStringStatic("sureTip"));
        TextNode* lbText = TextNode::textWithString(buf, CCSizeMake(100, 36), CCTextAlignmentCenter,kBtnTitleHeight);
        lbText->setPosition(CCPointMake(-4, -74));
        lbText->setColor(ccWHITE);
        lbText->setShadowColor(ccBLACK);
        addChild(lbText, 1);
    }
}
Exemplo n.º 6
0
void S65ShowVideo::DownLoadFinish()
{
    
    int nbegin=3;
	m_strUrlContent=m_strUrlContent.substr(nbegin,m_strUrlContent.length()-nbegin);
	CDataConvert dataConvert;
	m_strUrlContent=dataConvert.UTF8ToGB(m_strUrlContent.c_str());
    
    
	Json* root= Json_create(m_strUrlContent.c_str());
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    string detailClassName ="S"+PersonalApi::convertIntToString(AppDelegate::S1NaviSelected) +"ShowVideo";
    string currentClassName(detailClassName.c_str());
    string version = currentClassName+"version";
    string needUpDate = currentClassName+"needUpDate";
    string newVersion = currentClassName+"newVersion";
    string time = currentClassName+"time";
    
    Json* root_Version=Json_getItem(root,"version");
    
    if (root_Version)
	{
        string versionStr(root_Version->valuestring);
        
        
        if (CCUserDefault::sharedUserDefault()->getStringForKey(version.c_str()).compare(versionStr) == 0)
        {
            CCUserDefault::sharedUserDefault()->setBoolForKey(needUpDate.c_str(),false);
            
            
            AppDelegate::loadingLabel->setString("");
            //setButtonEnabel(false);
            
            setUpUpDateLabel(CCPointMake(130, 570),CCPointMake(900, 570),CCUserDefault::sharedUserDefault()->getStringForKey(time.c_str()),CCUserDefault::sharedUserDefault()->getBoolForKey(needUpDate.c_str()));
            
            
            return;
        }
        else
        {
            CCUserDefault::sharedUserDefault()->setBoolForKey(needUpDate.c_str(),true);
            CCUserDefault::sharedUserDefault()->setStringForKey(newVersion.c_str(), root_Version->valuestring);
        }
	}
    
    Json* root_time=Json_getItem(root,"time");
    if (root_time)
	{
        CCUserDefault::sharedUserDefault()->setStringForKey(time.c_str(), root_time->valuestring);
	}
    
    setUpUpDateLabel(CCPointMake(130, 570),CCPointMake(900, 570),CCUserDefault::sharedUserDefault()->getStringForKey(time.c_str()),CCUserDefault::sharedUserDefault()->getBoolForKey(needUpDate.c_str()));
    //setButtonEnabel(true);
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    
	//picture and title
	Json* root_smallpicture=Json_getItem(root,"video");
	if (root_smallpicture && root_smallpicture->type==Json_Array)
	{
		Json* json_child=root_smallpicture->child;
        map<string, string> valueMap;
        showPicMap.clear();
        showBigPicMap.clear();
        int i = 0;//smal image
        int k = 0;
        int j = 0;//big image
		while(json_child)
		{
			Json* child_pic_url=Json_getItem(json_child,"img");
            Json* child_video_url=Json_getItem(json_child,"video_url");
            
            if (i==0) {
                
                //self
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollBigPic%d.png",AppDelegate::S1NaviSelected,j+1);
                        string picNameStr(szsamllpicname);
                        showBigPicMap[PersonalApi::convertIntToString(j+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(j+1)] = valueStr;
                    }
                    j++;
                }
                
            }else if (i==1) {
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                }
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                }
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                }
                
            }else if (i==3) {
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                    
                }
                
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                    
                }
                
                //self
                {
                    if (child_pic_url)
                    {
                        char szsamllpicname[512]={0};
                        sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                        string picNameStr(szsamllpicname);
                        showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                        DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                        
                        string valueStr = child_video_url->valuestring;
                        valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    }
                    k++;
                }
                
                
            }else{
                if(child_pic_url){
                    char szsamllpicname[512]={0};
                    sprintf(szsamllpicname, "S%d5ScrollPic%d.png",AppDelegate::S1NaviSelected,k+1);
                    string picNameStr(szsamllpicname);
                    showPicMap[PersonalApi::convertIntToString(k+1)] = picNameStr;
                    DownLoadFile(child_pic_url->valuestring,szsamllpicname);
                    
                    string valueStr = child_video_url->valuestring;
                    valueMap[PersonalApi::convertIntToString(k+1)] = valueStr;
                    
                }
                k++;
            }
            
            i++;
			json_child=json_child->next;
		}
        
        string str1 = "S"+PersonalApi::convertIntToString(AppDelegate::S1NaviSelected) +"5scrollPic";
        string str2 = "S"+PersonalApi::convertIntToString(AppDelegate::S1NaviSelected) +"5VideoIntro";
        
        PersonalApi::wirteVecToXml(showPicMap,str1);
        PersonalApi::wirteVecToXml(valueMap,str2);
        
	}
    
    checkPicDownLoading();
}
Exemplo n.º 7
0
CCPoint getCenter(CCNode *node) {
	CCRect frame = getFrame(node);
	return CCPointMake(frame.origin.x + frame.size.width * 0.5, frame.origin.y + frame.size.height * 0.5);
}
Exemplo n.º 8
0
//------------------------------------------------------------------
//
// CameraCenterTest
//
//------------------------------------------------------------------
CameraCenterTest::CameraCenterTest()
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();
			
	CCSprite *sprite;
	CCOrbitCamera *orbit;
	
	// LEFT-TOP
	sprite = new CCSprite();//::node();
    sprite->init();
	addChild( sprite, 0);
	sprite->setPosition(CCPointMake(s.width/5*1, s.height/5*1));
	sprite->setColor(ccRED);
	sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
	orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
	sprite->runAction(CCRepeatForever::actionWithAction( orbit ));
    sprite->release();
//		[sprite setAnchorPoint: CCPointMake(0,1));

	
	
	// LEFT-BOTTOM
	sprite = new CCSprite();//::node();
    sprite->init();
	addChild( sprite, 0, 40);
	sprite->setPosition(CCPointMake(s.width/5*1, s.height/5*4));
	sprite->setColor(ccBLUE);
	sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
	orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
	sprite->runAction(CCRepeatForever::actionWithAction( orbit ));
    sprite->release();
    //		[sprite setAnchorPoint: CCPointMake(0,0));


	// RIGHT-TOP
	sprite = new CCSprite();//::node();
    sprite->init();
	addChild( sprite, 0);	
	sprite->setPosition(CCPointMake(s.width/5*4, s.height/5*1));
	sprite->setColor(ccYELLOW);
	sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
	orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
	sprite->runAction(CCRepeatForever::actionWithAction( orbit) );
    sprite->release();
//		[sprite setAnchorPoint: CCPointMake(1,1));

	
	// RIGHT-BOTTOM
	sprite = new CCSprite();//::node();
    sprite->init();
	addChild( sprite, 0, 40);
	sprite->setPosition(CCPointMake(s.width/5*4, s.height/5*4));
	sprite->setColor(ccGREEN);
	sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
	orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
	sprite->runAction( CCRepeatForever::actionWithAction( orbit ) );
    sprite->release();
//		[sprite setAnchorPoint: CCPointMake(1,0));

	// CENTER
	sprite = new CCSprite();
    sprite->init();
	addChild( sprite, 0, 40);
	sprite->setPosition(CCPointMake(s.width/2, s.height/2));
	sprite->setColor(ccWHITE);
	sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
	orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
	sprite->runAction(CCRepeatForever::actionWithAction( orbit ) );
    sprite->release();
//		[sprite setAnchorPoint: CCPointMake(0.5f, 0.5f));
}
Exemplo n.º 9
0
bool PanelLayer::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(! CCLayer::init());
		CCSize winSize = CCDirector::sharedDirector()->getWinSize();
		
		// Settting and pause (Right Top)
		CCMenuItemImage* setting = CCMenuItemImage::create(
			STATIC_DATA_STRING("setting_normal"),
			STATIC_DATA_STRING("setting_selected"),
			this,
			menu_selector(PanelLayer::setting));
		CC_BREAK_IF( !setting );
		
		CCMenuItemImage* pause = CCMenuItemImage::create(
			STATIC_DATA_STRING("pause_normal"),
			STATIC_DATA_STRING("pause_selected"),
			this,
			menu_selector(PanelLayer::pause));
		CC_BREAK_IF( !pause );

		CCSize settingSize = setting->getContentSize();
		CCSize pauseSize = pause->getContentSize();

		CCMenu* menu = CCMenu::create(setting, pause, NULL);
		CC_BREAK_IF( !menu );
		this->addChild(menu, 1, MENUTAG);

		menu->setPosition(CCPointMake(winSize.width-pauseSize.width * 3 / 2, winSize.height-pauseSize.height * 3 /4));
		menu->alignItemsHorizontallyWithPadding(pauseSize.width / 3);

		// energy bar (Left Top)
		energyBar = ProgressBar::create();
		CC_BREAK_IF( !energyBar );
		CCSize barSize = energyBar->getContentSize();
		energyBar->setPosition(ccp(barSize.width*0.52, winSize.height-barSize.height*0.58));
		this->addChild(energyBar);

		// energy button(Left Top)
		eneygyButtonNormal = CCMenuItemImage::create(
			STATIC_DATA_STRING("ultimateButton_normal"),
			STATIC_DATA_STRING("ultimateButton_normal"),
			this,
			menu_selector(PanelLayer::useUltimate));
		eneygyButtonFull = CCMenuItemImage::create(
			STATIC_DATA_STRING("ultimateButton_selected"),
			STATIC_DATA_STRING("ultimateButton_selected"),
			this,
			menu_selector(PanelLayer::useUltimate));
		menuUltimate = CCMenu::create(eneygyButtonNormal, eneygyButtonFull, NULL);
		eneygyButtonFull->setVisible(false);
		this->addChild(menuUltimate);
		CCSize ultiSize = eneygyButtonNormal->getContentSize();
		menuUltimate->setPosition(ccp(ultiSize.width*0.6, winSize.height-ultiSize.height*0.58));


		// Pro
		propLeft = CCMenuItemImage::create(
			STATIC_DATA_STRING("prop_nothing"),
			STATIC_DATA_STRING("prop_nothing"),
			this,
			menu_selector(PanelLayer::useLeftPro));
		propLeft->setTag(LEFT);
		Prop* prop = Prop::create(No_Prop);
		this->setLeftProp(prop);

		propRight = CCMenuItemImage::create(
			STATIC_DATA_STRING("prop_nothing"),
			STATIC_DATA_STRING("prop_nothing"),
			this,
			menu_selector(PanelLayer::useRightPro));
		propRight->setTag(RIGHT);

		Prop* prop2 = Prop::create(No_Prop);
		this->setRightProp(prop2);


		menuProp = CCMenu::create(propLeft, propRight, NULL);
		this->addChild(menuProp);
		CCSize proSize = propLeft->getContentSize();
		menuProp->setPosition(CCPointMake(proSize.width * 3 / 2, proSize.height * 0.618));
		menuProp->alignItemsHorizontallyWithPadding(proSize.width / 3);
		leftPlaced = rightPlaced = false;
		bRet = true;
	} while (0);

	return bRet;
}
Exemplo n.º 10
0
//------------------------------------------------------------------
//
// MenuLayer1
//
//------------------------------------------------------------------
MenuLayer1::MenuLayer1()
{
	CCMenuItemFont::setFontSize( 30 );
	CCMenuItemFont::setFontName("Courier New");

    setIsTouchEnabled(true);
	// Font Item
	
	CCSprite* spriteNormal = CCSprite::spriteWithFile(s_MenuItem, CCRectMake(0,23*2,115,23));
	CCSprite* spriteSelected = CCSprite::spriteWithFile(s_MenuItem, CCRectMake(0,23*1,115,23));
	CCSprite* spriteDisabled = CCSprite::spriteWithFile(s_MenuItem, CCRectMake(0,23*0,115,23));
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteNormal);
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteSelected);
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteDisabled);

	CCMenuItemSprite* item1 = CCMenuItemSprite::itemFromNormalSprite(spriteNormal, spriteSelected, spriteDisabled, this, menu_selector(MenuLayer1::menuCallback) );
	
	// Image Item
	CCMenuItem* item2 = CCMenuItemImage::itemFromNormalImage(s_SendScore, s_PressSendScore, this, menu_selector(MenuLayer1::menuCallback2) );

	// Label Item (LabelAtlas)
	CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0123456789", "fonts/fps_images.png", 16, 24, '.');
	CCMenuItemLabel* item3 = CCMenuItemLabel::itemWithLabel(labelAtlas, this, menu_selector(MenuLayer1::menuCallbackDisabled) );
	item3->setDisabledColor( ccc3(32,32,64) );
	item3->setColor( ccc3(200,200,255) );
	
	// Font Item
	CCMenuItemFont *item4 = CCMenuItemFont::itemFromString("I toggle enable items", this, menu_selector(MenuLayer1::menuCallbackEnable) );

	item4->setFontSizeObj(20);
	item4->setFontName("Marker Felt");
	
	// Label Item (CCLabelBMFont)
	CCLabelBMFont* label = CCLabelBMFont::labelWithString("configuration", "fonts/bitmapFontTest3.fnt");
	CCMenuItemLabel* item5 = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(MenuLayer1::menuCallbackConfig));

	// Testing issue #500
	item5->setScale( 0.8f );

	// Font Item
	CCMenuItemFont* item6 = CCMenuItemFont::itemFromString("Quit", this, menu_selector(MenuLayer1::onQuit));
	
	CCActionInterval* color_action = CCTintBy::actionWithDuration(0.5f, 0, -255, -255);
	CCActionInterval* color_back = color_action->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(color_action, color_back, NULL);
	item6->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq));

	CCMenu* menu = CCMenu::menuWithItems( item1, item2, item3, item4, item5, item6, NULL);
	menu->alignItemsVertically();
	
	
	// elastic effect
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	
	int i=0;
	CCNode* child;
	CCArray * pArray = menu->getChildren();
    CCObject* pObject = NULL;
    CCARRAY_FOREACH(pArray, pObject)
	{
		if(pObject == NULL)
			break;

		child = (CCNode*)pObject;

		CCPoint dstPoint = child->getPosition();
		int offset = (int) (s.width/2 + 50);
		if( i % 2 == 0)
			offset = -offset;
		
		child->setPosition( CCPointMake( dstPoint.x + offset, dstPoint.y) );
		child->runAction( 
							CCEaseElasticOut::actionWithAction(
																CCMoveBy::actionWithDuration(2, CCPointMake(dstPoint.x - offset,0)), 0.35f
															) 
						);
		i++;
	}

	m_disabledItem = item3; item3->retain();
	m_disabledItem->setIsEnabled( false );

	addChild(menu);

}
Exemplo n.º 11
0
	void ScutCxListItem::draw(void)
	{
		//mark es2.0
		//判断是否超出范围,如果超出,那么不进行绘画
		if (this->getParent())
		{
			if (this->getPosition().y + this->getParent()->getPosition().y > this->getParent()->getContentSize().height || this->getPosition().y + this->getParent()->getPosition().y + this->getContentSize().height < 0)
			{
				return;
			}
		}

		updateColor();      

		CCSize size = getContentSize();
		if (selected_)
		{
			if(draw_selected)
			{
				CC_NODE_DRAW_SETUP();

				ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );

				ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position |  kCCVertexAttribFlag_Color);

				// vertex
				glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, (void*)m_pSquareVertices);

				// color
				glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_TRUE, 0, (void*)m_pSquareColors);

				glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

				CHECK_GL_ERROR_DEBUG();

				CC_INCREMENT_GL_DRAWS(1);
			}
		}
		else
		{
			CCLayerColor::draw();
		}

		//glDisable(GL_LINE_SMOOTH);


		if (draw_top_line_)
		{
			glLineWidth(1.0f);
			cocos2d::ccDrawColor4F(line_color_.r, line_color_.g, line_color_.b, 0xFF);
			ccDrawLine(CCPointMake(0, size.height-0.5f), CCPointMake(size.width, size.height-0.5f));
		}

		if (draw_bottom_line_)
		{
			glLineWidth(1.0f);
			cocos2d::ccDrawColor4F(line_color_.r, line_color_.g, line_color_.b, 0xFF);
			ccDrawLine(CCPointMake(0, 0.5f), CCPointMake(size.width, 0.5f));
		}

	}
Exemplo n.º 12
0
void OrgRankList::showCntryDgRank()
{
    char buf[100];
    
    CCMutableArray<CCntryDgRankInfo* > * pRandLst = CGameData::Inst()->getCntryDgRankInfArr();
    int iItemCnt = pRandLst->count();

    CUserInfo* pUsrInf = CGameData::Inst()->getUsrInfo();
    for (int i = 0; i < iItemCnt; i++) {
        CCntryDgRankInfo* pInf = pRandLst->getObjectAtIndex(i);
        
        bool bIsMe = (pInf->strUid.compare(pUsrInf->uid) == 0);
        
        snprintf(buf, 99, "%d", i+1);
        CCLabelTTF* text = CCLabelTTF::labelWithString(buf, "STHeitiSC-Medium", 20);
        text->setPositionInPixels(CCPointMake(30, 296 - i * 22));
        text->setAnchorPoint(ccp(0, 0.5));
        if(bIsMe)
            text->setColor(ccc3(249, 196, 15));
        else
            text->setColor(ccc3(255, 255, 255));
        addChild(text);
        
        text = CCLabelTTF::labelWithString(pInf->strName.c_str(), "STHeitiSC-Medium", 20);
        text->setPositionInPixels(CCPointMake(190, 296 - i * 22));
        text->setAnchorPoint(ccp(0, 0.5));
        if(bIsMe)
            text->setColor(ccc3(249, 196, 15));
        else
            text->setColor(ccc3(255, 255, 255));
        addChild(text);
        
        snprintf(buf, 99, "%ld", pInf->lDamage);
        text = CCLabelTTF::labelWithString(buf, "STHeitiSC-Medium", 20);
        text->setPositionInPixels(CCPointMake(426, 296 - i * 22));
        text->setAnchorPoint(ccp(0, 0.5));
        if(bIsMe)
            text->setColor(ccc3(249, 196, 15));
        else
            text->setColor(ccc3(255, 255, 255));
        addChild(text);
    }
    
    
    string lastKillName = CGameData::Inst()->getCntryBossLastKillName();
    if (!lastKillName.empty())
    {
        CCLabelTTF* text1 = CCLabelTTF::labelWithString(lastKillName.c_str(), "STHeitiSC-Medium", 20);
        text1->setPositionInPixels(CCPointMake(30, 296 - iItemCnt * 22 - 10));
        text1->setAnchorPoint(ccp(0, 0.5));
        addChild(text1);
        text1->setColor(ccRED);
        CCLabelTTF* text2 = CCLabelTTF::labelWithString(CGameData::Inst()->getLanguageValue("orgft_last_kill"), "STHeitiSC-Medium", 20);
        text2->setPositionInPixels(CCPointMake(30 + text1->getContentSize().width + 6, text1->getPosition().y));
        text2->setAnchorPoint(ccp(0, 0.5));
        addChild(text2);
        
        iItemCnt += 2;
    }
    
    
    if (iItemCnt > 6) {
        m_fLimitY = (iItemCnt - 7) * 22 + 10;
        m_fBarBgPosY = 304;
        
        m_spScrollBg = CCSprite::spriteWithFile("rankscrollbg.png");
        if (m_spScrollBg) {
            addChild(m_spScrollBg);
            m_spScrollBg->setAnchorPoint(ccp(0, 1));
            m_spScrollBg->setPositionInPixels(ccp(600, m_fBarBgPosY));
            m_spScrollBg->setScaleY(0.72);
            
            m_spScrollBar = CCSprite::spriteWithFile("rankscrollbar.png");
            if (m_spScrollBar) {
                m_spScrollBg->addChild(m_spScrollBar);
                m_spScrollBar->setAnchorPoint(ccp(0, 1));
                m_spScrollBar->setPositionInPixels(ccp(5, m_fBarPos0));
            }
        }
    }
    else{
        m_fLimitY = 0;
    }
}
Exemplo n.º 13
0
void OrgRankList::showSpecialDgRank(string dgType)
{
    float fPosY = 30.0;
    char buf[100];
    
    CCMutableArray<CSpecialDgRankInfo* > * pRandLst = CGameData::Inst()->getSpecialDgRankInfArr(dgType);
    int iItemCnt = pRandLst->count();
            
    
    
    int myRank = CGameData::Inst()->getMySpecialDgRank(dgType);
    bool bAddMyRank = false;
    if (myRank > iItemCnt)
    {
        iItemCnt++;
        bAddMyRank = true;
    }
    CCountryInfo* pCntryInfo = CGameData::Inst()->getCntryInfo();
    for (int i = 0; i < iItemCnt; i++) {
        CSpecialDgRankInfo* pInf = NULL;
        if (bAddMyRank && i == iItemCnt - 1) {
            snprintf(buf, 99, "%d", myRank);
            pInf = CGameData::Inst()->getMySpecialDgRankInf(dgType);
        }
        else
        {
            snprintf(buf, 99, "%d", i+1);
            pInf = pRandLst->getObjectAtIndex(i);
        }
        
        bool bIsMe = (pInf->strCid.compare(pCntryInfo->cid) == 0);
        
        CCLabelTTF* text = CCLabelTTF::labelWithString(buf, "STHeitiSC-Medium", 20);
        text->setPositionInPixels(CCPointMake(30, 296 - fPosY - i * 22));
        text->setAnchorPoint(ccp(0, 0.5));
        if(bIsMe)
            text->setColor(ccc3(249, 196, 15));
        else
            text->setColor(ccc3(255, 255, 255));
        addChild(text);
        
        text = CCLabelTTF::labelWithString(pInf->strName.c_str(), "STHeitiSC-Medium", 20);
        text->setPositionInPixels(CCPointMake(190, 296 - fPosY - i * 22));
        text->setAnchorPoint(ccp(0, 0.5));
        if(bIsMe)
            text->setColor(ccc3(249, 196, 15));
        else
            text->setColor(ccc3(255, 255, 255));
        addChild(text);
        
        text = CCLabelTTF::labelWithString(pInf->strTime.c_str(), "STHeitiSC-Medium", 20);
        text->setPositionInPixels(CCPointMake(426, 296 - fPosY - i * 22));
        text->setAnchorPoint(ccp(0, 0.5));
        if(bIsMe)
            text->setColor(ccc3(249, 196, 15));
        else
            text->setColor(ccc3(255, 255, 255));
        addChild(text);
    }
        
    if (iItemCnt > 5) {
        m_fLimitY = (iItemCnt - 6) * 22 + 16;
        m_fBarBgPosY = 276;
        
        m_spScrollBg = CCSprite::spriteWithFile("rankscrollbg.png");
        if (m_spScrollBg) {
            addChild(m_spScrollBg);
            m_spScrollBg->setAnchorPoint(ccp(0, 1));
            m_spScrollBg->setPositionInPixels(ccp(600, m_fBarBgPosY));
            m_spScrollBg->setScaleY(0.58);
            
            m_spScrollBar = CCSprite::spriteWithFile("rankscrollbar.png");
            if (m_spScrollBar) {
                m_spScrollBg->addChild(m_spScrollBar);
                m_spScrollBar->setAnchorPoint(ccp(0, 1));
                m_spScrollBar->setPositionInPixels(ccp(5, m_fBarPos0));
            }
        }
    }
    else{
        m_fLimitY = 0;
    }
}
Exemplo n.º 14
0
bool CCPreLoad::cacheFramesForPlist(const char* plist, const char* textureFileName)
{
	bool ret = false;
	do{
		//private权限不好继承,直接挑出来改,Zwoptex.swf 1.0的version
		CCTexture2D *pobTexture = CCTextureCache::sharedTextureCache()->addImage(textureFileName);
		if(pobTexture == NULL)
			break;

		string pszPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist);
		CCDictionary *dictionary = CCDictionary::createWithContentsOfFileThreadSafe(pszPath.c_str());

		CCDictionary *framesDict = (CCDictionary*)dictionary->objectForKey("frames");
		int format = 0;

		CCDictElement* pElement = NULL;
		CCDICT_FOREACH(framesDict, pElement)
		{
			CCDictionary* frameDict = (CCDictionary*)pElement->getObject();
			std::string spriteFrameName = pElement->getStrKey();
			CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrameName.c_str());
			if (spriteFrame)
			{
				continue;
			}
		    
			int format = 0;//就只挑这个
			if(format == 0) 
			{
				float x = frameDict->valueForKey("x")->floatValue();
				float y = frameDict->valueForKey("y")->floatValue();
				float w = frameDict->valueForKey("width")->floatValue();
				float h = frameDict->valueForKey("height")->floatValue();
				float ox = frameDict->valueForKey("offsetX")->floatValue();
				float oy = frameDict->valueForKey("offsetY")->floatValue();
				int ow = frameDict->valueForKey("originalWidth")->intValue();
				int oh = frameDict->valueForKey("originalHeight")->intValue();
				// check ow/oh
				if(!ow || !oh)
				{
					CCLOGWARN("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
				}
				// abs ow/oh
				ow = abs(ow);
				oh = abs(oh);
				// create frame
				spriteFrame = new CCSpriteFrame();
				spriteFrame->initWithTexture(pobTexture, 
											CCRectMake(x, y, w, h), 
											false,
											CCPointMake(ox, oy),
											CCSizeMake((float)ow, (float)oh)
											);
			} 

			// add sprite frame
			CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(spriteFrame, spriteFrameName.c_str());
			m_tmpFrames.insert(make_pair(spriteFrameName,spriteFrame));
			spriteFrame->release();
		}
		dictionary->release();
		ret = true;
	}while(0);
Exemplo n.º 15
0
void CArmySprite::createSprite(ARMY_KINDS eKind)
{
	//std::string tString = CGlobalData::getSingleton()->getNameByEnum(eKind);
	mScreenSize = CCDirector::sharedDirector()->getWinSize();
	m_sCurData = CGlobalData::getSingleton()->getDataByKind(eKind);
	m_pCurCache = CCSpriteFrameCache::sharedSpriteFrameCache();
	char szName[128] = {0};
	//sprintf(szName, "%s%02d_01.png", "Plane", m_sCurData);NPC_Tank01_01
	

	setContentSize(CCSizeMake(98,176));

	if (CCRANDOM_0_1() > 0.5f && m_sCurData.mKind == AK_DEFAULT || m_sCurData.mKind == AK_MISSILEARMY)
	{
		m_bIsHorizontal = true;
	}

	sprintf(szName, "%s%02d_%02d.png", "NPC_Tank", m_sCurData.mIndex, 1);
	if (m_bIsHorizontal)
	{
		sprintf(szName, "%s%02d_%02d.png", "NPC_Tank", m_sCurData.mIndex, 2);
	}
	if (m_pCurCache->spriteFrameByName(szName) == NULL)
	{
		return ;
	}
	m_pBaseSprite = CCSprite::createWithSpriteFrame(m_pCurCache->spriteFrameByName(szName));
	m_pBaseSprite->setPosition(ccp(getContentSize().width * 0.5f, getContentSize().height * 0.5f));
	addChild(m_pBaseSprite);

	sprintf(szName, "%s%02d_%02d.png", "NPC_Tank", m_sCurData.mIndex, 3);
	if (m_pCurCache->spriteFrameByName(szName) == NULL)
	{
		return ;
	}
	m_pTurretSprite = CCSprite::createWithSpriteFrame(m_pCurCache->spriteFrameByName(szName));

	//各地面武器偏移位置和基准大小
	CCPoint mBase = CCPointMake(0,0);
	CCPoint mOffset = CCPointMake(0,0);
	switch(eKind)
	{
	case AK_DEFAULT:
		mBase = ccp(0.5f, 0.4f);
		mOffset = ccp(0.5f, 0.75f);
		break;
	case AK_MISSILEARMY:
		mBase = ccp(0.5f, 0.5f);
		mOffset = ccp(0.5f, 0.714f);
		break;
	case AK_GREENGUN01:
		mBase = ccp(0.75f, 0.7f);
		mOffset = ccp(0.5f, 0.78f);
		break;
	case AK_GREENGUN02:
		mBase = ccp(0.75f, 0.5f);
		mOffset = ccp(0.5f, 0.68f);
		break;
	case AK_BATTERY01:
		mBase = ccp(0.55f, 0.5f);
		mOffset = ccp(0.5f, 0.7f);
		break;
	case AK_BATTERY02:
		mBase = ccp(0.5f, 0.5f);
		mOffset = ccp(0.5f, 0.7f);
		break;
	case AK_BUNKER01:
		mBase = ccp(0.5f, 0.5f);
		mOffset = ccp(0.5f, 0.5f);
		break;
	case AK_BUNKER02:
		mBase = ccp(0.5f, 0.5f);
		mOffset = ccp(0.5f, 0.5f);
		break;
	}
	m_pTurretSprite->setAnchorPoint(mOffset);
	m_pTurretSprite->setPosition(ccp(m_pBaseSprite->getContentSize().width * mBase.x, m_pBaseSprite->getContentSize().height * mBase.y));
	m_pBaseSprite->addChild(m_pTurretSprite);

	sprintf(szName, "%s%02d_%02d.png", "NPC_Tank", m_sCurData.mIndex, 4);
	if (m_bIsHorizontal)
	{
		sprintf(szName, "%s%02d_%02d.png", "NPC_Tank", m_sCurData.mIndex, 5);
	}

	m_pWreckSprite = CCSprite::createWithSpriteFrame(m_pCurCache->spriteFrameByName(szName));
	m_pWreckSprite->setPosition(ccp(getContentSize().width * 0.5f, getContentSize().height * 0.5f));
	m_pWreckSprite->setVisible(false);
	addChild(m_pWreckSprite);

	

	m_pEffectSprite = CCSprite::create();
	m_pEffectSprite->setPosition(ccp(getContentSize().width * 0.5f, getContentSize().height * 0.5f));
	addChild(m_pEffectSprite);

	//create and mount weapon
	//m_pPlayerWeapon = CPlayerWeapon::createWeapon();
	//addChild(m_pPlayerWeapon);

	setPosition(m_sCurLandData.mPosition);
	setAnchorPoint(ccp(0.5f,0.5f));
	//setScale(0.282f);
	m_fFireTime = CCRANDOM_0_1() + 2.0f;
	m_eCurState = AS_MOVE;
	if (m_sCurData.mKind == AK_GREENGUN01 || m_sCurData.mKind == AK_GREENGUN02)
	{
		addCap();
		m_eCurState = AS_READY;
	}
	this->schedule(schedule_selector(CArmySprite::enemyUpdate));
}
Exemplo n.º 16
0
DeadDlg::DeadDlg(CCObject *listener,SEL_CallFuncO selector,int type)
{
   // CCLayerColor *layer = CCLayerColor::layerWithColor)
    m_listener = listener;
    m_selector = selector;
    
    m_backGround = CCSprite::spriteWithSpriteFrameName("fr_window2.png");
    m_backGround->setScale(2.0);
    addChild(m_backGround);
    m_backGround->setPosition(ccp(320, 500));
    
    CCSprite* spMenu1 = CCSprite::spriteWithSpriteFrameName("fr_button.png");
    CCSprite* spMenu2 = CCSprite::spriteWithSpriteFrameName("fr_button.png");
    sureItem = CCMenuItemImage::itemFromNormalSprite(spMenu1, spMenu2, this, menu_selector(DeadDlg::menuCallback)); 
    sureItem->setTag(111);
    sureItem->setPosition(ccp(88, 284));
    
    int need;
    long hold;
    if (CGameData::Inst()->chkLogin()) {
        need =  CGameData::Inst()->getCommonInfo()->revive_coin;
    }
    else {
        need = SaveData::Inst()->getReviveCoin();
    }
    
    if(CGameData::Inst()->getUsrInfo()->login_time > 0){
        hold =  CGameData::Inst()->getUsrInfo()->coin;
        SaveData::Inst()->setCurCoin(hold);
    }
    else{
        hold = SaveData::Inst()->getCurCoin();
    }
    char buf[100];
    if(type == enDeadType_normal)
    {
        if (hold<need) {
            strncpy(buf, CGameData::Inst()->getLanguageValue("shopTip14"), 99);
        }
        else
        {
            strncpy(buf, CGameData::Inst()->getLanguageValue("sureTip"), 99);
        }
    }
    else if(type == enDeadType_free)
    {
       strncpy(buf, CGameData::Inst()->getLanguageValue("sureTip"), 99);
    }
    
    
    TextNode *sureLabel = TextNode::textWithString(buf, 42);
    sureLabel->setColor(ccc3(255, 255, 255));
    sureLabel->setShadowColor(ccBLACK);
    sureLabel->setPosition(CCPointMake(spMenu1->getContentSize().width * 0.5 - 2,
                                       spMenu1->getContentSize().height * 0.5 + 2));
    sureItem->addChild(sureLabel);
    
    spMenu1 = CCSprite::spriteWithSpriteFrameName("fr_button.png");
    spMenu2 = CCSprite::spriteWithSpriteFrameName("fr_button.png");
    cancelItem = CCMenuItemImage::itemFromNormalSprite(spMenu1, spMenu2, this, menu_selector(DeadDlg::menuCallback)); 
    cancelItem->setTag(112);
    cancelItem->setPosition(ccp(394, 284));
    
    TextNode *cancelLabel = TextNode::textWithString(CGameData::Inst()->getLanguageValue("cancelTip"), 42);
    cancelLabel->setColor(ccc3(255, 255, 255));
    cancelLabel->setShadowColor(ccBLACK);
    cancelLabel->setPosition(CCPointMake(spMenu1->getContentSize().width * 0.5 - 2,
                                         spMenu1->getContentSize().height * 0.5 + 2));
    cancelItem->addChild(cancelLabel);
    
    sureItem->setAnchorPoint(ccp(0, 0));
    cancelItem->setAnchorPoint(ccp(0, 0));
    
    CCMenu *menu = CCMenu::menuWithItems(sureItem,cancelItem,NULL);
    menu->setPosition(ccp(0, 0));
    addChild(menu);
    
    TextNode *titleLabel = TextNode::textWithString(CGameData::Inst()->getLanguageValue("deadDlgtip1"), 55);
    titleLabel->setColor(ccc3(122, 37, 8));
    addChild(titleLabel);
    titleLabel->setPosition(ccp(320, 420+255));
    
    if(type == enDeadType_normal)
    {
        if (hold<need) {
            snprintf(buf, 99, "%s%d%s",CGameData::Inst()->getLanguageValue("deadDlgtip2"),need,CGameData::Inst()->getLanguageValue("deadDlgtip3"));
        }
        else
        {
            snprintf(buf, 99, "%s%d%s",CGameData::Inst()->getLanguageValue("deadDlgtip2"),need,CGameData::Inst()->getLanguageValue("deadDlgtip4"));
        }
        infoLabel = TextNode::textWithString(buf, CCSize(388, 70), CCTextAlignmentCenter, 30);
        infoLabel->setPosition(ccp(320, 300+255));
        infoLabel->setColor(ccc3(63, 23, 13));
        addChild(infoLabel);
    }
    else if(type == enDeadType_free)
    {
         snprintf(buf, 99,CGameData::Inst()->getLanguageValue("deadDlgtip7"),CGameData::Inst()->getCommonInfo()->free_revive_lv);
        infoLabel = TextNode::textWithString(buf, CCSize(388, 110), CCTextAlignmentCenter, 30);
        infoLabel->setPosition(ccp(320, 300+205));
        infoLabel->setColor(ccc3(63, 23, 13));
        addChild(infoLabel);
    }
    
    
   
    
    if(type == enDeadType_normal)
    {
        snprintf(buf, 99,"%s%ld%s!",CGameData::Inst()->getLanguageValue("deadDlgtip5"),hold,CGameData::Inst()->getLanguageValue("deadDlgtip6"));
        
        myYuanbaoLabel = TextNode::textWithString(buf, CCSize(388, 70), CCTextAlignmentCenter, 30);
        myYuanbaoLabel->setPosition(ccp(320, 190+255));
        myYuanbaoLabel->setColor(ccc3(63, 23, 13));
        addChild(myYuanbaoLabel);
    }
}
Exemplo n.º 17
0
CCTableViewCell* MailListScene::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
	CCString *string = (CCString *)mArrayList->objectAtIndex(idx);
    CCSize size = this->tableCellSizeForIndex(table, idx);
	CCTableViewCell *cell = table->dequeueCell();
	if (!cell) {
		cell = new CCTableViewCell();
		cell->autorelease();

		CCSprite *sState = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mail_state_read.png"));
		sState->setAnchorPoint(CCPointMake(0, 0.5));
		sState->setPosition(ccp(10,size.height * 0.5));
		sState->setTag(120);
		cell->addChild(sState);

		CCLabelTTF *lblName = CCLabelTTF::create(string->getCString(), "Arial", 14.0);
		lblName->setPosition(ccp(65,size.height * 0.5));
        lblName->setColor(ccc3(255, 255, 204));
        //lblName->enableStroke(ccc3(51, 0, 0), 0.6);
		lblName->setTag(121);
		lblName->setHorizontalAlignment(kCCTextAlignmentLeft);
        lblName->setString(string->getCString());
		cell->addChild(lblName);

		CCLabelTTF *lblSubject = CCLabelTTF::create("100", "Arial", 14.0);
		lblSubject->setPosition(ccp(130,size.height * 0.5));
        lblSubject->setColor(ccc3(255, 255, 204));
        //lblSubject->enableStroke(ccc3(51, 0, 0), 0.6);
        lblSubject->setTag(122);
        lblSubject->setString(string->getCString());
		cell->addChild(lblSubject);
        
        CCScale9Sprite *sline = CCScale9Sprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mail_line.png"));
        sline->setPreferredSize(CCSizeMake(310, 1));
        sline->setPosition(ccp(0,size.height-2));
        sline->setAnchorPoint(CCPointZero);
        cell->addChild(sline);
        
        CCMenu *menuCheck = this->generateCheckBox();
        cell->addChild(menuCheck);
        CCMenuItemToggle *toggle= (CCMenuItemToggle *)menuCheck->getChildByTag(1);
        toggle->setUserData(&vUserData[idx]);
		if (vUserData[idx] == 1) {
			toggle->setSelectedIndex(1);
		} else {
			toggle->setSelectedIndex(0);
		}

        menuCheck->setTag(123);
        menuCheck->setAnchorPoint(CCPointMake(0, 0.5));
        menuCheck->setPosition(CCPointMake(280, size.height * 0.5));
	}
	else
	{
		CCLabelTTF *lblName = (CCLabelTTF*)cell->getChildByTag(121);
		lblName->setString(string->getCString());
        
        CCLabelTTF *lblSubject = (CCLabelTTF*)cell->getChildByTag(122);
		lblSubject->setString(string->getCString());
        
        CCMenu *menuCheck = (CCMenu *)cell->getChildByTag(123);
        CCMenuItemToggle *toggle= (CCMenuItemToggle *)menuCheck->getChildByTag(1);
		toggle->setUserData(&vUserData[idx]);

        if (vUserData[idx] == 1) {
			toggle->setSelectedIndex(1);
        } else {
            toggle->setSelectedIndex(0);
        }
	}

	return cell;
}
Exemplo n.º 18
0
void LHParallaxNode::repositionPoint(LHParallaxPointObject* point, double frameTime)
{
    CCSize spriteContentSize = point->ccsprite->getContentSize();
    CCPoint spritePosition = point->ccsprite->getPosition();
    float angle = point->ccsprite->getRotation();
    float rotation = CC_DEGREES_TO_RADIANS(angle);
	float scaleX = point->ccsprite->getScaleX();
	float scaleY = point->ccsprite->getScaleY();
    
    CCSize contentSize = getBounds(spriteContentSize.width,
                                   spriteContentSize.height,
                                   rotation);
    
	switch (direction) {
		case 1: //right to left
		{
            if(spritePosition.x + contentSize.width/2.0f*scaleX <= 0)
                
                //			if(spritePosition.x + contentSize.width*scaleX <= 0)
			{
                if(NULL != point->ccsprite){
                    float difX = spritePosition.x;
                    
                    CCPoint newPos = CCPointMake(winSize.width*screenNumberOnTheRight + difX,
                                                 spritePosition.y);
                    
                    
                    if(point->isLHSprite)
                    {
                        ((LHSprite*)point->ccsprite)->transformPosition(newPos);
                    }
                    else {
                        point->ccsprite->setPosition(newPos);
                    }
                }
                
                
                if(NULL != movedEndListenerObj){
                    (movedEndListenerObj->*movedEndListenerSEL)(point->ccsprite);
                }
			}
		}
			break;
			
		case 0://left to right
		{
            if(spritePosition.x - contentSize.width/2.0f*scaleX >= winSize.width)
			{
				float difX = spritePosition.x - winSize.width;
				
                CCPoint newPos = CCPointMake(winSize.width*screenNumberOnTheLeft + difX,
                                             spritePosition.y);
                
                if(point->isLHSprite)
                {
                    ((LHSprite*)point->ccsprite)->transformPosition(newPos);
                }
                else {
                    point->ccsprite->setPosition(newPos);
                }
                
                if(NULL != movedEndListenerObj){
                    (movedEndListenerObj->*movedEndListenerSEL)(point->ccsprite);
                }
			}
		}
			break;
			
		case 2://up to bottom
		{
            if(spritePosition.y + contentSize.height/2.0f*scaleY <= 0)
                //			if(spritePosition.y + contentSize.height*scaleY <= 0)
			{
				float difY = spritePosition.y;
				
                CCPoint newPos = CCPointMake(spritePosition.x,
                                             winSize.height*screenNumberOnTheTop +difY);
                
                
                if(point->isLHSprite)
                {
                    ((LHSprite*)point->ccsprite)->transformPosition(newPos);
                }
                else {
                    point->ccsprite->setPosition(newPos);
                }
                
                if(NULL != movedEndListenerObj){
                    (movedEndListenerObj->*movedEndListenerSEL)(point->ccsprite);
                }
			}
		}
			break;
			
		case 3://bottom to top
		{
            if(spritePosition.y - contentSize.height/2.0f*scaleY >= winSize.height)
                //			if(spritePosition.y - contentSize.height*scaleY >= winSize.height)
			{
				float difY = spritePosition.y - winSize.height;
                
                CCPoint newPos = CCPointMake(spritePosition.x,
                                             winSize.height*screenNumberOnTheBottom + difY);
                
                if(point->isLHSprite)
                {
                    ((LHSprite*)point->ccsprite)->transformPosition(newPos);
                }
                else {
                    point->ccsprite->setPosition(newPos);
                }
                
                if(NULL != movedEndListenerObj){
                    (movedEndListenerObj->*movedEndListenerSEL)(point->ccsprite);
                }
			}
		}
			break;
		default:
			break;
	}
}
Exemplo n.º 19
0
bool NDPlayer::ClickPoint(CCPoint point, bool bLongTouch, bool bPath/*=true*/)
{
//	CCLog( "NDPlayer::ClickPoint(%d, %d), @0\r\n", (int)point.x, (int)point.y );

	if (AutoPathTipObj.IsWorking())
	{
		AutoPathTipObj.Stop();
	}
	
	if (ScriptMgrObj.excuteLuaFunc("CloseMainUI", ""))
	{
		//this->stopMoving();
		//return false;
	}
	
	if (bLongTouch && bPath)
	{
		//长按不执行其它操作
//		CCLog( "NDPlayer::ClickPoint(%d, %d), @1\r\n", (int)point.x, (int)point.y );
//		WriteCon( "NDPlayer::ClickPoint(%d, %d), @1\r\n", (int)point.x, (int)point.y );
		NDPlayer::defaultHero().Walk(point, SpriteSpeedStep8);
		return true;
	}
	
	bool bNpcPath = false;

	NDScene* pkRunningScene = NDDirector::DefaultDirector()->GetRunningScene();
	if (pkRunningScene->IsKindOfClass(RUNTIME_CLASS(CSMGameScene)))
	{
		//CSMGameScene* gameScene = (CSMGameScene*)pkRunningScene;
		if (!NDUISynLayer::IsShown())// && !gameScene->IsUIShow())
		{
			do {

				bool bDealed = false;
				// 1.先处理npc
				NDMapMgr::VEC_NPC& npclist = NDMapMgrObj.m_vNPC;
				for (NDMapMgr::vec_npc_it it = npclist.begin(); it != npclist.end(); it++) 
				{
					NDNpc* npc = *it;

					if (npc && npc->IsPointInside(point))
					{
						int dis = NDMapMgrObj.getDistBetweenRole(this, npc);

						CCPoint pos;

						if ( dis < FOCUS_JUDGE_DISTANCE )
						{
							//TestDrama();//@del
							SendNpcInteractionMessage(npc->m_nID);
							return false;
						}
						else if (npc->getNearestPoint(this->GetPosition(), pos))
						{
							point = ccpAdd(pos, CCPointMake(0, 30));

							AutoPathTipObj.work(npc->GetName());
							bDealed = true;
							bNpcPath = true;
							break;

						}
					}
				}

				if (bDealed)
				{
					break;
				}

								/*
				// 2.再处理角色
				//other role
				if ( m_iFocusManuRoleID != -1 )
				{
					NDManualRole *otherplayer = NDMapMgrObj.GetManualRole(m_iFocusManuRoleID);
					if (otherplayer && cocos2d::CCRect::CCRectContainsPoint(otherplayer->GetFocusRect(), point)) 
					{
						if ( otherplayer->IsInState(USERSTATE_BOOTH) )
						{ //与其摆摊玩家交互
							NDUISynLayer::Show();
							VendorBuyUILayer::s_idVendor = otherplayer->m_id;
							
							NDTransData bao(_MSG_BOOTH);
							bao << Byte(BOOTH_QUEST) << otherplayer->m_id << int(0);
							// SEND_DATA(bao);
						}
						
						QuickInteraction::RefreshOptions();
						
						return false;
					}
				}
				else
				{
					NDMapMgr::map_manualrole& roles = NDMapMgrObj.GetManualRoles();
					
					bool find = false;
					for (NDMapMgr::map_manualrole_it it = roles.begin(); it != roles.end(); it++) 
					{
						NDManualRole* role = it->second;
						
						if (role->bClear) continue;
						
						if ( !cocos2d::CCRect::CCRectContainsPoint(role->GetFocusRect(), point)) continue;
						
						find = true;
						
						SetFocusRole(role);
						
						return false;
					}
				}
				*/

				//** chh 2012-08-27 **//
				if ( m_iFocusManuRoleID == -1 )
				{
					NDMapMgr::map_manualrole& roles = NDMapMgrObj.GetManualRoles();

					bool find = false;
					for (NDMapMgr::map_manualrole_it it = roles.begin(); it != roles.end(); it++) 
					{
						NDManualRole* role = it->second;

						if (role->m_bClear) continue;

						if ( !cocos2d::CCRect::CCRectContainsPoint(role->GetFocusRect(), point)) continue;

						//find = true;

						SetFocusRole(role);

						//return false;
					}
				}

// 				NDManualRole *otherplayer = NDMapMgrObj.GetManualRole(m_iFocusManuRoleID);
// 				if (otherplayer && cocos2d::CCRect::CCRectContainsPoint(otherplayer->GetFocusRect(), point)) 
// 				{
// 					if ( otherplayer->IsInState(USERSTATE_BOOTH) )
// 					{ //与其摆摊玩家交互
// 						NDUISynLayer::Show();
// 						VendorBuyUILayer::s_idVendor = otherplayer->m_nID;
// 
// 						NDTransData bao(_MSG_BOOTH);
// 						bao << Byte(BOOTH_QUEST) << otherplayer->m_nID << int(0);
// 						SEND_DATA(bao);
// 					}
// 
// 					ScriptGlobalEvent::OnEvent(GE_CLICK_OTHERPLAYER,otherplayer->m_nID);
// 					//QuickInteraction::RefreshOptions();
// 
// 					//return false;
// 				}

			}while(0);
		}//if
	}//if
 		
	if (bPath || bNpcPath)
	{
//		CCLog( "NDPlayer::ClickPoint(%d, %d), @2\r\n", (int)point.x, (int)point.y );
//		WriteCon( "NDPlayer::ClickPoint(%d, %d), @2\r\n", (int)point.x, (int)point.y );
		NDPlayer::defaultHero().Walk(point, SpriteSpeedStep8);
	}

	if (m_kPointList.empty())
	{
		NDMapLayer* layer = M_GetMapLayer();
		if (layer)
		{
			layer->ShowRoadSign(false);
		}

		return false;
	}

	return true;
}
Exemplo n.º 20
0
////////////////////////////////////////////////////////////////////////////////
//void LHParallaxNode::visit(void)
void LHParallaxNode::tick(float dt)
{
    
    if(LHSettings::sharedInstance()->levelPaused() || paused) //level is paused
    {
        return;
    }
    
    if(NULL != followedSprite)
    {
        CCPoint spritePos = followedSprite->getPosition();
        float deltaFX = lastFollowedSpritePosition.x - spritePos.x;
        float deltaFY = lastFollowedSpritePosition.y - spritePos.y;
        lastFollowedSpritePosition = spritePos;
        
        CCPoint lastNodePosition = getPosition();
        if(followChangeX && !followChangeY){
            setPosition(ccp(lastNodePosition.x + deltaFX,
                            lastNodePosition.y));
        }
        else if(!followChangeX && followChangeY){
            setPosition(ccp(lastNodePosition.x,
                            lastNodePosition.y + deltaFY));
        }
        else if(followChangeX && followChangeY){
            setPosition(ccp(lastNodePosition.x + deltaFX,
                            lastNodePosition.y + deltaFY));
        }
    }
    
    double i = -1.0f; //direction left to right //bottom to up
	CCPoint pos = getPosition();
    
    CCPoint deltaPos = CCPointMake(pos.x - lastPosition.x,
                                   pos.y - lastPosition.y);
    
	if(isContinuous || ! (pos.x == lastPosition.x && pos.y == lastPosition.y))
	{
        float   frameTime = dt;//[[NSDate date] timeIntervalSince1970] - time;
        
        for(int j = 0; j< sprites->count(); ++j){
            LHParallaxPointObject* point = (LHParallaxPointObject*)sprites->objectAtIndex(j);
        
		    i = -1.0f; //direction left to right //bottom to up
            if(direction == 1 || direction == 2) //right to left //up to bottom
                i = 1.0f;
            
            LHSprite* spr = (LHSprite*)point->ccsprite;
            CCPoint oldPos = spr->getPosition();
            
            
            if(isContinuous)
            {
                spr->transformPosition(CCPointMake((float)(oldPos.x - i*point->ratio.x*speed*frameTime),
                                                   (float)(oldPos.y - i*point->ratio.y*speed*frameTime)));
                
                repositionPoint(point, frameTime);
            }
            else {
                
                spr->transformPosition(CCPointMake(oldPos.x + point->ratio.x*deltaPos.x/*2.0f*frameTime*/,
                                                   oldPos.y + point->ratio.y*deltaPos.y/*2.0f*frameTime*/));
                
                
            }
		}
	}
    lastPosition = pos;    
}
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)
{
	/*
	Supported Zwoptex Formats:

	ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
	ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
	ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
	ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
	*/

	CCDictionary<std::string, CCObject*> *metadataDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("metadata"));
	CCDictionary<std::string, CCObject*> *framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("frames"));
	int format = 0;

	// get the format
	if(metadataDict != NULL) 
	{
		format = atoi(valueForKey("format", metadataDict));
	}

	// check the format
	assert(format >=0 && format <= 3);

	framesDict->begin();
	std::string key = "";
	CCDictionary<std::string, CCObject*> *frameDict = NULL;
	while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
	{
		CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
		if (spriteFrame)
		{
			continue;
		}
		
		if(format == 0) 
		{
			float x = (float)atof(valueForKey("x", frameDict));
			float y = (float)atof(valueForKey("y", frameDict));
			float w = (float)atof(valueForKey("width", frameDict));
			float h = (float)atof(valueForKey("height", frameDict));
			float ox = (float)atof(valueForKey("offsetX", frameDict));
			float oy = (float)atof(valueForKey("offsetY", frameDict));
			int ow = atoi(valueForKey("originalWidth", frameDict));
			int oh = atoi(valueForKey("originalHeight", frameDict));
			// check ow/oh
			if(!ow || !oh)
			{
				CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
			}
			// abs ow/oh
			ow = abs(ow);
			oh = abs(oh);
			// create frame
			spriteFrame = new CCSpriteFrame();
			spriteFrame->initWithTexture(pobTexture, 
				                        CCRectMake(x, y, w, h), 
										false,
                                        CCPointMake(ox, oy),
                                        CCSizeMake((float)ow, (float)oh)
										);
		} 
		else if(format == 1 || format == 2) 
		{
			CCRect frame = CCRectFromString(valueForKey("frame", frameDict));
			bool rotated = false;

			// rotation
			if (format == 2)
			{
				rotated = atoi(valueForKey("rotated", frameDict)) == 0 ? false : true;
			}

			CCPoint offset = CCPointFromString(valueForKey("offset", frameDict));
			CCSize sourceSize = CCSizeFromString(valueForKey("sourceSize", frameDict));

			// create frame
			spriteFrame = new CCSpriteFrame();
			spriteFrame->initWithTexture(pobTexture, 
				frame,
				rotated,
				offset,
				sourceSize
				);
		} else
		if (format == 3)
		{
			// get values
			CCSize spriteSize = CCSizeFromString(valueForKey("spriteSize", frameDict));
			CCPoint spriteOffset = CCPointFromString(valueForKey("spriteOffset", frameDict));
			CCSize spriteSourceSize = CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
			CCRect textureRect = CCRectFromString(valueForKey("textureRect", frameDict));
            bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;

			// get aliases
			CCMutableArray<CCString*> *aliases = (CCMutableArray<CCString*> *) (frameDict->objectForKey(std::string("aliases")));
            CCMutableArray<CCString*>::CCMutableArrayIterator iter;

            CCString * frameKey = new CCString(key.c_str());
            for (iter = aliases->begin(); iter != aliases->end(); ++iter)
            {
                std::string oneAlias = ((CCString*) (*iter))->m_sString;
                if (m_pSpriteFramesAliases->objectForKey(oneAlias))
                {
                    CCLOG("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
                }

                m_pSpriteFramesAliases->setObject(frameKey, oneAlias);
            }
            frameKey->release();
            // create frame
            spriteFrame = new CCSpriteFrame();
            spriteFrame->initWithTexture(pobTexture,
                            CCRectMake(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
                            textureRotated,
                            spriteOffset,
                            spriteSourceSize);
		}

		// add sprite frame
		m_pSpriteFrames->setObject(spriteFrame, key);
		spriteFrame->release();
	}
}
Exemplo n.º 22
0
//------------------------------------------------------------------
//
// DemoRotFlower
//
//------------------------------------------------------------------
void DemoRotFlower::onEnter()
{
    ParticleDemo::onEnter();

    m_emitter = new CCParticleSystemQuad();
    m_emitter->initWithTotalParticles(300);
    //m_emitter->autorelease();

    m_background->addChild(m_emitter, 10);
    ////m_emitter->release();	// win32 : Remove this line
    m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars2) );

    // duration
    m_emitter->setDuration(-1);

    // gravity
    m_emitter->setGravity(CCPointZero);

    // angle
    m_emitter->setAngle(90);
    m_emitter->setAngleVar(360);

    // speed of particles
    m_emitter->setSpeed(160);
    m_emitter->setSpeedVar(20);

    // radial
    m_emitter->setRadialAccel(-120);
    m_emitter->setRadialAccelVar(0);

    // tagential
    m_emitter->setTangentialAccel(30);
    m_emitter->setTangentialAccelVar(0);

    // emitter position
    m_emitter->setPosition( CCPointMake(160,240) );
    m_emitter->setPosVar(CCPointZero);

    // life of particles
    m_emitter->setLife(3);
    m_emitter->setLifeVar(1);

    // spin of particles
    m_emitter->setStartSpin(0);
    m_emitter->setStartSpinVar(0);
    m_emitter->setEndSpin(0);
    m_emitter->setEndSpinVar(2000);

    // color of particles
    ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
    m_emitter->setStartColor(startColor);

    ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
    m_emitter->setStartColorVar(startColorVar);

    ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
    m_emitter->setEndColor(endColor);

    ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
    m_emitter->setEndColorVar(endColorVar);

    // size, in pixels
    m_emitter->setStartSize(30.0f);
    m_emitter->setStartSizeVar(00.0f);
    m_emitter->setEndSize(kParticleStartSizeEqualToEndSize);

    // emits per second
    m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife());

    // additive
    m_emitter->setIsBlendAdditive(false);

    setEmitterPosition();
}
void ParticleDemo::setEmitterPosition()
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();

	m_emitter->setPosition( CCPointMake(s.width / 2, s.height / 2) );
}
Exemplo n.º 24
0
//------------------------------------------------------------------
//
// DemoModernArt
//
//------------------------------------------------------------------
void DemoModernArt::onEnter()
{
    ParticleDemo::onEnter();

    m_emitter = new CCParticleSystemPoint();
    m_emitter->initWithTotalParticles(1000);
    //m_emitter->autorelease();

    m_background->addChild(m_emitter, 10);
    ////m_emitter->release();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    // duration
    m_emitter->setDuration(-1);

    // gravity
    m_emitter->setGravity(CCPointMake(0,0));

    // angle
    m_emitter->setAngle(0);
    m_emitter->setAngleVar(360);

    // radial
    m_emitter->setRadialAccel(70);
    m_emitter->setRadialAccelVar(10);

    // tagential
    m_emitter->setTangentialAccel(80);
    m_emitter->setTangentialAccelVar(0);

    // speed of particles
    m_emitter->setSpeed(50);
    m_emitter->setSpeedVar(10);

    // emitter position
    m_emitter->setPosition( CCPointMake( s.width/2, s.height/2) );
    m_emitter->setPosVar(CCPointZero);

    // life of particles
    m_emitter->setLife(2.0f);
    m_emitter->setLifeVar(0.3f);

    // emits per frame
    m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife());

    // color of particles
    ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f};
    m_emitter->setStartColor(startColor);

    ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f};
    m_emitter->setStartColorVar(startColorVar);

    ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f};
    m_emitter->setEndColor(endColor);

    ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f};
    m_emitter->setEndColorVar(endColorVar);

    // size, in pixels
    m_emitter->setStartSize(1.0f);
    m_emitter->setStartSizeVar(1.0f);
    m_emitter->setEndSize(32.0f);
    m_emitter->setEndSizeVar(8.0f);

    // texture
    m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) );

    // additive
    m_emitter->setIsBlendAdditive(false);

    setEmitterPosition();
}
Exemplo n.º 25
0
	static CCActionInterval* actionWithDuration(ccTime t)
	{
		CCSize size = CCDirector::sharedDirector()->getWinSize();
		return CCTwirl::actionWithPosition(CCPointMake(size.width/2, size.height/2), 1, 2.5f, ccg(12,8), t); 
	}
Exemplo n.º 26
0
 static CCActionInterval* create(float t)
 {
     CCSize size = CCDirector::sharedDirector()->getWinSize();
     return CCTwirl::create(CCPointMake(size.width/2, size.height/2), 1, 2.5f, ccg(12,8), t); 
 }
Exemplo n.º 27
0
SectionGuide::SectionGuide(BaseContentLayer* baseContentLayer,int seasonId,int sectionId)
{
    mBaseContentLayer = baseContentLayer;
    redStartPrompt = NULL;
    redStartToTableArrows = NULL;
    boxClickPrompt = NULL;
    bombClickPrompt = NULL;
    watingPrompt = NULL;
    forbidenPrompt = NULL;
    shine = NULL;
    clickAction = NULL;
    int z = 5;
    isGuide = false;
    isUserDoEffectiveClickAffterGuide = false;

    winSize = CCDirector::sharedDirector()->getWinSize();
    center = CCPointMake(winSize.width/2, winSize.height/2);



    {   //就针对第一章,第一关的教学配置
        if (seasonId == 1 && sectionId == 1)
        {   //第一章,第一关的指导:目标的教学
            //添加红星的提示
            baseContentLayer->addChild(redStartPrompt = createRedStartPrompt(),z);
            //添加箭头指示
            baseContentLayer->addChild(redStartToTableArrows = createRedStartToTableArrows(),z);
            //添加点击方块的提示,就是手指
            baseContentLayer->addChild(boxClickPrompt = createBoxClickPrompt(),z);

            clickAction = createClickAct_retain();
        }
    }

    {   //针对某一关需要加等待提示的地方
        if (seasonId == WAITING_PROMPT_SEASON_ID || WAITING_PROMPT_SEASON_ID == ALL)
        {
            if (sectionId == WAITING_PROMPT_SECTION_ID || WAITING_PROMPT_SECTION_ID == ALL)
            {
                baseContentLayer->addChild(watingPrompt = createWatingPrompt(),z);
                baseContentLayer->addChild(shine = createShine(),z);
            }
        }
    }

    {   //添加不可消除的提示
        if (seasonId == CAN_NOT_DESTORY_PROMPT_SEASON_ID || CAN_NOT_DESTORY_PROMPT_SEASON_ID == ALL)
        {
            if (sectionId == CAN_NOT_DESTORY_PROMPT_SECTION_ID || CAN_NOT_DESTORY_PROMPT_SECTION_ID == ALL)
            {
                baseContentLayer->addChild(forbidenPrompt = createCanNotDestoryPrompt(),z);
            }
        }
    }

    {   //添加炸弹提示
        if (seasonId == BOMB_PROMPT_SEASON_ID || BOMB_PROMPT_SEASON_ID == ALL)
        {
            if (sectionId == BOMB_PROMPT_SECTION_ID || BOMB_PROMPT_SECTION_ID == ALL)
            {
                baseContentLayer->addChild(bombClickPrompt = createBombClickPrompt(),z);
                clickAction = createClickAct_retain();
            }
        }
    }

}
Exemplo n.º 28
0
 static CCActionInterval* create(float t)
 {
     CCSize size = CCDirector::sharedDirector()->getWinSize();
     return CCRipple3D::create(CCPointMake(size.width/2,size.height/2), 240, 4, 160, ccg(32,24), t);
 }
Exemplo n.º 29
0
SpriteTest::SpriteTest(){
    this->init();
    this->initWithFile("Default.png");
    this->setAnchorPoint(CCPointMake(0, 0));
    
}
Exemplo n.º 30
0
bool RoleLayer::init() {
	CCLayer::init();

	//this->setContentSize(designResolutionSize);
	//CCSprite *role = CCSprite::createWithSpriteFrameName("Apple.png");
	//role->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height/2));
	//this->addChild(role);

	// test tile map
	//CCTMXTiledMap *tiledMap = CCTMXTiledMap::create("testmap.tmx");
	//tiledMap->setAnchorPoint(ccp(.5,.5));
	//tiledMap->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height/2));
	//this->addChild(tiledMap);

	// kDebugLabel
	CCLabelTTF *pDebugLabel = CCLabelTTF::create("", "Arial", 40);
	pDebugLabel->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height/2));
	pDebugLabel->setString("init");
	this->addChild(pDebugLabel, 100, kDebugLabel);

	// control btn
	CCScale9Sprite * btnNormal = CCScale9Sprite::createWithSpriteFrameName("Acorn_Squash.png");
	CCScale9Sprite* btnDown = CCScale9Sprite::createWithSpriteFrameName("Apple.png");
	CCLabelTTF * ttf_down = CCLabelTTF::create("[Down]", "Arial", 60);
	CCControlButton * cb_down = CCControlButton::create(ttf_down, btnNormal);  
	cb_down->setBackgroundSpriteForState(btnDown, CCControlStateSelected); 
	cb_down->setPosition(ccp(600,60));
	this->addChild(cb_down, 100, kDownControl);

	cb_down->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::down_power_on), CCControlEventTouchDown);  
	cb_down->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::down_power_on), CCControlEventTouchDragEnter);  
	cb_down->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::down_power_off), CCControlEventTouchDragExit);  
	cb_down->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::down_power_on), CCControlEventTouchDragInside);  
	cb_down->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::down_power_off), CCControlEventTouchDragOutside);  
	cb_down->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::down_power_off), CCControlEventTouchUpInside);  
	cb_down->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::down_power_off), CCControlEventTouchUpOutside);
	cb_down->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::down_power_off), CCControlEventTouchCancel);  

	// control btn
	CCScale9Sprite * btnNormal2 = CCScale9Sprite::createWithSpriteFrameName("Acorn_Squash.png");
	CCScale9Sprite* btnDown2 = CCScale9Sprite::createWithSpriteFrameName("Apple.png");
	CCLabelTTF * ttf_left = CCLabelTTF::create("[left]", "Arial", 60);
	CCControlButton * cb_left = CCControlButton::create(ttf_left, btnNormal2);  
	cb_left->setBackgroundSpriteForState(btnDown2, CCControlStateSelected); 
	cb_left->setPosition(ccp(100,60));
	this->addChild(cb_left, 100, kDownControl);

	cb_left->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::left_power_on), CCControlEventTouchDown);  
	cb_left->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::left_power_on), CCControlEventTouchDragEnter);  
	cb_left->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::left_power_off), CCControlEventTouchDragExit);  
	cb_left->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::left_power_on), CCControlEventTouchDragInside);  
	cb_left->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::left_power_off), CCControlEventTouchDragOutside);  
	cb_left->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::left_power_off), CCControlEventTouchUpInside);  
	cb_left->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::left_power_off), CCControlEventTouchUpOutside);
	cb_left->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::left_power_off), CCControlEventTouchCancel);  

	// control btn
	CCScale9Sprite * btnNormal3 = CCScale9Sprite::createWithSpriteFrameName("Acorn_Squash.png");
	CCScale9Sprite* btnDown3 = CCScale9Sprite::createWithSpriteFrameName("Apple.png");
	CCLabelTTF * ttf_right = CCLabelTTF::create("[right]", "Arial", 60);
	CCControlButton * cb_right = CCControlButton::create(ttf_right, btnNormal3);  
	cb_right->setBackgroundSpriteForState(btnDown3, CCControlStateSelected); 
	cb_right->setPosition(ccp(1180,60));
	this->addChild(cb_right, 100, kDownControl);

	cb_right->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::right_power_on), CCControlEventTouchDown);  
	cb_right->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::right_power_on), CCControlEventTouchDragEnter);  
	cb_right->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::right_power_off), CCControlEventTouchDragExit);  
	cb_right->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::right_power_on), CCControlEventTouchDragInside);  
	cb_right->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::right_power_off), CCControlEventTouchDragOutside);  
	cb_right->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::right_power_off), CCControlEventTouchUpInside);  
	cb_right->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::right_power_off), CCControlEventTouchUpOutside);
	cb_right->addTargetWithActionForControlEvents(this, cccontrol_selector(RoleLayer::right_power_off), CCControlEventTouchCancel);  


	// space ship
	CCSprite * ship = CCSprite::create("space_ship.png");
	ship->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height/2));
	this->addChild(ship, 50, kShip);

	// data init
	ai[0] = ai[1] = ai[2] = ccp(0,0);
	a = CCPointMake(0,0);
	v = CCPointMake(0,0);
	schedule(schedule_selector(RoleLayer::step));
	return true;
}