Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 public CCPoint convertToWorldSpace(CCPoint nodePoint)
 {
     if (CCDirector.sharedDirector().ContentScaleFactor == 1f)
     {
         return(CCAffineTransform.CCPointApplyAffineTransform(nodePoint, this.nodeToWorldTransform()));
     }
     return(CCPointExtension.ccpMult(CCAffineTransform.CCPointApplyAffineTransform(CCPointExtension.ccpMult(nodePoint, CCDirector.sharedDirector().ContentScaleFactor), this.nodeToWorldTransform()), 1f / CCDirector.sharedDirector().ContentScaleFactor));
 }
Ejemplo n.º 3
0
        public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform)
        {
            float   single   = CCRect.CCRectGetMinY(rect);
            float   single1  = CCRect.CCRectGetMinX(rect);
            float   single2  = CCRect.CCRectGetMaxX(rect);
            float   single3  = CCRect.CCRectGetMaxY(rect);
            CCPoint cCPoint  = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(single1, single), anAffineTransform);
            CCPoint cCPoint1 = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(single2, single), anAffineTransform);
            CCPoint cCPoint2 = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(single1, single3), anAffineTransform);
            CCPoint cCPoint3 = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(single2, single3), anAffineTransform);
            float   single4  = Math.Min(Math.Min(cCPoint.x, cCPoint1.x), Math.Min(cCPoint2.x, cCPoint3.x));
            float   single5  = Math.Max(Math.Max(cCPoint.x, cCPoint1.x), Math.Max(cCPoint2.x, cCPoint3.x));
            float   single6  = Math.Min(Math.Min(cCPoint.y, cCPoint1.y), Math.Min(cCPoint2.y, cCPoint3.y));
            float   single7  = Math.Max(Math.Max(cCPoint.y, cCPoint1.y), Math.Max(cCPoint2.y, cCPoint3.y));

            return(new CCRect(single4, single6, single5 - single4, single7 - single6));
        }
Ejemplo n.º 4
0
        /// <summary>Converts a Point to world space coordinates. The result is in Points.</summary>
        public CCPoint ConvertToWorldSpace(CCPoint nodePoint)
        {
            CCPoint ret;

            if (Director.SharedDirector.ContentScaleFactor == 1)
            {
                ret = CCAffineTransform.CCPointApplyAffineTransform(nodePoint, nodeToWorldTransform());
            }
            else
            {
                ret = CCPointExtension.ccpMult(nodePoint, Director.SharedDirector.ContentScaleFactor);
                ret = CCAffineTransform.CCPointApplyAffineTransform(ret, nodeToWorldTransform());
                ret = CCPointExtension.ccpMult(ret, 1 / Director.SharedDirector.ContentScaleFactor);
            }

            return(ret);
        }
Ejemplo n.º 5
0
        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
        }