public override void draw()
        {
            base.draw();
            BlendState blendState = CCApplication.sharedApplication().GraphicsDevice.BlendState;
            BlendState alphaBlend = BlendState.AlphaBlend;

            if (base.IsBlendAdditive)
            {
                alphaBlend = BlendState.Additive;
            }
            CCApplication.sharedApplication().spriteBatch.Begin(SpriteSortMode.Deferred, alphaBlend);
            for (int i = 0; i < base.ParticleCount; i++)
            {
                CCParticle particle = base.m_pParticles[i];
                CCPoint    obPoint  = CCPointExtension.ccpAdd(CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), base.nodeToWorldTransform()), new CCPoint(this.m_pQuads[i].bl.vertices.x, this.m_pQuads[i].bl.vertices.y));
                obPoint = CCDirector.sharedDirector().convertToUI(obPoint);
                Vector2 position = new Vector2(obPoint.x, obPoint.y);
                Color   color    = new Color(particle.color.r, particle.color.g, particle.color.b, particle.color.a);
                float   scale    = 1f;
                if (this.Texture.getTexture2D().Width > this.Texture.getTexture2D().Height)
                {
                    scale = particle.size / ((float)this.Texture.getTexture2D().Height);
                }
                else
                {
                    scale = particle.size / ((float)this.Texture.getTexture2D().Width);
                }
                float     rotation        = particle.rotation;
                Vector2   origin          = new Vector2((float)(this.Texture.getTexture2D().Width / 2), (float)(this.Texture.getTexture2D().Height / 2));
                Rectangle?sourceRectangle = null;
                CCApplication.sharedApplication().spriteBatch.Draw(this.Texture.getTexture2D(), position, sourceRectangle, color, rotation, origin, scale, SpriteEffects.None, 0f);
            }
            CCApplication.sharedApplication().spriteBatch.End();
            CCApplication.sharedApplication().GraphicsDevice.BlendState = blendState;
        }
Exemple #2
0
        public override CCFiniteTimeAction reverse()
        {
            ccBezierConfig _ccBezierConfig = new ccBezierConfig();

            _ccBezierConfig.endPosition    = CCPointExtension.ccpNeg(this.m_sConfig.endPosition);
            _ccBezierConfig.controlPoint_1 = CCPointExtension.ccpAdd(this.m_sConfig.controlPoint_2, CCPointExtension.ccpNeg(this.m_sConfig.endPosition));
            _ccBezierConfig.controlPoint_2 = CCPointExtension.ccpAdd(this.m_sConfig.controlPoint_1, CCPointExtension.ccpNeg(this.m_sConfig.endPosition));
            return(CCBezierBy.actionWithDuration(this.m_fDuration, _ccBezierConfig));
        }
Exemple #3
0
        public override CCFiniteTimeAction reverse()
        {
            ccBezierConfig r;

            r.endPosition    = CCPointExtension.ccpNeg(m_sConfig.endPosition);
            r.controlPoint_1 = CCPointExtension.ccpAdd(m_sConfig.controlPoint_2, CCPointExtension.ccpNeg(m_sConfig.endPosition));
            r.controlPoint_2 = CCPointExtension.ccpAdd(m_sConfig.controlPoint_1, CCPointExtension.ccpNeg(m_sConfig.endPosition));

            CCBezierBy action = CCBezierBy.actionWithDuration(m_fDuration, r);

            return(action);
        }
Exemple #4
0
        public CCPoint convertToWorldSpaceAR(CCPoint nodePoint)
        {
            CCPoint tAnchorPointInPixels;

            if (CCDirector.sharedDirector().ContentScaleFactor == 1f)
            {
                tAnchorPointInPixels = this.m_tAnchorPointInPixels;
            }
            else
            {
                tAnchorPointInPixels = CCPointExtension.ccpMult(this.m_tAnchorPointInPixels, 1f / CCDirector.sharedDirector().ContentScaleFactor);
            }
            CCPoint point2 = CCPointExtension.ccpAdd(nodePoint, tAnchorPointInPixels);

            return(this.convertToWorldSpace(point2));
        }
Exemple #5
0
        /// <summary>
        /// Converts a local Point to world space coordinates.The result is in Points.
        /// treating the returned/received node point as anchor relative.
        /// </summary>
        public CCPoint ConvertToWorldSpaceAR(CCPoint nodePoint)
        {
            CCPoint anchorInPoints;

            if (Director.SharedDirector.ContentScaleFactor == 1)
            {
                anchorInPoints = AnchorPointInPixels;
            }
            else
            {
                anchorInPoints = CCPointExtension.ccpMult(AnchorPointInPixels, 1 / Director.SharedDirector.ContentScaleFactor);
            }

            CCPoint pt = CCPointExtension.ccpAdd(nodePoint, anchorInPoints);

            return(ConvertToWorldSpace(pt));
        }
Exemple #6
0
 public override void update(float dt)
 {
     if (this.m_pTarget != null)
     {
         float single         = 0f;
         float controlPoint1  = this.m_sConfig.controlPoint_1.x;
         float controlPoint2  = this.m_sConfig.controlPoint_2.x;
         float mSConfig       = this.m_sConfig.endPosition.x;
         float single1        = 0f;
         float controlPoint11 = this.m_sConfig.controlPoint_1.y;
         float controlPoint21 = this.m_sConfig.controlPoint_2.y;
         float mSConfig1      = this.m_sConfig.endPosition.y;
         float single2        = this.bezierat(single, controlPoint1, controlPoint2, mSConfig, dt);
         float single3        = this.bezierat(single1, controlPoint11, controlPoint21, mSConfig1, dt);
         this.m_pTarget.position = CCPointExtension.ccpAdd(this.m_startPosition, CCPointExtension.ccp(single2, single3));
     }
 }
Exemple #7
0
        public override void update(float dt)
        {
            if (m_pTarget != null)
            {
                float xa = 0;
                float xb = m_sConfig.controlPoint_1.x;
                float xc = m_sConfig.controlPoint_2.x;
                float xd = m_sConfig.endPosition.x;

                float ya = 0;
                float yb = m_sConfig.controlPoint_1.y;
                float yc = m_sConfig.controlPoint_2.y;
                float yd = m_sConfig.endPosition.y;

                float x = bezierat(xa, xb, xc, xd, dt);
                float y = bezierat(ya, yb, yc, yd, dt);
                m_pTarget.position = CCPointExtension.ccpAdd(m_startPosition, CCPointExtension.ccp(x, y));
            }
        }
        public override void draw()
        {
            base.draw();

            BlendState oldBlendState = Application.SharedApplication.GraphicsDevice.BlendState;

            BlendState eBlendState = BlendState.AlphaBlend;

            if (this.IsBlendAdditive)
            {
                eBlendState = BlendState.Additive;
            }

            Application.SharedApplication.SpriteBatch.Begin(SpriteSortMode.Deferred, eBlendState);
            for (int i = 0; i < this.ParticleCount; i++)
            {
                CCParticle particle = m_pParticles[i];

                CCPoint uiPoint = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), this.nodeToWorldTransform());
                uiPoint = CCPointExtension.ccpAdd(uiPoint, new CCPoint(m_pQuads[i].bl.vertices.x, m_pQuads[i].bl.vertices.y));
                uiPoint = Director.SharedDirector.ConvertToUI(uiPoint);

                Vector2 vecPosition = new Vector2(uiPoint.X, uiPoint.Y);

                Color color = new Color(particle.color.r,
                                        particle.color.g,
                                        particle.color.b,
                                        particle.color.a);

                float scale = 1.0f;
                if (Texture.Texture2D.Width > Texture.Texture2D.Height)
                {
                    scale = particle.size / Texture.Texture2D.Height;
                }
                else
                {
                    scale = particle.size / Texture.Texture2D.Width;
                }

                float rotation = particle.rotation;

                Vector2 origin = new Vector2(Texture.Texture2D.Width / 2, Texture.Texture2D.Height / 2);
                Application.SharedApplication.SpriteBatch.Draw(this.Texture.Texture2D, vecPosition, null, color, rotation, origin, scale, SpriteEffects.None, 0);


                //CCPoint uiPoint = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), this.nodeToWorldTransform());
                //uiPoint.x += m_pQuads[i].bl.vertices.x;
                //uiPoint.y += m_pQuads[i].bl.vertices.y;
                //uiPoint = CCDirector.sharedDirector().convertToUI(uiPoint);
                //Vector2 vecPosition = new Vector2(uiPoint.x, uiPoint.y);

                //Color color = new Color(m_pQuads[i].bl.colors.r,
                //                        m_pQuads[i].bl.colors.g,
                //                        m_pQuads[i].bl.colors.b,
                //                        m_pQuads[i].bl.colors.a);

                //Vector2 origin = new Vector2(Texture.Texture2D.Width/2, Texture.Texture2D.Height/2);
                //Application.SharedApplication.SpriteBatch.Draw(this.Texture.Texture2D, vecPosition, null, color, 0, origin, 1.0f, SpriteEffects.None, 0);
            }
            Application.SharedApplication.SpriteBatch.End();

            Application.SharedApplication.GraphicsDevice.BlendState = oldBlendState;

            //    // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
            //    // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
            //    // Unneeded states: -
            //    glBindTexture(GL_TEXTURE_2D, m_pTexture->getName());

            //    #define kQuadSize sizeof(m_pQuads[0].bl)


            //    int offset = (int) m_pQuads;

            //    // vertex
            //    int diff = offsetof( ccV2F_C4B_T2F, vertices);
            //    glVertexPointer(2,GL_FLOAT, kQuadSize, (GLvoid*) (offset+diff) );

            //    // color
            //    diff = offsetof( ccV2F_C4B_T2F, colors);
            //    glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (GLvoid*)(offset + diff));

            //    // tex coords
            //    diff = offsetof( ccV2F_C4B_T2F, texCoords);
            //    glTexCoordPointer(2, GL_FLOAT, kQuadSize, (GLvoid*)(offset + diff));


            //    bool newBlend = (m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST) ? true : false;
            //    if( newBlend )
            //    {
            //        glBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
            //    }

            //    CCAssert( m_uParticleIdx == m_uParticleCount, "Abnormal error in particle quad");

            //    glDrawElements(GL_TRIANGLES, (GLsizei)(m_uParticleIdx*6), GL_UNSIGNED_SHORT, m_pIndices);

            //    // restore blend state
            //    if( newBlend )
            //        glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST );

            //#if CC_USES_VBO
            //    glBindBuffer(GL_ARRAY_BUFFER, 0);
            //#endif
        }
        public override void update(float dt)
        {
            if (this.m_bIsActive && (this.m_fEmissionRate != 0f))
            {
                float num = 1f / this.m_fEmissionRate;
                this.m_fEmitCounter += dt;
                while ((this.m_uParticleCount < this.m_uTotalParticles) && (this.m_fEmitCounter > num))
                {
                    this.addParticle();
                    this.m_fEmitCounter -= num;
                }
                this.m_fElapsed += dt;
                if ((this.m_fDuration != -1f) && (this.m_fDuration < this.m_fElapsed))
                {
                    this.stopSystem();
                }
            }
            this.m_uParticleIdx = 0;
            CCPoint tPosition = new CCPoint(0f, 0f);

            if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree)
            {
                tPosition    = base.convertToWorldSpace(new CCPoint(0f, 0f));
                tPosition.x *= CCDirector.sharedDirector().ContentScaleFactor;
                tPosition.y *= CCDirector.sharedDirector().ContentScaleFactor;
            }
            else if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative)
            {
                tPosition    = base.m_tPosition;
                tPosition.x *= CCDirector.sharedDirector().ContentScaleFactor;
                tPosition.y *= CCDirector.sharedDirector().ContentScaleFactor;
            }
            while (this.m_uParticleIdx < this.m_uParticleCount)
            {
                CCParticle particle = this.m_pParticles[this.m_uParticleIdx];
                particle.timeToLive -= dt;
                if (particle.timeToLive > 0f)
                {
                    CCPoint pos;
                    if (this.m_nEmitterMode == 0)
                    {
                        CCPoint v = new CCPoint(0f, 0f);
                        if ((particle.pos.x != 0f) || (particle.pos.y != 0f))
                        {
                            v = CCPointExtension.ccpNormalize(particle.pos);
                        }
                        CCPoint point4 = v;
                        v = CCPointExtension.ccpMult(v, particle.modeA.radialAccel);
                        float x = point4.x;
                        point4.x = -point4.y;
                        point4.y = x;
                        point4   = CCPointExtension.ccpMult(point4, particle.modeA.tangentialAccel);
                        CCPoint point2 = CCPointExtension.ccpMult(CCPointExtension.ccpAdd(CCPointExtension.ccpAdd(v, point4), this.modeA.gravity), dt);
                        particle.modeA.dir = CCPointExtension.ccpAdd(particle.modeA.dir, point2);
                        point2             = CCPointExtension.ccpMult(particle.modeA.dir, dt);
                        particle.pos       = CCPointExtension.ccpAdd(particle.pos, point2);
                    }
                    else
                    {
                        particle.modeB.angle  += particle.modeB.degreesPerSecond * dt;
                        particle.modeB.radius += particle.modeB.deltaRadius * dt;
                        particle.pos.x         = -((float)Math.Cos((double)particle.modeB.angle)) * particle.modeB.radius;
                        particle.pos.y         = -((float)Math.Sin((double)particle.modeB.angle)) * particle.modeB.radius;
                    }
                    particle.color.r  += particle.deltaColor.r * dt;
                    particle.color.g  += particle.deltaColor.g * dt;
                    particle.color.b  += particle.deltaColor.b * dt;
                    particle.color.a  += particle.deltaColor.a * dt;
                    particle.size     += particle.deltaSize * dt;
                    particle.size      = (0f > particle.size) ? 0f : particle.size;
                    particle.rotation += particle.deltaRotation * dt;
                    if ((this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree) || (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative))
                    {
                        CCPoint point6 = CCPointExtension.ccpSub(tPosition, particle.startPos);
                        pos = CCPointExtension.ccpSub(particle.pos, point6);
                    }
                    else
                    {
                        pos = particle.pos;
                    }
                    this.updateQuadWithParticle(particle, pos);
                    this.m_uParticleIdx++;
                }
                else
                {
                    if (this.m_uParticleIdx != (this.m_uParticleCount - 1))
                    {
                        this.m_pParticles[this.m_uParticleIdx].copy(this.m_pParticles[(int)((IntPtr)(this.m_uParticleCount - 1))]);
                    }
                    this.m_uParticleCount--;
                    if ((this.m_uParticleCount == 0) && this.m_bIsAutoRemoveOnFinish)
                    {
                        base.unscheduleUpdate();
                        base.m_pParent.removeChild(this, true);
                        return;
                    }
                }
            }
            this.postStep();
        }
Exemple #10
0
        protected void updateRadial()
        {
            float   single       = Math.Max(this.m_pSprite.quad.br.texCoords.u, this.m_pSprite.quad.bl.texCoords.u);
            float   single1      = Math.Min(this.m_pSprite.quad.br.texCoords.u, this.m_pSprite.quad.bl.texCoords.u);
            float   single2      = Math.Max(this.m_pSprite.quad.tl.texCoords.v, this.m_pSprite.quad.bl.texCoords.v);
            float   single3      = Math.Min(this.m_pSprite.quad.tl.texCoords.v, this.m_pSprite.quad.bl.texCoords.v);
            CCPoint cCPoint      = new CCPoint(single, single2);
            CCPoint cCPoint1     = new CCPoint(single1, single3);
            CCPoint cCPoint2     = CCPointExtension.ccpAdd(cCPoint1, CCPointExtension.ccpCompMult(this.m_tAnchorPoint, CCPointExtension.ccpSub(cCPoint, cCPoint1)));
            float   mFPercentage = this.m_fPercentage / 100f;
            float   single4      = 6.28318548f * (this.m_eType == CCProgressTimerType.kCCProgressTimerTypeRadialCW ? mFPercentage : 1f - mFPercentage);
            CCPoint cCPoint3     = new CCPoint(cCPoint2.x, cCPoint1.y);
            CCPoint cCPoint4     = CCPointExtension.ccpRotateByAngle(cCPoint3, cCPoint2, single4);
            int     num          = 0;
            CCPoint cCPoint5     = new CCPoint();

            if (mFPercentage == 0f)
            {
                cCPoint5 = cCPoint3;
                num      = 0;
            }
            else if (mFPercentage != 1f)
            {
                float single5 = float.MaxValue;
                for (int i = 0; i <= 4; i++)
                {
                    int     num1     = (i + 3) % 4;
                    CCPoint cCPoint6 = CCPointExtension.ccpAdd(cCPoint1, CCPointExtension.ccpCompMult(this.boundaryTexCoord(i % 4), CCPointExtension.ccpSub(cCPoint, cCPoint1)));
                    CCPoint cCPoint7 = CCPointExtension.ccpAdd(cCPoint1, CCPointExtension.ccpCompMult(this.boundaryTexCoord(num1), CCPointExtension.ccpSub(cCPoint, cCPoint1)));
                    if (i == 0)
                    {
                        cCPoint7 = CCPointExtension.ccpLerp(cCPoint6, cCPoint7, 0.5f);
                    }
                    else if (i == 4)
                    {
                        cCPoint6 = CCPointExtension.ccpLerp(cCPoint6, cCPoint7, 0.5f);
                    }
                    float single6 = 0f;
                    float single7 = 0f;
                    if (CCPointExtension.ccpLineIntersect(cCPoint6, cCPoint7, cCPoint2, cCPoint4, ref single6, ref single7) && (i != 0 && i != 4 || 0f <= single6 && single6 <= 1f) && single7 >= 0f && single7 < single5)
                    {
                        single5 = single7;
                        num     = i;
                    }
                }
                cCPoint5 = CCPointExtension.ccpAdd(cCPoint2, CCPointExtension.ccpMult(CCPointExtension.ccpSub(cCPoint4, cCPoint2), single5));
            }
            else
            {
                cCPoint5 = cCPoint3;
                num      = 4;
            }
            bool flag = true;

            if (this.m_nVertexDataCount != num + 3)
            {
                flag = false;
                if (this.m_pVertexData != null)
                {
                    this.m_pVertexData      = null;
                    this.m_nVertexDataCount = 0;
                }
            }
            if (this.m_pVertexData == null)
            {
                this.m_nVertexDataCount = num + 3;
                this.m_pVertexData      = new ccV2F_C4B_T2F[this.m_nVertexDataCount];
                for (int j = 0; j < this.m_nVertexDataCount; j++)
                {
                    this.m_pVertexData[j] = new ccV2F_C4B_T2F();
                }
                this.updateColor();
            }
            if (!flag)
            {
                this.m_pVertexData[0].texCoords = new ccTex2F(cCPoint2.x, cCPoint2.y);
                this.m_pVertexData[0].vertices  = this.vertexFromTexCoord(cCPoint2);
                this.m_pVertexData[1].texCoords = new ccTex2F(cCPoint2.x, cCPoint1.y);
                this.m_pVertexData[1].vertices  = this.vertexFromTexCoord(new CCPoint(cCPoint2.x, cCPoint1.y));
                for (int k = 0; k < num; k++)
                {
                    CCPoint cCPoint8 = CCPointExtension.ccpAdd(cCPoint1, CCPointExtension.ccpCompMult(this.boundaryTexCoord(k), CCPointExtension.ccpSub(cCPoint, cCPoint1)));
                    this.m_pVertexData[k + 2].texCoords = new ccTex2F(cCPoint8.x, cCPoint8.y);
                    this.m_pVertexData[k + 2].vertices  = this.vertexFromTexCoord(cCPoint8);
                }
                if (this.m_pSprite.IsFlipX || this.m_pSprite.IsFlipY)
                {
                    for (int l = 0; l < this.m_nVertexDataCount - 1; l++)
                    {
                        if (this.m_pSprite.IsFlipX)
                        {
                            this.m_pVertexData[l].texCoords.u = cCPoint1.x + cCPoint.x - this.m_pVertexData[l].texCoords.u;
                        }
                        if (this.m_pSprite.IsFlipY)
                        {
                            this.m_pVertexData[l].texCoords.v = cCPoint1.y + cCPoint.y - this.m_pVertexData[l].texCoords.v;
                        }
                    }
                }
            }
            this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords = new ccTex2F(cCPoint5.x, cCPoint5.y);
            this.m_pVertexData[this.m_nVertexDataCount - 1].vertices  = this.vertexFromTexCoord(cCPoint5);
            if (this.m_pSprite.IsFlipX || this.m_pSprite.IsFlipY)
            {
                if (this.m_pSprite.IsFlipX)
                {
                    this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords.u = cCPoint1.x + cCPoint.x - this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords.u;
                }
                if (this.m_pSprite.IsFlipY)
                {
                    this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords.v = cCPoint1.y + cCPoint.y - this.m_pVertexData[this.m_nVertexDataCount - 1].texCoords.v;
                }
            }
        }
 public static CCPoint ccpMidpoint(CCPoint v1, CCPoint v2)
 {
     return(CCPointExtension.ccpMult(CCPointExtension.ccpAdd(v1, v2), 0.5f));
 }
 public static CCPoint ccpLerp(CCPoint a, CCPoint b, float alpha)
 {
     return(CCPointExtension.ccpAdd(CCPointExtension.ccpMult(a, 1f - alpha), CCPointExtension.ccpMult(b, alpha)));
 }
Exemple #13
0
        /// <summary>
        /// Update does the work of mapping the texture onto the triangles
        //	It now doesn't occur the cost of free/alloc data every update cycle.
        //	It also only changes the percentage point but no other points if they have not
        //	been modified.
        //
        //	It now deals with flipped texture. If you run into this problem, just use the
        //	sprite property and enable the methods flipX, flipY.
        /// </summary>
        protected void updateRadial()
        {
            //	Texture Max is the actual max coordinates to deal with non-power of 2 textures
            float   fXMax = Math.Max(m_pSprite.quad.br.texCoords.u, m_pSprite.quad.bl.texCoords.u);
            float   fXMin = Math.Min(m_pSprite.quad.br.texCoords.u, m_pSprite.quad.bl.texCoords.u);
            float   fYMax = Math.Max(m_pSprite.quad.tl.texCoords.v, m_pSprite.quad.bl.texCoords.v);
            float   fYMin = Math.Min(m_pSprite.quad.tl.texCoords.v, m_pSprite.quad.bl.texCoords.v);
            CCPoint tMax  = new CCPoint(fXMax, fYMax);
            CCPoint tMin  = new CCPoint(fXMin, fYMin);

            //	Grab the midpoint
            CCPoint midpoint = CCPointExtension.ccpAdd(tMin, CCPointExtension.ccpCompMult(m_tAnchorPoint, CCPointExtension.ccpSub(tMax, tMin)));

            float alpha = m_fPercentage / 100.0f;

            //	Otherwise we can get the angle from the alpha
            float angle = 2.0f * ((float)Math.PI) * (m_eType == CCProgressTimerType.kCCProgressTimerTypeRadialCW ? alpha : 1.0f - alpha);

            //	We find the vector to do a hit detection based on the percentage
            //	We know the first vector is the one @ 12 o'clock (top,mid) so we rotate
            //	from that by the progress angle around the midpoint pivot
            CCPoint topMid       = new CCPoint(midpoint.x, tMin.y);
            CCPoint percentagePt = CCPointExtension.ccpRotateByAngle(topMid, midpoint, angle);

            int     index = 0;
            CCPoint hit   = new CCPoint();

            if (alpha == 0.0f)
            {
                //	More efficient since we don't always need to check intersection
                //	If the alpha is zero then the hit point is top mid and the index is 0.
                hit   = topMid;
                index = 0;
            }
            else
            if (alpha == 1.0f)
            {
                //	More efficient since we don't always need to check intersection
                //	If the alpha is one then the hit point is top mid and the index is 4.
                hit   = topMid;
                index = 4;
            }
            else
            {
                //	We run a for loop checking the edges of the texture to find the
                //	intersection point
                //	We loop through five points since the top is split in half

                float min_t = float.MaxValue;

                for (int i = 0; i <= kProgressTextureCoordsCount; ++i)
                {
                    int pIndex = (i + (kProgressTextureCoordsCount - 1)) % kProgressTextureCoordsCount;

                    CCPoint edgePtA = CCPointExtension.ccpAdd(tMin, CCPointExtension.ccpCompMult(boundaryTexCoord(i % kProgressTextureCoordsCount), CCPointExtension.ccpSub(tMax, tMin)));
                    CCPoint edgePtB = CCPointExtension.ccpAdd(tMin, CCPointExtension.ccpCompMult(boundaryTexCoord(pIndex), CCPointExtension.ccpSub(tMax, tMin)));

                    //	Remember that the top edge is split in half for the 12 o'clock position
                    //	Let's deal with that here by finding the correct endpoints
                    if (i == 0)
                    {
                        edgePtB = CCPointExtension.ccpLerp(edgePtA, edgePtB, 0.5f);
                    }
                    else
                    if (i == 4)
                    {
                        edgePtA = CCPointExtension.ccpLerp(edgePtA, edgePtB, 0.5f);
                    }

                    //	s and t are returned by ccpLineIntersect
                    float s = 0;
                    float t = 0;
                    if (CCPointExtension.ccpLineIntersect(edgePtA, edgePtB, midpoint, percentagePt, ref s, ref t))
                    {
                        //	Since our hit test is on rays we have to deal with the top edge
                        //	being in split in half so we have to test as a segment
                        if (i == 0 || i == 4)
                        {
                            //	s represents the point between edgePtA--edgePtB
                            if (!(0.0f <= s && s <= 1.0f))
                            {
                                continue;
                            }
                        }

                        //	As long as our t isn't negative we are at least finding a
                        //	correct hitpoint from midpoint to percentagePt.
                        if (t >= 0.0f)
                        {
                            //	Because the percentage line and all the texture edges are
                            //	rays we should only account for the shortest intersection
                            if (t < min_t)
                            {
                                min_t = t;
                                index = i;
                            }
                        }
                    }
                }

                //	Now that we have the minimum magnitude we can use that to find our intersection
                hit = CCPointExtension.ccpAdd(midpoint, CCPointExtension.ccpMult(CCPointExtension.ccpSub(percentagePt, midpoint), min_t));
            }

            //	The size of the vertex data is the index from the hitpoint
            //	the 3 is for the midpoint, 12 o'clock point and hitpoint position.

            bool sameIndexCount = true;

            if (m_nVertexDataCount != index + 3)
            {
                sameIndexCount = false;
                if (m_pVertexData != null)
                {
                    m_pVertexData      = null;
                    m_nVertexDataCount = 0;
                }
            }

            if (m_pVertexData == null)
            {
                m_nVertexDataCount = index + 3;
                m_pVertexData      = new ccV2F_C4B_T2F[m_nVertexDataCount];
                for (int i = 0; i < m_nVertexDataCount; i++)
                {
                    m_pVertexData[i] = new ccV2F_C4B_T2F();
                }


                Debug.Assert(m_pVertexData != null);

                updateColor();
            }

            if (!sameIndexCount)
            {
                //	First we populate the array with the midpoint, then all
                //	vertices/texcoords/colors of the 12 'o clock start and edges and the hitpoint
                m_pVertexData[0].texCoords = new ccTex2F(midpoint.x, midpoint.y);
                m_pVertexData[0].vertices  = vertexFromTexCoord(midpoint);

                m_pVertexData[1].texCoords = new ccTex2F(midpoint.x, tMin.y);
                m_pVertexData[1].vertices  = vertexFromTexCoord(new CCPoint(midpoint.x, tMin.y));

                for (int i = 0; i < index; ++i)
                {
                    CCPoint texCoords = CCPointExtension.ccpAdd(tMin, CCPointExtension.ccpCompMult(boundaryTexCoord(i), CCPointExtension.ccpSub(tMax, tMin)));

                    m_pVertexData[i + 2].texCoords = new ccTex2F(texCoords.x, texCoords.y);
                    m_pVertexData[i + 2].vertices  = vertexFromTexCoord(texCoords);
                }

                //	Flip the texture coordinates if set
                if (m_pSprite.IsFlipX || m_pSprite.IsFlipY)
                {
                    for (int i = 0; i < m_nVertexDataCount - 1; ++i)
                    {
                        if (m_pSprite.IsFlipX)
                        {
                            m_pVertexData[i].texCoords.u = tMin.x + tMax.x - m_pVertexData[i].texCoords.u;
                        }

                        if (m_pSprite.IsFlipY)
                        {
                            m_pVertexData[i].texCoords.v = tMin.y + tMax.y - m_pVertexData[i].texCoords.v;
                        }
                    }
                }
            }

            //	hitpoint will go last
            m_pVertexData[m_nVertexDataCount - 1].texCoords = new ccTex2F(hit.x, hit.y);
            m_pVertexData[m_nVertexDataCount - 1].vertices  = vertexFromTexCoord(hit);

            if (m_pSprite.IsFlipX || m_pSprite.IsFlipY)
            {
                if (m_pSprite.IsFlipX)
                {
                    m_pVertexData[m_nVertexDataCount - 1].texCoords.u = tMin.x + tMax.x - m_pVertexData[m_nVertexDataCount - 1].texCoords.u;
                }

                if (m_pSprite.IsFlipY)
                {
                    m_pVertexData[m_nVertexDataCount - 1].texCoords.v = tMin.y + tMax.y - m_pVertexData[m_nVertexDataCount - 1].texCoords.v;
                }
            }
        }