bool SHSceneNode::initSceneNodeWithContentOfFile(const std::string& sceneFile) { #if COCOS2D_VERSION >= 0x00020000 std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(sceneFile.c_str()); LHDictionary* dictionary = (LHDictionary*)LHDictionary::createWithContentsOfFile(fullPath.c_str()); #else std::string fullPath = CCFileUtils::fullPathFromRelativePath(sceneFile.c_str()); LHDictionary* dictionary = (LHDictionary*)CCFileUtils::dictionaryWithContentsOfFile(fullPath.c_str()); #endif LHArray* sheetsList = dictionary->arrayForKey("SHEETS_INFO"); for(int i = 0; i < sheetsList->count(); ++i) { LHDictionary* dic = sheetsList->dictAtIndex(i); sheets->setObject(dic, dic->stringForKey("SheetName")); } LHArray* animList = dictionary->arrayForKey("SH_ANIMATIONS_LIST"); for(int i = 0; i< animList->count(); ++i) { LHDictionary* dic = animList->dictAtIndex(i); animations->setObject(dic, dic->stringForKey("UniqueName")); } return true; }
LHAnimationNode::LHAnimationNode(LHDictionary* dictionary, LHSprite* spr, std::string shScene){ frames= NULL; sprite= NULL; activeFrame= NULL; oldBatch= NULL; oldTexture= NULL; //this info will be from the spritehelper document //the info from the level is loaded by LHSprite shSceneName = std::string(shScene); uniqueName = std::string(dictionary->stringForKey("UniqueName")); sheetName = std::string(dictionary->stringForKey("SheetName")); restoreOriginalFrame = dictionary->boolForKey("RestoreOriginalFrame"); repetitions = dictionary->intForKey("Repetitions"); delayPerUnit= dictionary->floatForKey("DelayPerUnit"); loop = dictionary->boolForKey("Loop"); sprite = spr; oldRect = sprite->getTextureRect(); #if COCOS2D_VERSION >= 0x00020000 oldSpriteFrame = sprite->displayFrame(); #else oldSpriteFrame = sprite->displayedFrame(); #endif oldSpriteFrame->retain(); repetitionsPerformed = 0; currentFrame = 0; elapsedFrameTime = 0.0f; LHArray* framesInfo = dictionary->arrayForKey("Frames"); #if COCOS2D_VERSION >= 0x00020000 frames = CCArray::create(); #else frames = CCArray::array(); #endif frames->retain(); for(int i = 0; i< framesInfo->count(); ++i){ LHDictionary* frmInfo = framesInfo->dictAtIndex(i); frames->addObject(LHAnimationFrameInfo::frameWithDictionary(frmInfo, sprite)); } paused = true; }
bool LHCameraActivateProperty::initWithDictionary(LHDictionary* dict, LHAnimation* anim) { if(dict == NULL)return true; //special case for children subproperties if(LHAnimationProperty::initWithDictionary(dict, anim)) { LHArray* framesInfo = dict->arrayForKey("Frames"); for(int i = 0; i < framesInfo->count(); ++i) { LHDictionary* frmInfo = framesInfo->dictAtIndex(i); LHFrame* frm = LHFrame::createWithDictionary(frmInfo, this); addKeyFrame(frm); } return true; } return false; }
bool LHLayer::initWithDictionary(LHDictionary* dictionary){ isMainLayer = false; uniqueName = dictionary->stringForKey("UniqueName"); if(uniqueName == ""){ uniqueName = "UntitledLayer_" + stringFromInt(untitledLayersCount); ++untitledLayersCount; } setTag(dictionary->intForKey("Tag")); m_nZOrder = dictionary->intForKey("ZOrder"); loadUserCustomInfoFromDictionary(dictionary->dictForKey("CustomClassInfo")); LHArray* childrenInfo = dictionary->arrayForKey("Children"); for(int i = 0; i< childrenInfo->count(); ++i){ LHDictionary* childDict = childrenInfo->dictAtIndex(i); addChildFromDictionary(childDict); } return true; }
void LHShape::loadShapeFromDictionary(LHDictionary* dict, LHScene* scene) { _tile = dict->boolForKey("tileTexture"); _tileScale = dict->sizeForKey("tileScale"); Size size = this->getContentSize(); float alpha = dict->floatForKey("alpha"); LHDrawNode* shape = LHDrawNode::create(); this->addChild(shape); shape->setPosition(Point(size.width*0.5, size.height*0.5)); _drawNode = shape; Texture2D* texture = NULL; if(dict->objectForKey("relativeImagePath")) { std::string imgRelPath = dict->stringForKey("relativeImagePath"); std::string filename = LHUtils::getLastPathComponent(imgRelPath); std::string foldername = LHUtils::removeLastPathComponent(imgRelPath); foldername = LHUtils::getLastPathComponent(foldername); std::string imagePath = LHUtils::getImagePathWithFilename(filename, foldername, scene->getCurrentDeviceSuffix()); texture = Director::getInstance()->getTextureCache()->addImage(imagePath); if(texture){ Texture2D::TexParams texParams = {GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT}; if(_tile){ texParams = {GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_REPEAT, GL_REPEAT}; } texture->setTexParameters(texParams); _drawNode->setTexture(texture); } } LHArray* triangles = dict->arrayForKey("triangles"); Color3B overlay = dict->colorForKey("colorOverlay"); Color4F c4(overlay.r/255.0f, overlay.g/255.0f, overlay.b/255.0f, alpha/255.0f); LHArray* points = dict->arrayForKey("points"); for(int i = 0; i < points->count(); ++i) { LHDictionary* dict = points->dictAtIndex(i); Point pt = dict->pointForKey("point"); pt.y = -pt.y; _outline.push_back(pt); } __Array* shapeTriangles = __Array::create(); __Array* uvPoints = __Array::create(); __Array* colors = __Array::create(); float scaleX = this->getScaleX(); float scaleY = this->getScaleY(); Size imageSize; if(texture) imageSize = Size(texture->getPixelsWide(), texture->getPixelsHigh()); for(int i = 0; i < triangles->count(); i+=3) { LHDictionary* dictA = triangles->dictAtIndex(i); LHDictionary* dictB = triangles->dictAtIndex(i+1); LHDictionary* dictC = triangles->dictAtIndex(i+2); Color4F c4A; Color4F c4B; Color4F c4C; if(!texture){ c4A = c4; c4B = c4; c4C = c4; } else{ float alpha= dictA->floatForKey("alpha"); Color3B color = dictA->colorForKey("color"); c4A = Color4F(color.r/255.0f, color.g/255.0f, color.b/255.0f, alpha/255.0f); alpha = dictB->floatForKey("alpha"); color = dictB->colorForKey("color"); c4B = Color4F(color.r/255.0f, color.g/255.0f, color.b/255.0f, alpha/255.0f); alpha = dictC->floatForKey("alpha"); color = dictC->colorForKey("color"); c4C = Color4F(color.r/255.0f, color.g/255.0f, color.b/255.0f, alpha/255.0f); } Point posA = dictA->pointForKey("point"); posA.y = -posA.y; Point uvA = dictA->pointForKey("uv"); Point posB = dictB->pointForKey("point"); posB.y = -posB.y; Point uvB = dictB->pointForKey("uv"); Point posC = dictC->pointForKey("point"); posC.y = -posC.y; Point uvC = dictC->pointForKey("uv"); if(_tile && texture){ uvA.x = (posA.x/imageSize.width)*(_tileScale.width); uvA.y = -(posA.y/imageSize.height)*(_tileScale.height); uvB.x = (posB.x/imageSize.width)*(_tileScale.width); uvB.y = -(posB.y/imageSize.height)*(_tileScale.height); uvC.x = (posC.x/imageSize.width)*(_tileScale.width); uvC.y = -(posC.y/imageSize.height)*(_tileScale.height); } posA.x *= scaleX; posA.y *= scaleY; posB.x *= scaleX; posB.y *= scaleY; posC.x *= scaleX; posC.y *= scaleY; _triangles.push_back(posA); _triangles.push_back(posB); _triangles.push_back(posC); shapeTriangles->addObject(LHValue::create(posA)); shapeTriangles->addObject(LHValue::create(posB)); shapeTriangles->addObject(LHValue::create(posC)); if(!texture){ uvA = Point(); uvB = Point(); uvC = Point(); } uvPoints->addObject(LHValue::create(uvA)); uvPoints->addObject(LHValue::create(uvB)); uvPoints->addObject(LHValue::create(uvC)); colors->addObject(LHValue::create(c4A)); colors->addObject(LHValue::create(c4B)); colors->addObject(LHValue::create(c4C)); } _drawNode->setShapeTriangles(shapeTriangles, uvPoints, colors); }