/// <summary> /// draws n quads from an index (offset). /// n + start can't be greater than the capacity of the atlas /// @since v1.0 /// </summary> public void drawNumberOfQuads(int n, int start) { if (n == start) { return; } if (this.m_pQuads == null || this.m_pQuads.Length < 1) { return; } CCApplication app = CCApplication.sharedApplication(); CCSize size = CCDirector.sharedDirector().getWinSize(); //app.basicEffect.World = app.worldMatrix *TransformUtils.CGAffineToMatrix( this.nodeToWorldTransform()); app.basicEffect.Texture = this.Texture.getTexture2D(); app.basicEffect.TextureEnabled = true; app.GraphicsDevice.BlendState = BlendState.AlphaBlend; app.basicEffect.VertexColorEnabled = true; List <VertexPositionColorTexture> vertices = new List <VertexPositionColorTexture>(); short[] indexes = new short[n * 6]; for (int i = start; i < start + n; i++) { ccV3F_C4B_T2F_Quad quad = this.m_pQuads[i]; if (quad != null) { vertices.AddRange(quad.getVertices(ccDirectorProjection.CCDirectorProjection3D).ToList()); indexes[i * 6 + 0] = (short)(i * 4 + 0); indexes[i * 6 + 1] = (short)(i * 4 + 1); indexes[i * 6 + 2] = (short)(i * 4 + 2); // inverted index. issue #179 indexes[i * 6 + 3] = (short)(i * 4 + 2); indexes[i * 6 + 4] = (short)(i * 4 + 1); indexes[i * 6 + 5] = (short)(i * 4 + 3); } } VertexDeclaration vertexDeclaration = new VertexDeclaration(new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Color, 0), new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) }); foreach (var pass in app.basicEffect.CurrentTechnique.Passes) { pass.Apply(); app.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>( PrimitiveType.TriangleList, vertices.ToArray(), 0, vertices.Count, indexes, 0, vertices.Count / 2); } }
public void drawNumberOfQuads(int n, int start) { if (n == start) { return; } if (this.m_pQuads == null || (int)this.m_pQuads.Length < 1) { return; } CCApplication texture2D = CCApplication.sharedApplication(); CCDirector.sharedDirector().getWinSize(); texture2D.basicEffect.Texture = this.Texture.getTexture2D(); texture2D.basicEffect.TextureEnabled = true; texture2D.GraphicsDevice.BlendState = BlendState.AlphaBlend; texture2D.basicEffect.VertexColorEnabled = true; List <VertexPositionColorTexture> vertexPositionColorTextures = new List <VertexPositionColorTexture>(); short[] numArray = new short[n * 6]; for (int i = start; i < start + n; i++) { ccV3F_C4B_T2F_Quad mPQuads = this.m_pQuads[i]; if (mPQuads != null) { vertexPositionColorTextures.AddRange(mPQuads.getVertices(ccDirectorProjection.kCCDirectorProjection3D).ToList <VertexPositionColorTexture>()); numArray[i * 6] = (short)(i * 4); numArray[i * 6 + 1] = (short)(i * 4 + 1); numArray[i * 6 + 2] = (short)(i * 4 + 2); numArray[i * 6 + 3] = (short)(i * 4 + 2); numArray[i * 6 + 4] = (short)(i * 4 + 1); numArray[i * 6 + 5] = (short)(i * 4 + 3); } } VertexElement[] vertexElement = new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Color, 0), new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) }; VertexDeclaration vertexDeclaration = new VertexDeclaration(vertexElement); foreach (EffectPass pass in texture2D.basicEffect.CurrentTechnique.Passes) { pass.Apply(); texture2D.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColorTexture>(PrimitiveType.TriangleList, vertexPositionColorTextures.ToArray(), 0, vertexPositionColorTextures.Count, numArray, 0, vertexPositionColorTextures.Count / 2); } }