示例#1
0
 public static CCTextureCache sharedTextureCache()
 {
     if (g_sharedTextureCache == null)
     {
         g_sharedTextureCache = new CCTextureCache();
     }
     return(g_sharedTextureCache);
 }
        /// <summary>
        /// Retruns ths shared instance of the cache
        /// </summary>
        public static CCTextureCache sharedTextureCache()
        {
            if (g_sharedTextureCache == null)
            {
                g_sharedTextureCache = new CCTextureCache();
            }

            return g_sharedTextureCache;
        }
示例#3
0
        public bool initWithFade(float fade, float minSeg, float stroke, ccColor3B color, string path)
        {
            if (path == null)
            {
                throw (new ArgumentNullException(path, "Path is required to create the texture2d."));
            }
            CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(path);

            return(initWithFade(fade, minSeg, stroke, color, texture));
        }
示例#4
0
        public bool initWithFile(string file, int capacity)
        {
            CCTexture2D cCTexture2D = CCTextureCache.sharedTextureCache().addImage(file);

            if (cCTexture2D == null)
            {
                return(false);
            }
            return(this.initWithTexture(cCTexture2D, capacity));
        }
示例#5
0
        public void addFrameWithFileName(string pszFileName)
        {
            CCTexture2D cCTexture2D = CCTextureCache.sharedTextureCache().addImage(pszFileName);
            CCRect      cCRect      = new CCRect(0f, 0f, 0f, 0f)
            {
                size = cCTexture2D.getContentSize()
            };
            CCSpriteFrame cCSpriteFrame = CCSpriteFrame.frameWithTexture(cCTexture2D, cCRect);

            this.m_pobFrames.Add(cCSpriteFrame);
        }
        public void addSpriteFramesWithFile(string plist, string textureFileName)
        {
            CCTexture2D cCTexture2D = CCTextureCache.sharedTextureCache().addImage(textureFileName);

            if (cCTexture2D != null)
            {
                this.addSpriteFramesWithFile(plist, cCTexture2D);
                return;
            }
            CCLog.Log("cocos2d: CCSpriteFrameCache: couldn't load texture file. File not found {0}", new object[] { textureFileName });
        }
示例#7
0
        /** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it.
         * Added to facilitate the migration from v0.8 to v0.9.
         */
        public void addFrameWithFileName(string pszFileName)
        {
            Texture pTexture = CCTextureCache.sharedTextureCache().addImage(pszFileName);
            //CCRect rect = CCRectZero;
            CCRect rect = new CCRect(0, 0, 0, 0);

            rect.Size = pTexture.ContentSize;
            CCSpriteFrame pFrame = CCSpriteFrame.frameWithTexture(pTexture, rect);

            //// m_pobFrames.addObject(pFrame);
            m_pobFrames.Add(pFrame);
        }
示例#8
0
        /// <summary>
        /// initializes a CCTMXLayer with a tileset info, a layer info and a map info
        /// </summary>
        public bool initWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo)
        {
            // XXX: is 35% a good estimate ?
            CCSize size = layerInfo.m_tLayerSize;
            float  totalNumberOfTiles = size.width * size.height;
            float  capacity           = totalNumberOfTiles * 0.35f + 1; // 35 percent is occupied ?

            CCTexture2D texture = null;

            if (tilesetInfo != null)
            {
                texture = CCTextureCache.sharedTextureCache().addImage(tilesetInfo.m_sSourceImage);
            }

            if (base.initWithTexture(texture, (int)capacity))
            {
                // layerInfo
                m_sLayerName  = layerInfo.m_sName;
                m_tLayerSize  = layerInfo.m_tLayerSize;
                m_pTiles      = layerInfo.m_pTiles;
                m_uMinGID     = layerInfo.m_uMinGID;
                m_uMaxGID     = layerInfo.m_uMaxGID;
                m_cOpacity    = layerInfo.m_cOpacity;
                m_pProperties = layerInfo.Properties;
                //			m_pProperties = CCStringToStringDictionary::dictionaryWithDictionary(layerInfo->getProperties());
                m_fContentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor;

                // tilesetInfo
                m_pTileSet = tilesetInfo;
                //CC_SAFE_RETAIN(m_pTileSet);

                // mapInfo
                m_tMapTileSize      = mapInfo.TileSize;
                m_uLayerOrientation = (CCTMXOrientatio)mapInfo.Orientation;

                // offset (after layer orientation is set);
                CCPoint offset = this.calculateLayerOffset(layerInfo.m_tOffset);
                this.position = offset;

                m_pAtlasIndexArray = ccCArray.ccCArrayNew((int)totalNumberOfTiles);

                this.contentSizeInPixels = new CCSize(m_tLayerSize.width * m_tMapTileSize.width, m_tLayerSize.height * m_tMapTileSize.height);
                m_tMapTileSize.width    /= m_fContentScaleFactor;
                m_tMapTileSize.height   /= m_fContentScaleFactor;

                m_bUseAutomaticVertexZ = false;
                m_nVertexZvalue        = 0;
                m_fAlphaFuncValue      = 0;
                return(true);
            }
            return(false);
        }
示例#9
0
        /// <summary>
        /// Adds multiple Sprite Frames from a plist file.
        /// A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
        /// If you want to use another texture, you should use the addSpriteFramesWithFile:texture method.
        /// </summary>
        public void addSpriteFramesWithFile(string pszPlist)
        {
            string pszPath = CCFileUtils.fullPathFromRelativePath(pszPlist);
            Dictionary <string, Object> dict = CCFileUtils.dictionaryWithContentsOfFile(pszPath);

            string texturePath = "";
            Dictionary <string, Object> metadataDict = dict.Keys.Contains("metadata") ?
                                                       (Dictionary <string, Object>)dict["metadata"] : null;

            if (metadataDict != null)
            {
                // C.A suggested to use metadataDict here instead of 'dict' to prevent the file not found error.
                // try to read  texture file name from meta data
                if (metadataDict.Keys.Contains("textureFileName"))
                {
                    texturePath = (valueForKey("textureFileName", metadataDict));
                }
            }

            if (!string.IsNullOrEmpty(texturePath))
            {
                // build texture path relative to plist file
                texturePath = CCFileUtils.fullPathFromRelativeFile(texturePath, pszPath);
            }
            else
            {
                // build texture path by replacing file path,case xna resource has no extension,so we move the image to images folder
                texturePath = pszPath;
                int index = pszPath.IndexOf("/");
                if (index < 0)
                {
                    index = pszPath.IndexOf(@"\");
                }
                if (index > 0)
                {
                    texturePath = pszPath.Substring(0, index) + "/images" + pszPath.Substring(index);
                }

                CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", texturePath);
            }

            CCTexture2D pTexture = CCTextureCache.sharedTextureCache().addImage(texturePath);

            if (pTexture != null)
            {
                addSpriteFramesWithDictionary(dict, pTexture);
            }
            else
            {
                CCLog.Log("cocos2d: CCSpriteFrameCache: Couldn't load texture");
            }
        }
示例#10
0
        /// <summary>
        /// Adds multiple Sprite Frames from a plist file. The texture will be associated with the created sprite frames.
        /// @since v0.99.5
        /// </summary>
        public void addSpriteFramesWithFile(string plist, string textureFileName)
        {
            Debug.Assert(textureFileName != null);
            CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(textureFileName);

            if (texture != null)
            {
                addSpriteFramesWithFile(plist, texture);
            }
            else
            {
                CCLog.Log("cocos2d: CCSpriteFrameCache: couldn't load texture file. File not found {0}", textureFileName);
            }
        }
示例#11
0
        /// <summary>
        /// initializes a TextureAtlas with a filename and with a certain capacity for Quads.
        /// The TextureAtlas capacity can be increased in runtime.
        /// WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
        /// </summary>
        public bool initWithFile(string file, int capacity)
        {
            // retained in property
            CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(file);

            if (texture != null)
            {
                return(initWithTexture(texture, capacity));
            }
            else
            {
                return(false);
            }
        }
示例#12
0
        public bool initWithFile(string fileName)
        {
            CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(fileName);

            if (texture != null)
            {
                CCRect rect = new CCRect
                {
                    size = texture.getContentSize()
                };
                return(this.initWithTexture(texture, rect));
            }
            return(false);
        }
示例#13
0
        /// <summary>
        /// Initializes an sprite with an image filename.
        /// The rect used will be the size of the image.
        /// The offset will be (0,0).
        /// </summary>
        public bool initWithFile(string fileName)
        {
            Debug.Assert(null != fileName, "fileName is null");

            CCTexture2D textureFromFile = CCTextureCache.sharedTextureCache().addImage(fileName);

            if (null != textureFromFile)
            {
                CCRect rect = new CCRect();
                rect.size = textureFromFile.getContentSize();
                return(initWithTexture(textureFromFile, rect));
            }

            return(false);
        }
示例#14
0
        public void addSpriteFramesWithFile(string pszPlist)
        {
            Dictionary <string, object> item;
            string str = CCFileUtils.fullPathFromRelativePath(pszPlist);
            Dictionary <string, object> strs = CCFileUtils.dictionaryWithContentsOfFile(str);
            string str1 = "";

            if (strs.Keys.Contains <string>("metadata"))
            {
                item = (Dictionary <string, object>)strs["metadata"];
            }
            else
            {
                item = null;
            }
            Dictionary <string, object> strs1 = item;

            if (strs1 != null && strs1.Keys.Contains <string>("textureFileName"))
            {
                str1 = this.valueForKey("textureFileName", strs1);
            }
            if (string.IsNullOrEmpty(str1))
            {
                str1 = str;
                int num = str.IndexOf("/");
                if (num < 0)
                {
                    num = str.IndexOf("\\");
                }
                if (num > 0)
                {
                    str1 = string.Concat(str.Substring(0, num), "/images", str.Substring(num));
                }
                CCLog.Log("cocos2d: CCSpriteFrameCache: Trying to use file {0} as texture", new object[] { str1 });
            }
            else
            {
                str1 = CCFileUtils.fullPathFromRelativeFile(str1, str);
            }
            CCTexture2D cCTexture2D = CCTextureCache.sharedTextureCache().addImage(str1);

            if (cCTexture2D == null)
            {
                CCLog.Log("cocos2d: CCSpriteFrameCache: Couldn't load texture");
                return;
            }
            this.addSpriteFramesWithDictionary(strs, cCTexture2D);
        }
示例#15
0
        /// <summary>
        /// Initializes an sprite with an image filename, and a rect.
        /// The offset will be (0,0).
        /// </summary>
        public bool initWithFile(string fileName, CCRect rect)
        {
            Debug.Assert(fileName != null);

            CCTexture2D pTexture = CCTextureCache.sharedTextureCache().addImage(fileName);

            if (pTexture != null)
            {
                return(initWithTexture(pTexture, rect));
            }

            // don't release here.
            // when load texture failed, it's better to get a "transparent" sprite then a crashed program
            // this->release();
            return(false);
        }
示例#16
0
        public bool initWithTilesetInfo(CCTMXTilesetInfo tilesetInfo, CCTMXLayerInfo layerInfo, CCTMXMapInfo mapInfo)
        {
            CCSize      mTLayerSize = layerInfo.m_tLayerSize;
            float       single      = mTLayerSize.width * mTLayerSize.height;
            float       single1     = single * 0.35f + 1f;
            CCTexture2D cCTexture2D = null;

            if (tilesetInfo != null)
            {
                cCTexture2D = CCTextureCache.sharedTextureCache().addImage(tilesetInfo.m_sSourceImage);
            }
            if (!base.initWithTexture(cCTexture2D, (int)single1))
            {
                return(false);
            }
            this.m_sLayerName          = layerInfo.m_sName;
            this.m_tLayerSize          = layerInfo.m_tLayerSize;
            this.m_pTiles              = layerInfo.m_pTiles;
            this.m_uMinGID             = layerInfo.m_uMinGID;
            this.m_uMaxGID             = layerInfo.m_uMaxGID;
            this.m_cOpacity            = layerInfo.m_cOpacity;
            this.m_pProperties         = layerInfo.Properties;
            this.m_fContentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor;
            this.m_pTileSet            = tilesetInfo;
            this.m_tMapTileSize        = mapInfo.TileSize;
            this.m_uLayerOrientation   = (CCTMXOrientatio)mapInfo.Orientation;
            this.position              = this.calculateLayerOffset(layerInfo.m_tOffset);
            this.m_pAtlasIndexArray    = ccCArray.ccCArrayNew((int)single);
            base.contentSizeInPixels   = new CCSize(this.m_tLayerSize.width * this.m_tMapTileSize.width, this.m_tLayerSize.height * this.m_tMapTileSize.height);
            CCSize mTMapTileSize = this.m_tMapTileSize;

            mTMapTileSize.width = mTMapTileSize.width / this.m_fContentScaleFactor;
            CCSize mFContentScaleFactor = this.m_tMapTileSize;

            mFContentScaleFactor.height = mFContentScaleFactor.height / this.m_fContentScaleFactor;
            this.m_bUseAutomaticVertexZ = false;
            this.m_nVertexZvalue        = 0;
            this.m_fAlphaFuncValue      = 0f;
            return(true);
        }
示例#17
0
 public bool initWithFile(string pszFileName)
 {
     return(this.initWithTexture(CCTextureCache.sharedTextureCache().addImage(pszFileName)));
 }
示例#18
0
        public bool initWithFile(string fileImage, int capacity)
        {
            CCTexture2D tex = CCTextureCache.sharedTextureCache().addImage(fileImage);

            return(this.initWithTexture(tex, capacity));
        }
示例#19
0
        /// <summary>
        /// initializes a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
        /// The capacity will be increased in 33% in runtime if it run out of space.
        /// The file will be loaded using the TextureMgr.
        /// </summary>
        public bool initWithFile(string fileImage, int capacity)
        {
            Texture pTexture2D = CCTextureCache.sharedTextureCache().addImage(fileImage);

            return(initWithTexture(pTexture2D, capacity));
        }
示例#20
0
 /// <summary>
 /// purges the cache. It releases the retained instance.
 /// @since v0.99.0
 /// </summary>
 public static void purgeSharedTextureCache()
 {
     g_sharedTextureCache = null;
 }
示例#21
0
 public static void purgeSharedTextureCache()
 {
     g_sharedTextureCache = null;
 }
示例#22
0
        public bool initWithFile(string fileName, CCRect rect)
        {
            CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage(fileName);

            return((texture != null) && this.initWithTexture(texture, rect));
        }
示例#23
0
        public bool initWithDictionary(Dictionary <string, object> dictionary)
        {
            bool flag = false;
            int  num  = ccUtils.ccParseInt(this.ChangeToZeroIfNull(this.valueForKey("maxParticles", dictionary)));

            if (this.initWithTotalParticles((uint)num))
            {
                this.m_fAngle           = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("angle", dictionary)));
                this.m_fAngleVar        = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("angleVariance", dictionary)));
                this.m_fDuration        = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("duration", dictionary)));
                this.m_tBlendFunc.src   = ccUtils.ccParseInt(this.ChangeToZeroIfNull(this.valueForKey("blendFuncSource", dictionary)));
                this.m_tBlendFunc.dst   = ccUtils.ccParseInt(this.ChangeToZeroIfNull(this.valueForKey("blendFuncDestination", dictionary)));
                this.m_tStartColor.r    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorRed", dictionary)));
                this.m_tStartColor.g    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorGreen", dictionary)));
                this.m_tStartColor.b    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorBlue", dictionary)));
                this.m_tStartColor.a    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorAlpha", dictionary)));
                this.m_tStartColorVar.r = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorVarianceRed", dictionary)));
                this.m_tStartColorVar.g = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorVarianceGreen", dictionary)));
                this.m_tStartColorVar.b = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorVarianceBlue", dictionary)));
                this.m_tStartColorVar.a = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startColorVarianceAlpha", dictionary)));
                this.m_tEndColor.r      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorRed", dictionary)));
                this.m_tEndColor.g      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorGreen", dictionary)));
                this.m_tEndColor.b      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorBlue", dictionary)));
                this.m_tEndColor.a      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorAlpha", dictionary)));
                this.m_tEndColorVar.r   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorVarianceRed", dictionary)));
                this.m_tEndColorVar.g   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorVarianceGreen", dictionary)));
                this.m_tEndColorVar.b   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorVarianceBlue", dictionary)));
                this.m_tEndColorVar.a   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishColorVarianceAlpha", dictionary)));
                this.m_fStartSize       = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startParticleSize", dictionary)));
                this.m_fStartSizeVar    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("startParticleSizeVariance", dictionary)));
                this.m_fEndSize         = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishParticleSize", dictionary)));
                this.m_fEndSizeVar      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("finishParticleSizeVariance", dictionary)));
                float x = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("sourcePositionx", dictionary)));
                float y = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("sourcePositiony", dictionary)));
                this.position        = new CCPoint(x, y);
                this.m_tPosVar.x     = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("sourcePositionVariancex", dictionary)));
                this.m_tPosVar.y     = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("sourcePositionVariancey", dictionary)));
                this.m_fStartSpin    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotationStart", dictionary)));
                this.m_fStartSpinVar = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotationStartVariance", dictionary)));
                this.m_fEndSpin      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotationEnd", dictionary)));
                this.m_fEndSpinVar   = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotationEndVariance", dictionary)));
                this.m_nEmitterMode  = ccUtils.ccParseInt(this.ChangeToZeroIfNull(this.valueForKey("emitterType", dictionary)), NumberStyles.AllowDecimalPoint);
                if (this.m_nEmitterMode == 0)
                {
                    this.modeA.gravity.x = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("gravityx", dictionary)));
                    this.modeA.gravity.y = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("gravityy", dictionary)));
                    this.modeA.speed     = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("speed", dictionary)));
                    this.modeA.speedVar  = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("speedVariance", dictionary)));
                    string str = this.valueForKey("radialAcceleration", dictionary);
                    this.modeA.radialAccel = (str != null) ? ccUtils.ccParseFloat(this.ChangeToZeroIfNull(str)) : 0f;
                    str = this.valueForKey("radialAccelVariance", dictionary);
                    this.modeA.radialAccelVar = (str != null) ? ccUtils.ccParseFloat(this.ChangeToZeroIfNull(str)) : 0f;
                    str = this.valueForKey("tangentialAcceleration", dictionary);
                    this.modeA.tangentialAccel = (str != null) ? ccUtils.ccParseFloat(this.ChangeToZeroIfNull(str)) : 0f;
                    str = this.valueForKey("tangentialAccelVariance", dictionary);
                    this.modeA.tangentialAccelVar = (str != null) ? ccUtils.ccParseFloat(this.ChangeToZeroIfNull(str)) : 0f;
                }
                else
                {
                    if (this.m_nEmitterMode != 1)
                    {
                        return(flag);
                    }
                    this.modeB.startRadius        = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("maxRadius", dictionary)));
                    this.modeB.startRadiusVar     = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("maxRadiusVariance", dictionary)));
                    this.modeB.endRadius          = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("minRadius", dictionary)));
                    this.modeB.endRadiusVar       = 0f;
                    this.modeB.rotatePerSecond    = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotatePerSecond", dictionary)));
                    this.modeB.rotatePerSecondVar = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("rotatePerSecondVariance", dictionary)));
                }
                this.m_fLife         = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("particleLifespan", dictionary)));
                this.m_fLifeVar      = ccUtils.ccParseFloat(this.ChangeToZeroIfNull(this.valueForKey("particleLifespanVariance", dictionary)));
                this.m_fEmissionRate = ((float)this.m_uTotalParticles) / this.m_fLife;
                string      pszFilename = this.valueForKey("textureFileName", dictionary);
                string      fileimage   = CCFileUtils.fullPathFromRelativeFile(pszFilename, this.m_sPlistFile);
                CCTexture2D textured    = null;
                if (pszFilename.Length > 0)
                {
                    bool isPopupNotify = CCFileUtils.IsPopupNotify;
                    CCFileUtils.IsPopupNotify = false;
                    textured = CCTextureCache.sharedTextureCache().addImage(fileimage);
                    CCFileUtils.IsPopupNotify = isPopupNotify;
                }
                if (textured == null)
                {
                    throw new NotImplementedException();
                }
                this.m_pTexture = textured;
                if (this.m_pTexture != null)
                {
                    flag = true;
                }
            }
            return(flag);
        }