本文整理汇总了C++中CCDictionary::objectForKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CCDictionary::objectForKey方法的具体用法?C++ CCDictionary::objectForKey怎么用?C++ CCDictionary::objectForKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCDictionary
的用法示例。
在下文中一共展示了CCDictionary::objectForKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createObject
CObjectBase* CObjectBase::createObject(const string& name)
{
CObjectBase* pObject = NULL;
CCDictionary* pDict = GAME_OJBECT_MANAGER->getObjectByName(name);
if (!pDict)
{
return NULL;
}
CCString* strCateName = dynamic_cast<CCString*>(pDict->objectForKey("CateName"));
if (NULL == strCateName)
{
return NULL;
}
pObject = OBJECT_FACTORY->createInstance(strCateName->getCString());
if (pObject)
{
pObject->init(pDict);
}
return pObject;
}
示例2:
CCDictionary * CCTMXObjectGroup::objectNamed(const char *objectName)
{
if (m_pObjects && m_pObjects->count() > 0)
{
//CCArray::CCMutableArrayIterator it;
//for (it = m_pObjects->begin(); it != m_pObjects->end(); ++it)
//{
// CCString *name = (*it)->objectForKey(std::string("name"));
// if (name && name->m_sString == objectName)
// {
// return *it;
// }
//}
CCObject* pObj = NULL;
CCARRAY_FOREACH(m_pObjects, pObj)
{
CCDictionary* pDict = (CCDictionary*)pObj;
CCString *name = (CCString*)pDict->objectForKey("name");
if (name && name->m_sString == objectName)
{
return pDict;
}
}
示例3: requestFinishedCallback
void MDHeroPrePromoLayer::requestFinishedCallback(CCHttpClient* client, CCHttpResponse* response)
{
if (!this->ValidateResponseData(client,response))
{
return;
}
std::vector<char> *buffer = response->getResponseData();
std::string content(buffer->begin(),buffer->end());
CCDictionary * dictionary = CCJSONConverter::sharedConverter()->dictionaryFrom(content.c_str());
int code = ((CCNumber *)dictionary->objectForKey("code"))->getIntValue();
if (code != 200) {
CCMessageBox("invoke web api failed!","ERROR");
return;
}
std::string requestTag(response->getHttpRequest()->getTag());
if (requestTag == "101") {
} else if (requestTag == "102"){
}
}
示例4:
bool Lottery10TimesCommand::handleRecieve(cocos2d::CCDictionary *dict){
if (dict->valueForKey("cmd")->compare(LOTTERY_10TIMES_COMMAND) != 0) {
return false;
}
LotteryController::shared()->setSendCMD(false);
CCDictionary* params = _dict(dict->objectForKey("params"));
const CCString *pStr = params->valueForKey("errorCode");
if (pStr->compare("")!=0)
{
CCCommonUtils::flyText((_lang(pStr->getCString()).c_str()));
return false;
}
CCDictionary* resourceDic = _dict(params->objectForKey("resource"));
if (resourceDic->objectForKey("chip"))
{
GlobalData::shared()->resourceInfo.lChip = resourceDic->valueForKey("chip")->intValue();
}
if (params->objectForKey("batchResult"))
{
CCArray* batchResult = dynamic_cast<CCArray*>(params->objectForKey("batchResult"));
if(batchResult && batchResult->count()>0){
for(int i=0;i<batchResult->count();i++){
CCDictionary* iDict = dynamic_cast<CCDictionary*>(batchResult->objectAtIndex(i));
if (iDict->valueForKey("type")->intValue()==1) {
continue;
}
CCDictionary* rewards = _dict(iDict->objectForKey("result"));
CCArray* arr = CCArray::create();
arr->addObject(rewards);
GCMRewardController::getInstance()->retReward2(arr, false);
}
}
}
if (params->objectForKey("boxTimes"))
{
LotteryController::shared()->lotteryInfo.boxTimes = params->valueForKey("boxTimes")->intValue();
}
// LotteryController::shared()->lotteryActCmdBack(dict);
CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYACTVIEWCMD10, NetResult::createWithSuccess(params));
return true;
}
示例5: intAtArray
void Live2dXSprite::convertDictToConfig(CCDictionary* config)
{
CCDictionary* property = (CCDictionary*)config->objectForKey("property");
m_baseSize.width = property->valueForKey("width")->intValue();
m_baseSize.height = property->valueForKey("height")->intValue();
CCDictionary* unit_list = (CCDictionary*)config->objectForKey("unit_list");
CCArray* unit_names = unit_list->allKeys();
for (int i = 0; i < unit_names->count(); ++i)
{
CCString* unit_name = (CCString*)unit_names->objectAtIndex(i);
CCDictionary* unit = (CCDictionary*)unit_list->objectForKey(unit_name->m_sString);
CCArray* point = (CCArray*)unit->objectForKey("point");
CCArray* triangle = (CCArray*)unit->objectForKey("triangle");
Live2dX_TriangleList& triangle_list = m_all_units[unit_name->m_sString];
for (int k = 0; k < triangle->count(); ++k)
{
CCArray* triangle_one = (CCArray*)triangle->objectAtIndex(k);
int point_index[3];
point_index[0] = intAtArray(0, triangle_one);
point_index[1] = intAtArray(1, triangle_one);
point_index[2] = intAtArray(2, triangle_one);
Live2dX_Triangle tconfig;
for (int m = 0; m < 3; ++m)
{
CCArray* origin_points = (CCArray*)point->objectAtIndex(point_index[m]);
Live2dX_UV uv = {floatAtArray(0,origin_points),floatAtArray(1,origin_points)};
Live2dX_Vertex vertex = {floatAtArray(2,origin_points),floatAtArray(3,origin_points),0};
int point_id = (int)m_orginUV.size();
m_orginUV.push_back(uv);
m_orginVertex.push_back(vertex);
m_nowVertex.push_back(vertex);
m_orginColor.push_back(ccc4(0xff, 0xff,0xff, 0xff));
tconfig.point[m] = point_id;
tconfig.orginPoint[m] = point_index[m];
}
triangle_list.push_back(tconfig);
}
// m_all_units[unit_name->m_sString] = triangle_list;
CCDictionary* animation = (CCDictionary*)unit->objectForKey("animation");
if(animation)
{
map<string,Live2dX_Unit_Anims>& anim2 = m_all_unitanims[unit_name->m_sString];
CCArray* unit_anim_names = animation->allKeys();
for (int k = 0; k < unit_anim_names->count(); ++k)
{
CCString* unit_anim_name = (CCString*)unit_anim_names->objectAtIndex(k);
CCArray* unit_anims = (CCArray*)animation->objectForKey(unit_anim_name->m_sString);
Live2dX_Unit_Anims& unit_anims2 = anim2[unit_anim_name->m_sString];
for (int m = 0; m < unit_anims->count(); ++m)
{
CCDictionary* anim_item = (CCDictionary*)unit_anims->objectAtIndex(m);
Live2dX_Unit_Anim anim;
anim.type = (Live2dX_Animation_Type)anim_item->valueForKey("type")->intValue();
anim.start_perc = anim_item->valueForKey("start")->floatValue();
anim.end_perc = anim_item->valueForKey("end")->floatValue();
CCArray* value = (CCArray*)anim_item->objectForKey("value");
map<int,Live2dX_Unit_Anim_Pos> anim_pos;
int anim_id = m_all_point_move.size();
anim.anim_id = anim_id;
for (int n = 0; n < value->count(); ++n)
{
CCDictionary* value_item = (CCDictionary*)value->objectAtIndex(n);
Live2dX_Unit_Anim_Pos value = {
value_item->valueForKey("x")->floatValue(),
value_item->valueForKey("y")->floatValue(),
value_item->valueForKey("x_move")->floatValue(),
value_item->valueForKey("y_move")->floatValue(),
};
anim_pos[value_item->valueForKey("id")->intValue()] = value;
}
m_all_point_move.push_back(anim_pos);
unit_anims2.push_back(anim);
}
}
}
}
CCDictionary* animation = (CCDictionary*)config->objectForKey("animation");
CCArray* animation_names = animation->allKeys();
for (int i = 0;animation_names != NULL && i < animation_names->count(); ++i)
{
CCString* animation_name = (CCString*)animation_names->objectAtIndex(i);
CCArray* animation_items = (CCArray*)animation->objectForKey(animation_name->m_sString);
Live2dX_Anims& anim_list = m_all_anims[animation_name->m_sString];
for (int k = 0; k < animation_items->count(); ++k)
{
CCDictionary* animation_item = (CCDictionary*)animation_items->objectAtIndex(k);
Live2dX_Anim value = {
&m_all_unitanims[animation_item->valueForKey("unit_name")->m_sString][animation_item->valueForKey("anim_name")->m_sString],
animation_item->valueForKey("unit_name")->m_sString,
animation_item->valueForKey("delay")->floatValue(),
animation_item->valueForKey("time")->floatValue()
};
//.........这里部分代码省略.........
示例6: requestFinished
void SGRegisterBox::requestFinished(int msgid, CCObject *data)
{
if(msgid == MSG_HTTP_REGISTER)
{
CCString *backString = (CCString*)data;
if(backString->intValue() == 1)
{
CCUserDefault::sharedUserDefault()->setStringForKey("username", m_pEditName->getText());
CCUserDefault::sharedUserDefault()->setStringForKey("password", m_pEditPassword->getText());
CCUserDefault::sharedUserDefault()->setBoolForKey("isExist", true);
CCUserDefault::sharedUserDefault()->setBoolForKey("isAccount", true);
CCUserDefault::sharedUserDefault()->flush();
std::string userId = CCUserDefault::sharedUserDefault()->getStringForKey("userId");
//外部适配类调用
#if (PLATFORM == IOS)
OcCaller::getInstance()->setAccountSDK(userId, m_pEditName->getText());
#else
//android code
AndroidSDKAdp::getInstance()->setAccountSDK(userId, m_pEditName->getText());
#endif
/*
[sdkReqCallBack setAccount:[NSString stringWithFormat:@"%d",userId]
accountName:[NSString stringWithUTF8String:m_pEditName->getText()]
accountType:kAccountRegistered];
*/
SGRegisterSuccess *su = SGRegisterSuccess::create(deletage);
this->boxCloseWithOutCallBack();
SGMainManager::shareMain()->showBox(su);
}else{
labelAccountError->setVisible(true);
labelAccountError->setString(str_RegisterBox_str10);
this->processErrorState(FLAG_ERROR, FLAG_NODISPLAY, FLAG_NODISPLAY);
}
}else if(msgid == MSG_HTTP_BING)
{
CCDictionary *dict = (CCDictionary*)data;
CCString *string1 = (CCString*)dict->objectForKey("string1");
CCString *string2 = (CCString*)dict->objectForKey("string2");
if(1 == string1->intValue())
{
//绑定成功
SG_SHOW_WINDOW(str_RegisterBox_str11);
CCUserDefault::sharedUserDefault()->setStringForKey("username", m_pEditName->getText());
CCUserDefault::sharedUserDefault()->setStringForKey("password", m_pEditPassword->getText());
CCUserDefault::sharedUserDefault()->setBoolForKey("isAccount", true);
CCUserDefault::sharedUserDefault()->flush();
SGBindSuccessBox *success = SGBindSuccessBox::create(deletage);
this->boxCloseWithOutCallBack();
SGMainManager::shareMain()->showBox(success);
}else
{
if(string2->intValue() == 1)
{
//绑定失败
SG_SHOW_WINDOW(str_RegisterBox_str12);
}
else if(2 == string2->intValue())
{
SG_SHOW_WINDOW(str_RegisterBox_str1301);
}else if(3 == string2->intValue())
{
SG_SHOW_WINDOW(str_RegisterBox_str14);
}
}
}
}
示例7: InitLayer
bool CNFServerChangeLayer::InitLayer(int nCurrentServerID,int nServerTotalNum)
{
do
{
//初始化父类
CC_BREAK_IF(CCLayer::init()==false);
m_nCurrentServerID = nCurrentServerID;
/************************************************************************/
/* 背景图片 */
/************************************************************************/
//创建背景
CCSprite * pBg = CCSprite::create("ui/serverselect_bg.png");
CC_BREAK_IF(pBg==NULL);
pBg->setPosition(SCREEN_CENTER);
pBg->setScaleX( (float)CCDirector::sharedDirector()->getWinSize().width/(float)pBg->getContentSize().width );
addChild(pBg,enZOrderBack);
//创建上次登录图片
CCSprite * pBg1 = CCSprite::create("ui/serverselect_title_1.png");
CC_BREAK_IF(pBg1==NULL);
pBg1->setPosition(ccp(150+_NF_SCREEN_WIDTH_DIS_,420));
addChild(pBg1,enZOrderBack);
//创建全服务器图片
CCSprite * pBg2 = CCSprite::create("ui/serverselect_title_2.png");
CC_BREAK_IF(pBg2==NULL);
pBg2->setPosition(ccp(160+_NF_SCREEN_WIDTH_DIS_,300));
addChild(pBg2,enZOrderBack);
/************************************************************************/
/* 创建按钮 */
/************************************************************************/
CCMenu * pMenu = CCMenu::create();
CC_BREAK_IF(pMenu==NULL);
pMenu->setPosition(CCPointZero);
addChild(pMenu,enZOrderFront);
//创建返回按钮
//CCMenuItemSprite * pBtnBack = CCMenuItemSprite::create(
// CCSprite::create("ui/serverselect_btn_back_n.png"),
// CCSprite::create("ui/serverselect_btn_back_p.png"),
// this,
// menu_selector(CNFServerChangeLayer::OnBtnCallBack));
//CC_BREAK_IF(pBtnBack==NULL);
//pBtnBack->setPosition(ccp(SCREEN_WIDTH - 30,SCREEN_HEIGHT-30));
//pMenu->addChild(pBtnBack,enZOrderFront);
//创建当前服务器按钮
CCMenuItemSprite * pBtnCurrentServer = CCMenuItemSprite::create(
CCSprite::create("ui/btn_enter_n.png"),
CCSprite::create("ui/btn_enter_p.png"),
this,
menu_selector(CNFServerChangeLayer::OnBtnCallBack));
CC_BREAK_IF(pBtnCurrentServer==NULL);
pBtnCurrentServer->setPosition(ccp(190+_NF_SCREEN_WIDTH_DIS_,380));
pMenu->addChild(pBtnCurrentServer,enZOrderFront);
//创建左侧按钮
CCMenuItemSprite * pBtnLeft = CCMenuItemSprite::create(
CCSprite::create("ui/serverselect_btn_back_n.png"),
CCSprite::create("ui/serverselect_btn_back_p.png"),
this,
menu_selector(CNFServerChangeLayer::OnBtnLeftMove));
CC_BREAK_IF(pBtnLeft==NULL);
pBtnLeft->setPosition(ccp(50+_NF_SCREEN_WIDTH_DIS_,150));
pMenu->addChild(pBtnLeft,enZOrderFront);
//创建右侧按钮
CCMenuItemSprite * pBtnRight = CCMenuItemSprite::create(
CCSprite::create("ui/serverselect_btn_back_n.png"),
CCSprite::create("ui/serverselect_btn_back_p.png"),
this,
menu_selector(CNFServerChangeLayer::OnBtnRightMove));
CC_BREAK_IF(pBtnRight==NULL);
pBtnRight->setPosition(ccp(SCREEN_WIDTH-_NF_SCREEN_WIDTH_DIS_-50,150));
pMenu->addChild(pBtnRight,enZOrderFront);
/************************************************************************/
/* 创建label */
/************************************************************************/
CCDictionary *pDicLang = CCDictionary::createWithContentsOfFile("ui_xml/serverselect_xml.xml");
CC_BREAK_IF(pDicLang==NULL);
//服务器名称label
CCString *pStrServerName = dynamic_cast<CCString*>(pDicLang->objectForKey("server_name"));
char szName[NAME_LEN] = {0};
sprintf(szName,pStrServerName->m_sString.c_str(),nCurrentServerID);
CCLabelTTF * pLabelServerName = CCLabelTTF::create(szName,"Arial",20);
CC_BREAK_IF(pLabelServerName==NULL);
pLabelServerName->setPosition(pBtnCurrentServer->getPosition());
addChild(pLabelServerName,enZOrderFront);
/************************************************************************/
/* 创建滑动层 */
/************************************************************************/
//创建滑动层
CNFServerChangeScrollLayer * pLayer = CNFServerChangeScrollLayer::CreateLayer(nServerTotalNum); //Item数组,x轴起始位置
//.........这里部分代码省略.........
示例8: showBoxCall
void SGHelpLayer::showBoxCall(CCObject *obj)
{
//不知道为什么需要加一个,返回的已经有了呀
SGMainLayer *mainLayer = (SGMainLayer *)SGMainManager::shareMain()->getMainScene()->getChildByTag(sg_mainLayer);
if (mainLayer) {
mainLayer->setIsCanTouch(true);
}
if (obj)
{
CCDictionary *dict = (CCDictionary *)obj;
CCString *key = (CCString*)dict->objectForKey("key");
if(key->isEqual(CCString::create("serverList")))
{
CCString *serverName = (CCString*)dict->objectForKey("serverName");
CCString *serverIp = ((CCString*)dict->objectForKey("serverIp"));
CCString *serverId = (CCString*)dict->objectForKey("serverId");
CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
CCLOG("选中服务器名字: %s",serverName->getCString());
CCLOG("选中服务器Ip: %s",serverIp->getCString());
CCLOG("选中服务器Post: %s",serverPost->getCString());
CCLOG("选中服务器Id: %s",serverId->getCString());
CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", (short)serverPost->intValue());
CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid", (short)serverId->intValue());
CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
CCUserDefault::sharedUserDefault()->flush();
std::string un = CCUserDefault::sharedUserDefault()->getStringForKey("username");
std::string pw = CCUserDefault::sharedUserDefault()->getStringForKey("password");
SGMainManager::shareMain()->setServerInfo(serverIp , (short)serverPost->intValue());
//SGHttpClient::shareHttpClient()->login(this, accountId, sid);
//OC调用改到外围
//#if (PLATFORM == IOS)
SGMainManager::shareMain()->dealIosLogin(un,pw);
// //OcCaller::getInstance()->pyUserSDKLoginReq(un.c_str(), pw.c_str());
//#else
// //android code
// SdkManager::shareSdkManager()->userLogin(un.c_str(), pw.c_str());
//#endif
/*
id sdkReqCallBack = SGMainManager::shareMain()->getSdkdelegate();
[[PYUserSDKLib sharedUserSDKLib] userLogin:[[NSString alloc] initWithUTF8String:un.c_str()]
Password:[[NSString alloc] initWithUTF8String:pw.c_str()]
GameId:@"1"
ChannelId:[sdkReqCallBack ChannelId]
SubChannelId:[sdkReqCallBack SubChannelId]
OsVersion:[sdkReqCallBack OsVersion]
OsType:[sdkReqCallBack OsType]
CallBackDelegate:sdkReqCallBack FinishSelector:@selector(loginFinished:) FailSelector:@selector(requestFailed:)];
*/
}
}
}
示例9: getChinese
std::string Language::getChinese( std::string str )
{
CCDictionary* strings = CCDictionary::createWithContentsOfFile("chinese.xml");
std::string word = ((CCString*)strings->objectForKey(str))->m_sString;
return word;
}
示例10: appendObject
void appendObject(Ref* obj, xml_node& node)
{
if(isKindOfClass(obj, CCDictionary))
{
//CCLOG("Dictionary recognized");
CCDictionary* dict = (CCDictionary*)obj;
xml_node children = node.append_child("dict");
CCArray* keys = dict->allKeys();
if(keys != NULL)
{
for(int i = 0; i < keys->count(); i++)
{
CCString* key = (CCString*)keys->objectAtIndex(i);
children.append_child("key").append_child(node_pcdata).set_value(key->getCString());
appendObject(dict->objectForKey(key->getCString()), children);
}
}
}
else if(isKindOfClass(obj, CCArray))
{
//CCLOG("Array recognized");
CCArray* array = (CCArray*)obj;
xml_node children = node.append_child("array");
for(int i = 0; i < array->count(); i++)
{
Ref* child = (Ref*)array->objectAtIndex(i);
appendObject(child, children);
}
}
else if (isKindOfClass(obj, CCString))
{
//CCLOG("String recognized");
node.append_child("string").append_child(node_pcdata).set_value(((CCString*)obj)->getCString());
}
else if (isKindOfClass(obj, CCInteger))
{
//CCLOG("Integer recognized");
int value = TOINT(obj);
CCString* stringVal = ScreateF("%d", value);
node.append_child("integer").append_child(node_pcdata).set_value(stringVal->getCString());
}
else if (isKindOfClass(obj, CCFloat))
{
//CCLOG("Float recognized");
float value = TOFLOAT(obj);
CCString* stringVal = ScreateF("%g", value);
node.append_child("real").append_child(node_pcdata).set_value(stringVal->getCString());
}
else if (isKindOfClass(obj, CCBool))
{
//CCLOG("Bool recognized");
bool value = TOBOOL(obj);
node.append_child(value ? "true" : "false");
}
#if VERBOSE_SAVE_PLIST
else
{
CCLOG("Warning: unrecognized type %s when saving plist, check if the object is in plist format", typeid(*obj).name());
}
#endif
}
示例11: addSpriteFramesWithDictionary
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
CCAssert(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)
//.........这里部分代码省略.........
示例12: touchDownAction
void QuestionLayer::touchDownAction(CCObject *sender, CCControlEvent controlEvent)
{
CCLOG("QuestionLayer::touchDownAction");
if (isAnswerFinished) {
return;
}
this->unschedule(schedule_selector(QuestionLayer::timerCB));
CCControlButton* button = (CCControlButton *)sender;
CCLOG("%d", button->getTag());
button->setEnabled(false);
bool bFind = false;
CCDictionary* results = questionObj->rightAnswer;
for (int i=0; i<results->allKeys()->count(); i++) {
CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
if (key->intValue() == button->getTag()) {
results->setObject(CCString::createWithFormat("%d", 1), key->getCString());
bFind = true;
break;
}
}
if (bFind) {
//统计已经回答正确答案的数量
int rCount = 0;
for (int i=0; i<results->allKeys()->count(); i++) {
CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
CCString* value = (CCString *)(results->objectForKey(key->getCString()));
if (value->intValue() == 1) {
rCount++;
}
}
CCLOG("rCount:%d", rCount);
if (rCount == results->allKeys()->count()) {
//回答完成所有正确答案
for (int i=0; i<results->allKeys()->count(); i++) {
CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
CCControlButton* btn = (CCControlButton *)(this->getChildByTag(key->intValue()));
CCSprite* spr = CCSprite::create("star000.png");
spr->setAnchorPoint(ccp(0.5f, 0.5f));
spr->setPosition(ccp(button->getContentSize().width/2, button->getContentSize().height/2));
btn->addChild(spr);
CCBlink* blink = CCBlink::create(1.0f, 3);
if (i < results->allKeys()->count()-1) {
spr->runAction(blink);
} else {
CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::noticeDelegate), NULL);
spr->runAction(CCSequence::create(blink, pAction, NULL));
}
}
rightAnswer++;
if (timerCount >= timerTotal*2/3) {
rightLimit += 1;
//播放快速答题音效
GameSoundManager::shareManager()->playAnswerCool();
} else {
//播放普通答题正确音效
GameSoundManager::shareManager()->playAnswerRight();
}
isAnswerFinished = true;
} else {
CCLOG("正确答案没选完");
}
} else {
//回答错误
CCSprite* spr = CCSprite::create("arrow000.png");
spr->setAnchorPoint(ccp(0.5f, 0.5f));
spr->setPosition(ccp(button->getContentSize().width/2, button->getContentSize().height/2));
button->addChild(spr);
CCFadeIn* fadeIn = CCFadeIn::create(1.0f);
CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::noticeDelegate), NULL);
spr->runAction(CCSequence::create(fadeIn, pAction, NULL));
errorAnswer++;
isAnswerFinished = true;
//播放错误音效
GameSoundManager::shareManager()->playAnswerError();
}
}
示例13: getCmdData
void LotteryRotateView::getCmdData(CCObject *pObj)
{
CCString* reward = CCString::create("");
if (LotteryController::shared()->rotateType==1) {//0-普通,1-连转10次
m_save10Arr = dynamic_cast<CCArray*>(pObj);
LotteryController::shared()->m_save10Arr = dynamic_cast<CCArray*>(pObj);
if(m_save10Arr && m_save10Arr->count()>0){
CCDictionary* lastDict = dynamic_cast<CCDictionary*>(m_save10Arr->objectAtIndex(m_save10Arr->count()-1));
int dictType = lastDict->valueForKey("type")->intValue();
CCDictionary* rewardsDic = _dict(lastDict->objectForKey("result"));
/* 里面的type 是
RESOURCE, BOX_TIMES, REWARD 0 1 2*/
if (dictType == 0) {//RESOURCE
int resType = rewardsDic->valueForKey("type")->intValue();
reward = CCString::create(CC_ITOA(resType));
}else if (dictType == 1){//BOX_TIMES
reward = CCString::create(CC_ITOA(100));
}else if (dictType == 2){//REWARD
int resType = rewardsDic->valueForKey("type")->intValue();
if (resType == 7) {
CCDictionary* valueDic = _dict(rewardsDic->objectForKey("value"));
int itemId = valueDic->valueForKey("itemId")->intValue();
reward = CCString::create(CC_ITOA(itemId));
}else{
reward = CCString::create(CC_ITOA(resType));
}
}
}
}else{
reward = dynamic_cast<CCString*>(pObj);
}
CCLOG("reward:%s",reward->getCString());
if (!reward || (reward && reward->compare("error")==0))
{
m_targetCell = NULL;
CCDictionary* dict = CCDictionary::create();
dict->setObject(ccs(LOTTERYACTVIEW_COM), "key");
dict->setObject(ccs("error"), "value");
CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
// rotateFinished();
this->unschedule(schedule_selector(LotteryRotateView::rotatingHandler));
m_rotating = false;
return;
}
float rotateAngleArr[12] = {0, 30, 60, 90, 120, 150, 180, -150, -120, -90, -60, -30};
float rotateAngle = 0.0f;
LotteryActCell* cell2 = NULL;
bool getTarget = false;
for (int i = 0; i < m_pContainer->getChildrenCount(); i++)
{
cell2 = dynamic_cast<LotteryActCell*>(m_pContainer->getChildByTag(i));
if (cell2)
{
rotateAngle = rotateAngleArr[i];
cell2->setAngle(CC_DEGREES_TO_RADIANS(rotateAngle));
if (!getTarget && reward->compare(cell2->getItemId().c_str())==0)
{
m_targetCell = cell2;
getTarget = true;
}
}
}
doCellSort();
if (m_targetCell == NULL)
{
// rotateFinished();
this->unschedule(schedule_selector(LotteryRotateView::rotatingHandler));
m_rotating = false;
CCDictionary* dict = CCDictionary::create();
dict->setObject(ccs(LOTTERYACTVIEW_COM), "key");
dict->setObject(ccs("error"), "value");
CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(LOTTERYROTATEVIEW, dict);
return;
}
int index = m_targetCell->getTag();
// 基准角度
float addAngle = 0.0;
if (LotteryController::shared()->rotateType==1) {//0-普通,1-连转10次
// addAngle = 360;
}
if (m_tScrollAngel > 0) {
m_fEndAngle = -(index+3)*30 + addAngle + (1 + ((int) m_speed3/360)) * 360.0f;//720
}
else {
m_fEndAngle = -(index+3)*30.0f - addAngle - (1 + ((int) m_speed3/360)) * 360.0f;//360
}
m_fEndTime3 = fabs(m_fEndAngle)/m_speed3;// 一圈的时间
m_fTimeCnt3 = (int) (m_fEndTime3/m_fTimeGap3)*1.3;
// if (LotteryController::shared()->rotateType==1) {//0-普通,1-连转10次
// addRewardsNodeBg();
// }
// if (m_fTimeCnt3 > 300)
// {
// m_fTimeCnt3 = m_fTimeCnt3/2;
// }
m_fTimeIdx3 = 0;
//.........这里部分代码省略.........
示例14: getBaseValue
CCObject* CCBAnimationManager::getBaseValue(CCNode *pNode, const char* pPropName)
{
CCDictionary *props = (CCDictionary*)mBaseValues->objectForKey((intptr_t)pNode);
return props->objectForKey(pPropName);
}
示例15: startAnswer
void QuestionLayer::startAnswer()
{
timerCount = timerTotal;
CCSize size = this->getContentSize();
CCLOG("%f %f", size.width, size.height);
CCScale9Sprite* labelBg = CCScale9Sprite::create("bg_question.png");
labelBg->setAnchorPoint(ccp(0.5, 0.5));
labelBg->setPosition(ccp(0, size.height/2-100));
labelBg->setContentSize(CCSizeMake(size.width, 160));
this->addChild(labelBg, 0);
const char* filePath = NULL;
if (queType == SingleQuestion) {
filePath = CCFileUtils::sharedFileUtils()->fullPathForFilename("question_4.plist").c_str();
} else if (queType == JudgeQuestion) {
filePath = CCFileUtils::sharedFileUtils()->fullPathForFilename("question_2.plist").c_str();
} else {
filePath = CCFileUtils::sharedFileUtils()->fullPathForFilename("question_3.plist").c_str();
}
CCArray* plistArray = CCArray::createWithContentsOfFile(filePath);
//开始查找随机题目,并且不能重复
bool bFind = false;
while (!bFind) {
serialNo = arc4random()%plistArray->count(); //serialNo = CCRANDOM_0_1()*plistArray->count()-1;
CCLOG("serialNo:%d", serialNo);
bool isSame = false;
for (int i=0; i<historyQuestiones->count(); i++) {
CCInteger* integer = (CCInteger *)historyQuestiones->objectAtIndex(i);
if (integer->getValue() == serialNo) {
isSame = true;
break;
}
}
if (!isSame) {
bFind = true;
}
}
historyQuestiones->addObject(CCInteger::create(serialNo));
CCDictionary* dic = (CCDictionary*)plistArray->objectAtIndex(serialNo);
CCString* qType = (CCString *)(dic->objectForKey("type")); //Number类型
CCString* pStr = (CCString *)(dic->objectForKey("question"));
CCLOG("%d %s", qType->intValue(), pStr->getCString());
CCArray* ans = (CCArray *)(dic->objectForKey("answer"));
questionObj = new QuestionObj(qType->intValue(), pStr->getCString(), ans);
CCLOG("读取题目信息完成");
questionString = questionObj->questionString;
displayLen = 0;
//题目
CCLabelTTF* pLabel = CCLabelTTF::create(questionStr.c_str(), "Arial", 24, CCSize(size.width-20, 90), kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop);
pLabel->setAnchorPoint(ccp(1, 0));
pLabel->setPosition(ccp(-size.width/2+15, size.height/2-130));
pLabel->setAnchorPoint(ccp(0, 0));
this->addChild(pLabel, 1, 11);
const char* typeStr = "单选题";
if (questionObj->questionType == 1) {
typeStr = "单选题";
timerTotal = 15;
} else if (questionObj->questionType == 2) {
typeStr = "判断题";
timerTotal = 12;
} else {
typeStr = "多选题";
timerTotal = 30;
}
CCString* title = CCString::createWithFormat("题型:%s", typeStr);
CCLabelTTF* label = CCLabelTTF::create(title->getCString(), "Arial", 24);
label->setAnchorPoint(ccp(0, 1));
label->setPosition(ccp(140, size.height/2-135));
this->addChild(label, 1, 12);
// CCSprite* timerBg = CCSprite::create("money_bg.png");
// timerBg->setPosition(ccp(0, size.height/2-200));
// this->addChild(timerBg);
progressTimer = CCProgressTimer::create(CCSprite::create("money_bg.png"));
progressTimer->setType(kCCProgressTimerTypeBar);
progressTimer->setMidpoint(ccp(0, 0));
progressTimer->setBarChangeRate(ccp(1, 0));
progressTimer->setAnchorPoint(ccp(0.5, 0.5));
progressTimer->setPosition(ccp(0, size.height/2-200));
progressTimer->setPercentage(100);
progressTimer->setContentSize(CCSizeMake(300, 38));
this->addChild(progressTimer, 2);
timerLabel_ = CCLabelTTF::create(CCString::createWithFormat("%d", timerCount)->getCString(), "Arial", 24);
timerLabel_->setAnchorPoint(ccp(1, 0));
timerLabel_->setPosition(ccp(0, 0));
progressTimer->addChild(timerLabel_);
warnTipSpr = CCSprite::create("arrow000.png");
warnTipSpr->setPosition( ccp(progressTimer->getContentSize().width/3*2, 0) );
warnTipSpr->setAnchorPoint( ccp(0.5, 0) );
progressTimer->addChild(warnTipSpr);
//显示宫格答案
this->displaySubViews();
//.........这里部分代码省略.........