////////AnimatorInitData///////////
void AnimatorInitData::init(cocos2d::CCDictionary *dataDict)
{
	assert(dataDict);
	
	m_anchorPoint = CCPointFromString(dataDict->valueForKey("AnchorPoint")->getCString());
	m_position = CCPointFromString(dataDict->valueForKey("Position")->getCString());
	m_scale = CCPointFromString(dataDict->valueForKey("Scale")->getCString());
	m_rotation = dataDict->valueForKey("Rotation")->floatValue();
	m_opacity = dataDict->valueForKey("Opacity")->uintValue();
}
CCAction* ParserBezierTo::parseAction(cocos2d::CCDictionary *dict)
{
	float duration = dict->valueForKey("Duration")->floatValue();
	ccBezierConfig config;
	CCDictionary* configDict = (CCDictionary*)dict->objectForKey("BezierConfig");
	config.endPosition = CCPointFromString(configDict->valueForKey("EndPosition")->getCString());
    config.endPosition = pointWithContentScale(config.endPosition);
	config.controlPoint_1 = CCPointFromString(configDict->valueForKey("ControlPoint1")->getCString());
    config.controlPoint_1 = pointWithContentScale(config.controlPoint_1);
	config.controlPoint_2 = CCPointFromString(configDict->valueForKey("ControlPoint2")->getCString());
    config.controlPoint_2 = pointWithContentScale(config.controlPoint_2);
	return CCBezierTo::create(duration, config);
}
Ejemplo n.º 3
0
bool SFPlace::initWithDictionary(CCDictionary * pDict)
{
	if (!SFActionInstant::initWithDictionary(pDict))
	{
		CNLog("error");
		return false;
	}
	CCString * pPosition = (CCString *)pDict->objectForKey("Position");
	if (pPosition)
	{
		m_tPosition = CCPointFromString(pPosition->getCString());
	}
	return true;
}
bool GHBone::initWithDictionary(CCDictionary* info)
{
    if(info == NULL)return false;
    
    neighbours = NULL;
    neighboursDistances = NULL;
    
    m_rigid = info->valueForKey("rigid")->boolValue();
    
    CCPoint localPos = ccp(0,0);

    CCString* bonePos = (CCString*)info->objectForKey("localPos"); //this position is local from the root bone
    if(bonePos){
        localPos = CCPointFromString(bonePos->getCString());
    }
    localPos.x /= CC_CONTENT_SCALE_FACTOR();
    localPos.y /= CC_CONTENT_SCALE_FACTOR();
    
    CCString* boneName = (CCString*)info->objectForKey("name");
    if(boneName){
        m_name = std::string(boneName->getCString());
    }
    else{
        m_name = std::string("UntitledBone");
    }
    
    CCString* boneUUID = (CCString*)info->objectForKey("uuid");
    if(boneUUID){
        m_uuid = std::string(boneUUID->getCString());
    }
    else{
        m_uuid = std::string("ERROR_NO_UUID_FOUND");
    }
    
    this->setPosition(localPos);
    
    
    CCArray* childrenInfo = (CCArray*)info->objectForKey("children");

    CCObject* pObj = NULL;
    CCARRAY_FOREACH(childrenInfo, pObj)
    {
        CCDictionary* childInfo = (CCDictionary*)pObj;

        GHBone* childBone = GHBone::createBoneWithDictionary(childInfo);
        if(childBone){
            this->addChild(childBone);
        }
    }
Ejemplo n.º 5
0
void HelloWorld::addCards(){
    CCPoint p;
    
    int randNum;
    Card* card;
    
    srand(time(NULL));
    
    for (int i=1; i<=10; i++) {
        randNum = rand()%(pointArr->count());
        p= CCPointFromString(((CCString*)pointArr->objectAtIndex(randNum))->getCString());
        card = Card::create(i);
        addChild(card);
        cardArr->addObject(card);
        card->setPosition(p);
        
        pointArr->removeObjectAtIndex(randNum);
    }
}
void ProjectConfig::parseCommandLine(vector<string>& args)
{
    vector<string>::iterator it = args.begin();
    while (it != args.end())
    {
        const string& arg = *it;

        if (arg.compare("-quick") == 0)
        {
            ++it;
            if (it == args.end()) break;
            SimulatorConfig::sharedDefaults()->setQuickCocos2dxRootPath((*it).c_str());
        }
        else if (arg.compare("-workdir") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setProjectDir(*it);
            if (m_writablePath.length() == 0) setWritablePath(*it);
        }
        else if (arg.compare("-writable") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setWritablePath(*it);
        }
        else if (arg.compare("-file") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setScriptFile(*it);
        }
        else if (arg.compare("-package.path") == 0)
        {
            ++it;
            if (it == args.end()) break;
            setPackagePath(*it);
        }
        else if (arg.compare("-landscape") == 0)
        {
            setFrameSize(CCSize(DEFAULT_HEIGHT, DEFAULT_WIDTH));
        }
        else if (arg.compare("-portrait") == 0)
        {
            setFrameSize(CCSize(DEFAULT_WIDTH, DEFAULT_HEIGHT));
        }
        else if (arg.compare("-size") == 0)
        {
            ++it;
            if (it == args.end()) break;
            const string& sizeStr(*it);
            size_t pos = sizeStr.find('x');
            int width = 0;
            int height = 0;
            if (pos != sizeStr.npos && pos > 0)
            {
                string widthStr, heightStr;
                widthStr.assign(sizeStr, 0, pos);
                heightStr.assign(sizeStr, pos + 1, sizeStr.length() - pos);
                width = atoi(widthStr.c_str());
                height = atoi(heightStr.c_str());
                setFrameSize(CCSize(width, height));
            }
        }
        else if (arg.compare("-scale") == 0)
        {
            ++it;
            if (it == args.end()) break;
            float scale = atof((*it).c_str());
            setFrameScale(scale);
        }
        else if (arg.compare("-write-debug-log") == 0)
        {
            setWriteDebugLogToFile(true);
        }
        else if (arg.compare("-disable-write-debug-log") == 0)
        {
            setWriteDebugLogToFile(false);
        }
        else if (arg.compare("-console") == 0)
        {
            setShowConsole(true);
        }
        else if (arg.compare("-disable-console") == 0)
        {
            setShowConsole(false);
        }
        else if (arg.compare("-load-framework") == 0)
        {
            setLoadPrecompiledFramework(true);
        }
        else if (arg.compare("-disable-load-framework") == 0)
        {
            setLoadPrecompiledFramework(false);
        }
        else if (arg.compare("-offset") == 0)
        {
            ++it;
            if (it == args.end()) break;
            CCPoint pos = CCPointFromString((*it).c_str());
            setWindowOffset(pos);
        }
        else if (arg.compare("-debugger-ldt") == 0)
        {
            setDebuggerType(kCCLuaDebuggerLDT);
        }
        else if (arg.compare("-disable-debugger") == 0)
        {
            setDebuggerType(kCCLuaDebuggerNone);
        }
        else if (arg.compare("-relaunch-off") == 0)
        {
            setExitWhenRelaunch(true);
        }
        else if (arg.compare("-relaunch-on") == 0)
        {
            setExitWhenRelaunch(false);
        }

        ++it;
    }
}
Ejemplo n.º 7
0
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)
            {
                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();
	}
}
Ejemplo n.º 8
0
void GB2ShapeCache::addShapesWithFile(const std::string &plist) {
	const char *fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist.c_str()).c_str();
	//const char *fullName = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(plist.c_str());
	ObjectDict *dict = CCDictionary::createWithContentsOfFile(fullName);
	CCAssert(dict != NULL, "Shape-file not found"); // not triggered - cocos2dx delivers empty dict if non was found
    CCAssert(dict->count() != 0, "plist file empty or not existing");
	
	ObjectDict *metadataDict = (ObjectDict *)dict->objectForKey("metadata");
    int format = atoi(static_cast<CCString *>(metadataDict->objectForKey("format"))->getCString());
    ptmRatio = atof(static_cast<CCString *>(metadataDict->objectForKey("ptm_ratio"))->getCString());
	CCAssert(format == 1, "Format not supported");

	ObjectDict *bodyDict = (ObjectDict *)dict->objectForKey("bodies");
    CCLOG("%d", bodyDict->count());
    
    b2Vec2 vertices[b2_maxPolygonVertices];

	std::string bodyName;
    ObjectDict *bodyData;
    CCDictElement *pElement = NULL;
    CCDICT_FOREACH(bodyDict, pElement)
    {
        bodyName = pElement->getStrKey();
        bodyData = (ObjectDict *)pElement->getObject();

        CCLOG("%d", bodyData->count());
        
        CCString *anchorPoint = static_cast<CCString *>(bodyData->objectForKey("anchorpoint"));
		BodyDef *bodyDef = new BodyDef();
		bodyDef->anchorPoint = CCPointFromString(anchorPoint->getCString());
		
		CCArray *fixtureList = (CCArray *)(bodyData->objectForKey("fixtures"));
        FixtureDef **nextFixtureDef = &(bodyDef->fixtures);

        CCObject *pElement = NULL;
        CCARRAY_FOREACH(fixtureList, pElement)
        {
            b2FixtureDef basicData;
            ObjectDict *fixtureData = (ObjectDict *)pElement;
			
            basicData.filter.categoryBits = atoi(static_cast<CCString *>(fixtureData->objectForKey("filter_categoryBits"))->getCString());
            basicData.filter.maskBits = atoi(static_cast<CCString *>(fixtureData->objectForKey("filter_maskBits"))->getCString());
            basicData.filter.groupIndex = atoi(static_cast<CCString *>(fixtureData->objectForKey("filter_groupIndex"))->getCString());
            basicData.friction = atof(static_cast<CCString *>(fixtureData->objectForKey("friction"))->getCString());
            basicData.density = atof(static_cast<CCString *>(fixtureData->objectForKey("density"))->getCString());
            basicData.restitution = atof(static_cast<CCString *>(fixtureData->objectForKey("restitution"))->getCString());
            basicData.isSensor = (bool)(atoi(static_cast<CCString *>(fixtureData->objectForKey("isSensor"))->getCString()));

			CCString *cb = static_cast<CCString *>(fixtureData->objectForKey("userdataCbValue"));
			
            int callbackData = 0;
			
			if (cb)
				callbackData = atoi(cb->getCString());
            
			std::string fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->getCString();
			
			if (fixtureType == "POLYGON") {
				CCArray *polygonsArray = (CCArray *)(fixtureData->objectForKey("polygons"));

                CCObject *pElement = NULL;
                CCARRAY_FOREACH(polygonsArray, pElement)
                {
                    FixtureDef *fix = new FixtureDef();
                    fix->fixture = basicData; // copy basic data
                    fix->callbackData = callbackData;
					
                    b2PolygonShape *polyshape = new b2PolygonShape();
                    int vindex = 0;
                    
					CCArray *polygonArray = (CCArray *)pElement;

                    assert(polygonArray->count() <= b2_maxPolygonVertices);

                    CCObject *pElement = NULL;
                    CCARRAY_FOREACH(polygonArray, pElement)
                    {
                        CCString *str = (CCString *)pElement;
                        CCPoint offset = CCPointFromString(str->getCString());
                        vertices[vindex].x = (offset.x / ptmRatio) ; 
                        vertices[vindex].y = (offset.y / ptmRatio) ; 
                        vindex++;
                    }
/////////////////AnimatorModuleData//////////////////////////////
void AnimatorModuleData::init(cocos2d::CCDictionary *moduleDict)
{
	m_anchorPoint = CCPointFromString(moduleDict->valueForKey("AnchorPoint")->getCString());
	m_contentSize = CCSizeFromString(moduleDict->valueForKey("Size")->getCString());
}
Ejemplo n.º 10
0
CCTexture2D* TextureHelper::addImageFromPlist(const char* plist)
{
	std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist);
	CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(fullPath.c_str());
	CCDictionary *metadataDict = (CCDictionary*)dict->objectForKey("metadata");
	std::string pngPath = metadataDict->valueForKey("realTextureFileName")->getCString();
	CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage(pngPath.c_str());
	CCDictionary *framesDict = (CCDictionary*)dict->objectForKey("frames");
	int format = 0;
	CCSize textureSize = texture->getContentSize();

	if(metadataDict != NULL) 
	{
		format = metadataDict->valueForKey("format")->intValue();
	}

	CCAssert(format >=0 && format <= 3, "format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:textureFilename:");

	CCDictElement* pElement = NULL;
	CCDICT_FOREACH(framesDict, pElement)
	{
		CCRect rect;
		CCDictionary* frameDict = (CCDictionary*)pElement->getObject();
		std::string spriteFrameName = pElement->getStrKey();
	
		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();
			if(!ow || !oh)
			{
				CCLOGWARN("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
			}
			ow = abs(ow);
			oh = abs(oh);
			rect = CCRectMake(x + ox,textureSize.height - y + oy,ow,oh);
		 } 
		 else if(format == 1 || format == 2) 
		 {
			  CCRect frame = CCRectFromString(frameDict->valueForKey("frame")->getCString());
			  frame.origin.y = textureSize.height - frame.origin.y;
			  bool rotated = false;

			  if (format == 2)
			  {
				  rotated = frameDict->valueForKey("rotated")->boolValue();
			  }

			  CCPoint offset = CCPointFromString(frameDict->valueForKey("offset")->getCString());
			  CCSize sourceSize = CCSizeFromString(frameDict->valueForKey("sourceSize")->getCString());
			  rect = frame;
		  } 
		  else if (format == 3)
		  {
			  CCSize spriteSize = CCSizeFromString(frameDict->valueForKey("spriteSize")->getCString());
			  CCPoint spriteOffset = CCPointFromString(frameDict->valueForKey("spriteOffset")->getCString());
			  CCSize spriteSourceSize = CCSizeFromString(frameDict->valueForKey("spriteSourceSize")->getCString());
			  CCRect textureRect = CCRectFromString(frameDict->valueForKey("textureRect")->getCString());
			  bool textureRotated = frameDict->valueForKey("textureRotated")->boolValue();
			  rect = textureRect;
		  }
		 rectMap.insert(std::pair<std::string,CCRect>(spriteFrameName,rect));
	}