Exemplo n.º 1
0
        public static CCGridBase gridWithSize(ccGridSize gridSize, Texture texture, bool flipped)
        {
            CCGridBase pGridBase = new CCGridBase();

            if (pGridBase.initWithSize(gridSize, texture, flipped))
            {
                return pGridBase;
            }

            return null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a CCSpriteFrame with a texture, rect in points.
        /// It is assumed that the frame was not trimmed.
        /// </summary>
        public static CCSpriteFrame frameWithTexture(Texture pobTexture, CCRect rect)
        {
            CCSpriteFrame pSpriteFrame = new CCSpriteFrame(); ;
            pSpriteFrame.initWithTexture(pobTexture, rect);

            return pSpriteFrame;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.
        /// The originalSize is the size in points of the frame before being trimmed.
        /// </summary>
        public bool initWithTexture(Texture pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize)
        {
            m_pobTexture = pobTexture;

            m_obRectInPixels = rect;
            m_obRect = ccMacros.CC_RECT_PIXELS_TO_POINTS(rect);
            m_bRotated = rotated;
            m_obOffsetInPixels = offset;

            m_obOriginalSizeInPixels = originalSize;

            return true;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a CCSpriteFrame with a texture, rect in points.
 /// It is assumed that the frame was not trimmed.
 /// </summary>
 public bool initWithTexture(Texture pobTexture, CCRect rect)
 {
     CCRect rectInPixels = ccMacros.CC_RECT_POINTS_TO_PIXELS(rect);
     return initWithTexture(pobTexture, rectInPixels, false, new CCPoint(0, 0), rectInPixels.Size);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.
        /// The originalSize is the size in points of the frame before being trimmed.
        /// </summary>
        public static CCSpriteFrame frameWithTexture(Texture pobTexture, CCRect rect, bool rotated, CCPoint offset, CCSize originalSize)
        {
            CCSpriteFrame pSpriteFrame = new CCSpriteFrame();
            pSpriteFrame.initWithTexture(pobTexture, rect, rotated, offset, originalSize);

            return pSpriteFrame;
        }
Exemplo n.º 6
0
 public CCParticleSystem()
 {
     m_sPlistFile = "";
     m_fElapsed = 0;
     m_pParticles = null;
     m_fEmitCounter = 0;
     m_uParticleIdx = 0;
     #if CC_ENABLE_PROFILERS
     m_pProfilingTimer = NULL;
     #endif
     m_bIsActive = true;
     m_uParticleCount = 0;
     m_fDuration = 0;
     m_tSourcePosition = new CCPoint(0, 0);
     m_tPosVar = new CCPoint(0, 0);
     m_fLife = 0;
     m_fLifeVar = 0;
     m_fAngle = 0;
     m_fAngleVar = 0;
     m_fStartSize = 0;
     m_fStartSizeVar = 0;
     m_fEndSize = 0;
     m_fEndSizeVar = 0;
     m_fStartSpin = 0;
     m_fStartSpinVar = 0;
     m_fEndSpin = 0;
     m_fEndSpinVar = 0;
     m_fEmissionRate = 0;
     m_uTotalParticles = 0;
     m_pTexture = null;
     m_bIsBlendAdditive = false;
     m_ePositionType = eParticlePositionType.kCCPositionTypeFree;
     m_bIsAutoRemoveOnFinish = false;
     m_nEmitterMode = (int)eParticleMode.kCCParticleModeGravity;
     modeA = new sModeA();
     modeA.gravity = new CCPoint(0, 0);
     modeA.speed = 0;
     modeA.speedVar = 0;
     modeA.tangentialAccel = 0;
     modeA.tangentialAccelVar = 0;
     modeA.radialAccel = 0;
     modeA.radialAccelVar = 0;
     modeB = new sModeB();
     modeB.startRadius = 0;
     modeB.startRadiusVar = 0;
     modeB.endRadius = 0;
     modeB.endRadiusVar = 0;
     modeB.rotatePerSecond = 0;
     modeB.rotatePerSecondVar = 0;
     m_tBlendFunc = new ccBlendFunc();
     m_tBlendFunc.src = 0;// CC_BLEND_SRC;
     m_tBlendFunc.dst = 0x0303;// CC_BLEND_DST;
 }
Exemplo n.º 7
0
        /** initializes a CCQuadParticleSystem from a CCDictionary.
        @since v0.99.3
        */
        bool initWithDictionary(Dictionary<string, object> dictionary)
        {
            bool bRet = false;
            string buffer;
            string deflated;
            Texture image;
            do
            {
                int maxParticles = ccUtils.ccParseInt(ChangeToZeroIfNull(valueForKey("maxParticles", dictionary)));
                // self, not super
                if (initWithTotalParticles((uint)maxParticles))
                {
                    // angle
                    m_fAngle = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("angle", dictionary)));
                    m_fAngleVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("angleVariance", dictionary)));

                    // duration
                    m_fDuration = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("duration", dictionary)));

                    // blend function
                    m_tBlendFunc.src = ccUtils.ccParseInt(ChangeToZeroIfNull(valueForKey("blendFuncSource", dictionary)));
                    m_tBlendFunc.dst = ccUtils.ccParseInt(ChangeToZeroIfNull(valueForKey("blendFuncDestination", dictionary)));

                    // color
                    m_tStartColor.r = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startColorRed", dictionary)));
                    m_tStartColor.g = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startColorGreen", dictionary)));
                    m_tStartColor.b = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startColorBlue", dictionary)));
                    m_tStartColor.a = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startColorAlpha", dictionary)));

                    m_tStartColorVar.r = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startColorVarianceRed", dictionary)));
                    m_tStartColorVar.g = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startColorVarianceGreen", dictionary)));
                    m_tStartColorVar.b = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startColorVarianceBlue", dictionary)));
                    m_tStartColorVar.a = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startColorVarianceAlpha", dictionary)));

                    m_tEndColor.r = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishColorRed", dictionary)));
                    m_tEndColor.g = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishColorGreen", dictionary)));
                    m_tEndColor.b = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishColorBlue", dictionary)));
                    m_tEndColor.a = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishColorAlpha", dictionary)));

                    m_tEndColorVar.r = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishColorVarianceRed", dictionary)));
                    m_tEndColorVar.g = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishColorVarianceGreen", dictionary)));
                    m_tEndColorVar.b = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishColorVarianceBlue", dictionary)));
                    m_tEndColorVar.a = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishColorVarianceAlpha", dictionary)));

                    // particle size
                    m_fStartSize = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startParticleSize", dictionary)));
                    m_fStartSizeVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("startParticleSizeVariance", dictionary)));
                    m_fEndSize = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishParticleSize", dictionary)));
                    m_fEndSizeVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("finishParticleSizeVariance", dictionary)));

                    // position
                    float x = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("sourcePositionx", dictionary)));
                    float y = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("sourcePositiony", dictionary)));
                    this.Position = new CCPoint(x, y);
                    m_tPosVar.X = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("sourcePositionVariancex", dictionary)));
                    m_tPosVar.Y = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("sourcePositionVariancey", dictionary)));

                    // Spinning
                    m_fStartSpin = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("rotationStart", dictionary)));
                    m_fStartSpinVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("rotationStartVariance", dictionary)));
                    m_fEndSpin = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("rotationEnd", dictionary)));
                    m_fEndSpinVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("rotationEndVariance", dictionary)));

                    m_nEmitterMode = ccUtils.ccParseInt(ChangeToZeroIfNull(valueForKey("emitterType", dictionary)), NumberStyles.AllowDecimalPoint);

                    // Mode A: Gravity + tangential accel + radial accel
                    if (m_nEmitterMode == (int)eParticleMode.kCCParticleModeGravity)
                    {
                        // gravity
                        modeA.gravity.X = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("gravityx", dictionary)));
                        modeA.gravity.Y = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("gravityy", dictionary)));

                        // speed
                        modeA.speed = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("speed", dictionary)));
                        modeA.speedVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("speedVariance", dictionary)));

                        string pszTmp;
                        // radial acceleration
                        pszTmp = valueForKey("radialAcceleration", dictionary);
                        modeA.radialAccel = (pszTmp != null) ? ccUtils.ccParseFloat(ChangeToZeroIfNull(pszTmp)) : 0;

                        pszTmp = valueForKey("radialAccelVariance", dictionary);
                        modeA.radialAccelVar = (pszTmp != null) ? ccUtils.ccParseFloat(ChangeToZeroIfNull(pszTmp)) : 0;

                        // tangential acceleration
                        pszTmp = valueForKey("tangentialAcceleration", dictionary);
                        modeA.tangentialAccel = (pszTmp != null) ? ccUtils.ccParseFloat(ChangeToZeroIfNull(pszTmp)) : 0;

                        pszTmp = valueForKey("tangentialAccelVariance", dictionary);
                        modeA.tangentialAccelVar = (pszTmp != null) ? ccUtils.ccParseFloat(ChangeToZeroIfNull(pszTmp)) : 0;
                    }

                    // or Mode B: radius movement
                    else if (m_nEmitterMode == (int)eParticleMode.kCCParticleModeRadius)
                    {
                        modeB.startRadius = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("maxRadius", dictionary)));
                        modeB.startRadiusVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("maxRadiusVariance", dictionary)));
                        modeB.endRadius = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("minRadius", dictionary)));
                        modeB.endRadiusVar = 0;
                        modeB.rotatePerSecond = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("rotatePerSecond", dictionary)));
                        modeB.rotatePerSecondVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("rotatePerSecondVariance", dictionary)));

                    }
                    else
                    {
                        Debug.Assert(false, "Invalid emitterType in config file");
                        break;
                    }

                    // life span
                    m_fLife = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("particleLifespan", dictionary)));
                    m_fLifeVar = ccUtils.ccParseFloat(ChangeToZeroIfNull(valueForKey("particleLifespanVariance", dictionary)));

                    // emission Rate
                    m_fEmissionRate = m_uTotalParticles / m_fLife;

                    // texture
                    // Try to get the texture from the cache
                    string textureName = valueForKey("textureFileName", dictionary);
                    //string fullpath = CCFileUtils.fullPathFromRelativeFile(textureName, m_sPlistFile);

                    Texture tex = null;

                    if (textureName.Length > 0)
                    {
                        //// set not pop-up message box when load image failed
                        //bool bNotify = CCFileUtils.IsPopupNotify;
                        //CCFileUtils.IsPopupNotify = false;
                        //tex = CCTextureCache.sharedTextureCache().addImage(fullpath);

                        //// reset the value of UIImage notify
                        //CCFileUtils.IsPopupNotify = bNotify;

                        //todo check

                        //tex = new Texture("Content/" + textureName);
                        tex = CCTextureCache.sharedTextureCache().addImage(textureName);
                    }

                    if (null != tex)
                    {
                        m_pTexture = tex;
                    }
                    else
                    {
                        throw new NotImplementedException();

                        //    string textureData = valueForKey("textureImageData", dictionary);
                        //    Debug.Assert(textureData != null);

                        //    int dataLen = textureData.Length;
                        //    if (dataLen != 0)
                        //    {
                        //        // if it fails, try to get it from the base64-gzipped data
                        //        int decodeLen = base64Decode(textureData, (uint)dataLen, buffer);
                        //        Debug.Assert(buffer != null, "CCParticleSystem: error decoding textureImageData");
                        //        if (buffer == null)
                        //            break;

                        //        int deflatedLen = ZipUtils.ccInflateMemory(buffer, decodeLen, &deflated);
                        //        Debug.Assert(deflated != null, "CCParticleSystem: error ungzipping textureImageData");
                        //        if (deflated == null)
                        //            break;

                        //        image = new CCTexture2D();
                        //        bool isOK = image.initWithImageData(deflated, deflatedLen);
                        //        Debug.Assert(isOK, "CCParticleSystem: error init image with Data");
                        //        if (!isOK)
                        //            break;

                        //        m_pTexture = CCTextureCache.sharedTextureCache().addUIImage(image, fullpath);
                        //    }
                    }
                    Debug.Assert(m_pTexture != null, "CCParticleSystem: error loading the texture");

                    if (m_pTexture == null)
                        break;
                    bRet = true;
                }
            } while (false);
            return bRet;
        }
Exemplo n.º 8
0
        /// <summary>
        /// creates a CCSpriteBatchNode with a texture2d and capacity of children.
        /// The capacity will be increased in 33% in runtime if it run out of space.
        /// </summary>
        public static CCSpriteBatchNode batchNodeWithTexture(Texture tex, int capacity)
        {
            CCSpriteBatchNode batchNode = new CCSpriteBatchNode();
            batchNode.initWithTexture(tex, capacity);

            return batchNode;
        }
Exemplo n.º 9
0
 /** Adds a frame with a texture and a rect. Internally it will create a CCSpriteFrame and it will add it.
 Added to facilitate the migration from v0.8 to v0.9.
 */
 public void addFrameWithTexture(Texture pobTexture, CCRect rect)
 {
     CCSpriteFrame pFrame = CCSpriteFrame.frameWithTexture(pobTexture, rect);
     //// m_pobFrames.addObject(pFrame);
     m_pobFrames.Add(pFrame);
     throw new NotFiniteNumberException();
 }
Exemplo n.º 10
0
        public bool initWithSize(ccGridSize gridSize)
        {
            Director pDirector = Director.SharedDirector;
            CCSize s = pDirector.DisplaySize;

            ulong POTWide = ccNextPOT((uint)s.Width);
            ulong POTHigh = ccNextPOT((uint)s.Height);

            // we only use rgba8888
            Texture pTexture = new Texture((int)POTWide, (int)POTHigh);

            if (pTexture == null)
            {
                System.Diagnostics.Debug.WriteLine("cocos2d: CCGrid: error creating texture");
                return false;
            }

            initWithSize(gridSize, pTexture, false);

            return true;
        }
Exemplo n.º 11
0
        public bool initWithSize(ccGridSize gridSize, Texture pTexture, bool bFlipped)
        {
            bool bRet = true;

            m_bActive = false;
            m_nReuseGrid = 0;
            m_sGridSize = gridSize;

            m_pTexture = pTexture;

            m_bIsTextureFlipped = bFlipped;

            CCSize texSize = m_pTexture.ContentSize;
            m_obStep = new CCPoint();
            m_obStep.X = texSize.Width / (float)m_sGridSize.x;
            m_obStep.Y = texSize.Height / (float)m_sGridSize.y;

            m_pGrabber = new CCGrabber();
            if (m_pGrabber != null)
            {
                m_pGrabber.grab(ref m_pTexture);
            }
            else
            {
                bRet = false;
            }

            calculateVertexPoints();

            return bRet;
        }