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 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;
}
Beispiel #4
0
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;
}
Beispiel #5
0
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);
}
void LHBezierNode::initPathPointsFromDictionary(LHDictionary* bezierDict)
{	
    LHArray* curvesInShape = bezierDict->objectForKey("Curves")->arrayValue();    
    int MAX_STEPS = 25;    
	CCPoint conv = LHSettings::sharedInstance()->convertRatio();
	
	int i = 0;
    for(int j = 0; j < curvesInShape->count(); ++j)
    {
        LHDictionary* curvDict = curvesInShape->objectAtIndex(j)->dictValue();
        
        CCPoint endCtrlPt   = LHPointFromString(curvDict->objectForKey("EndControlPoint")->stringValue());
        CCPoint startCtrlPt = LHPointFromString(curvDict->objectForKey("StartControlPoint")->stringValue());
        CCPoint endPt       = LHPointFromString(curvDict->objectForKey("EndPoint")->stringValue());
        CCPoint startPt     = LHPointFromString(curvDict->objectForKey("StartPoint")->stringValue());
		
		CCPoint pos_offset = LHSettings::sharedInstance()->possitionOffset();
        
		if(!isLine)
        {
            for(float t = 0; t <= (1 + (1.0f / MAX_STEPS)); t += 1.0f / MAX_STEPS)
            {
                CCPoint vPoint = LHBezierNode::pointOnCurve(startPt,
                                                            startCtrlPt,
                                                            endCtrlPt,
                                                            endPt,
                                                            t);
				
                vPoint = ccp(vPoint.x*conv.x, winSize.height - vPoint.y*conv.y);
                
                vPoint.x += pos_offset.x;
                vPoint.y -= pos_offset.y;
                                
                pathPoints.push_back(vPoint);
            }
			
            pathPoints.pop_back();
        }
        else
        {
            CCPoint sPoint =  ccp(startPt.x*conv.x, 
                                  winSize.height - startPt.y*conv.y);
            
            sPoint.x += pos_offset.x;
            sPoint.y -= pos_offset.y;
            
            pathPoints.push_back(sPoint);

            
            if(i == curvesInShape->count()-1)
            {
                CCPoint ePoint = ccp(endPt.x*conv.x,
                                     winSize.height - endPt.y*conv.y);
                ePoint.x += pos_offset.x;
                ePoint.y -= pos_offset.y;
                
                pathPoints.push_back(ePoint);
            }
            ++i;            
        }
	}		
}
void LHBezierNode::initTileVerticesFromDictionary(LHDictionary* bezierDict)
{
    float scale = CCDirector::sharedDirector()->getContentScaleFactor();
    
	CCPoint convert = LHSettings::sharedInstance()->convertRatio();
	LHArray* fixtures = bezierDict->arrayForKey("TileVertices");
    
    if(NULL != fixtures)
    {
        for(int i = 0; i < fixtures->count(); ++i)
        {
            LHArray* fix = fixtures->objectAtIndex(i)->arrayValue();
        
            std::vector<CCPoint> triagle;
        
            for(int j = 0; j < fix->count(); ++j)
            {
                CCPoint point = LHPointFromString(fix->objectAtIndex(j)->stringValue());
			
                CCPoint pos_offset = LHSettings::sharedInstance()->possitionOffset();
            
                point.x = point.x* convert.x;
                point.y = winSize.height - point.y*convert.y;
			
                //point.x*=scale;
                //point.y*=scale;

                point.x += pos_offset.x;
                point.y -= pos_offset.y;

                triagle.push_back(point);
            }
            trianglesHolder.push_back(triagle);
        }	
	}
	
	if(isVisible)
	{
		LHArray* curvesInShape = bezierDict->objectForKey("Curves")->arrayValue();
		
		int MAX_STEPS = 25;
		
        for(int i = 0; i < curvesInShape->count(); ++i)
		{
            LHDictionary* curvDict = curvesInShape->objectAtIndex(i)->dictValue();
            
			CCPoint endCtrlPt   = LHPointFromString(curvDict->objectForKey("EndControlPoint")->stringValue());
			CCPoint startCtrlPt = LHPointFromString(curvDict->objectForKey("StartControlPoint")->stringValue());
			CCPoint endPt       = LHPointFromString(curvDict->objectForKey("EndPoint")->stringValue());
			CCPoint startPt     = LHPointFromString(curvDict->objectForKey("StartPoint")->stringValue());
			
            CCPoint pos_offset = LHSettings::sharedInstance()->possitionOffset();
                        
			if(!isLine)
			{
				CCPoint prevPoint;
				bool firstPt = true;
				
				for(float t = 0; t <= (1 + (1.0f / MAX_STEPS)); t += 1.0f / MAX_STEPS)
				{
					CCPoint vPoint = LHBezierNode::pointOnCurve(startPt,
                                                                startCtrlPt,
                                                                endCtrlPt,
                                                                endPt,
                                                                t);
					
					if(!firstPt)
					{
						CCPoint pt1 = CCPointMake(prevPoint.x*convert.x, 
												  winSize.height - prevPoint.y*convert.y);
						CCPoint pt2 = CCPointMake(vPoint.x*convert.x, 
												  winSize.height - vPoint.y*convert.y);
						
                        pt1.x *=scale;
                        pt1.y *=scale;
                        
                        pt2.x *=scale;
                        pt2.y *=scale;
                        
                        pt1.x += pos_offset.x;
                        pt1.y -= pos_offset.y;
                        
                        pt2.x += pos_offset.x;
                        pt2.y -= pos_offset.y;
                        
                        linesHolder.push_back(pt1);
                        linesHolder.push_back(pt2);
					}
					prevPoint = vPoint;
					firstPt = false;					
				}
			}
			else
			{
				
				CCPoint pos1 = CCPointMake(startPt.x*convert.x, 
										   winSize.height - startPt.y*convert.y);
				CCPoint pos2 = CCPointMake(endPt.x*convert.x, 
										   winSize.height - endPt.y*convert.y);
				
                pos1.x*=scale;
                pos1.y*=scale;
                
                pos2.x*=scale;
                pos2.y*=scale;
                
                pos1.x += pos_offset.x;
                pos1.y -= pos_offset.y;
                
                pos2.x += pos_offset.x;
                pos2.y -= pos_offset.y;
                
                linesHolder.push_back(pos1);
                linesHolder.push_back(pos2);				
			}
		}
	}
}