예제 #1
0
        public CCRenderTexture(CCSize contentSize, CCSize textureSizeInPixels, 
            CCSurfaceFormat colorFormat=CCSurfaceFormat.Color, 
            CCDepthFormat depthFormat=CCDepthFormat.None, 
            CCRenderTargetUsage usage=CCRenderTargetUsage.DiscardContents) : this()
        {
            int textureWidth = (int)textureSizeInPixels.Width;
            int textureHeight = (int)textureSizeInPixels.Height;

            renderTarget2D = drawManager.CreateRenderTarget(
                textureWidth, textureHeight, colorFormat, depthFormat, usage);

            Texture = new CCTexture2D(renderTarget2D, colorFormat, true, false);
            Texture.IsAntialiased = false;

            Sprite = new CCSprite(Texture);
            Sprite.ContentSize = contentSize;
            Sprite.BlendFunc = CCBlendFunc.AlphaBlend;

            CCPoint center = contentSize.Center;

            renderViewMatrix = 
                Matrix.CreateLookAt(new CCPoint3(center, 300.0f).XnaVector, new CCPoint3(center, 0.0f).XnaVector, Vector3.Up);
            renderProjMatrix = 
                Matrix.CreateOrthographic(contentSize.Width, contentSize.Height, 1024f, -1024);
            renderViewport = new Viewport(0, 0, textureWidth, textureHeight);


            clearColor = CCColor4B.Transparent;
            drawManager.SetRenderTarget(Texture);
            drawManager.Clear(clearColor);
            drawManager.RestoreRenderTarget();
        }
예제 #2
0
        public CCMotionStreak(float fade, float minSegIn, float strokeIn, CCColor3B color, CCTexture2D texture)
        {
            streakRenderCommand = new CCCustomCommand(RenderMotionStreak);

            AnchorPoint = CCPoint.Zero;
            IgnoreAnchorPointForPosition = true;
            StartingPositionInitialized = false;
            FastMode = true;
            Texture = texture;
            Color = color;
            stroke = strokeIn;
            BlendFunc = CCBlendFunc.NonPremultiplied;

            minSeg = (minSegIn == -1.0f) ? stroke / 5.0f : minSegIn;
            minSeg *= minSeg;

            fadeDelta = 1.0f / fade;

            maxPoints = (int) (fade * 60.0f) + 2;

            pointState = new float[maxPoints];
            pointVertexes = new CCPoint[maxPoints];
            vertices = new CCV3F_C4B_T2F[(maxPoints + 1) * 2];

            Schedule();
        }
예제 #3
0
        public GameLayer()
        {
            var touchListener = new CCEventListenerTouchAllAtOnce ();
            touchListener.OnTouchesEnded = OnTouchesEnded;

            AddEventListener (touchListener, this);
            Color = new CCColor3B (CCColor4B.White);
            Opacity = 255;

            visibleBananas = new List<CCSprite> ();
            hitBananas = new List<CCSprite> ();

            // batch node for physics balls
            ballsBatch = new CCSpriteBatchNode ("balls", 100);
            ballTexture = ballsBatch.Texture;
            AddChild (ballsBatch, 1, 1);

            AddGrass ();
            AddSun ();
            AddMonkey ();

            StartScheduling();

            CCSimpleAudioEngine.SharedEngine.PlayBackgroundMusic ("Sounds/backgroundMusic", true);
        }
예제 #4
0
        internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment,
		                                   CCVerticalTextAlignment vAlignment, string fontName,
		                                   float fontSize, CCColor4B textColor)
		{

		    if (string.IsNullOrEmpty(text))
		    {
		        return new CCTexture2D();
		    }

		    var font = CreateFont (fontName, fontSize);

            if (dimensions.Equals(CCSize.Zero))
            {
                CreateBitmap(1, 1);

                var ms = _graphics.MeasureString(text, font);
                
                dimensions.Width = ms.Width;
                dimensions.Height = ms.Height;
            }

            CreateBitmap((int)dimensions.Width, (int)dimensions.Height);

            var stringFormat = new StringFormat();

		    switch (hAlignment)
		    {
		        case CCTextAlignment.Left:
                    stringFormat.Alignment = StringAlignment.Near;
		            break;
		        case CCTextAlignment.Center:
                    stringFormat.Alignment = StringAlignment.Center;
		            break;
		        case CCTextAlignment.Right:
                    stringFormat.Alignment = StringAlignment.Far;
		            break;
		    }

		    switch (vAlignment)
		    {
		        case CCVerticalTextAlignment.Top:
        		    stringFormat.LineAlignment = StringAlignment.Near;
		            break;
		        case CCVerticalTextAlignment.Center:
        		    stringFormat.LineAlignment = StringAlignment.Center;
		            break;
		        case CCVerticalTextAlignment.Bottom:
        		    stringFormat.LineAlignment = StringAlignment.Far;
		            break;
		    }

            _graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat);
            _graphics.Flush();

            var texture = new CCTexture2D(SaveToStream(), CCSurfaceFormat.Bgra4444);

			return texture;
		}
예제 #5
0
 protected CCGridBase(CCGridSize gridSize, CCTexture2D texture, bool flipped=false)
 {
     GridSize = gridSize;
     Texture = texture;
     textureFlipped = flipped;
     CCSize texSize = texture.ContentSizeInPixels;
     Step = new CCPoint ((float)Math.Ceiling(texSize.Width / GridSize.X), (float)Math.Ceiling(texSize.Height / GridSize.Y));
 }
        public SpriteBatchNodeNewTexture()
        {
            CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 50);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            texture1 = batch.Texture;
            texture2 = CCTextureCache.SharedTextureCache.AddImage("Images/grossini_dance_atlas-mono");
        }
예제 #7
0
 public void Render (DrawBatch drawBatch, CCTexture2D defaultTexture)
 {
     //device.Textures[0] = _texture ?? defaultTexture;
     //device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, _vertexBuffer, 0, _vertexBuffer.Length, _indexBuffer, 0, _indexBuffer.Length / 3);
     drawBatch.RenderBatch(PrimitiveType.TriangleList,
         0, _indexBuffer.Length, _indexBuffer,
         0, _vertexBuffer.Length, _vertexBuffer,
         _texture ?? defaultTexture);
 }
		public void Load (AtlasPage page, String path) 
		{
			var ccTexture = CCTextureCache.SharedTextureCache.AddImage(path);
            texture = ccTexture;

            page.rendererObject = texture;
            page.width = (int)texture.ContentSizeInPixels.Width;
            page.height = (int)texture.ContentSizeInPixels.Height;
		}
예제 #9
0
        public SpriteNewTexture()
        {
            CCNode node = new CCNode();
            AddChild(node, 0, (int)kTags.kTagSpriteBatchNode);

            texture1 = CCTextureCache.SharedTextureCache.AddImage("Images/grossini_dance_atlas");
            texture2 = CCTextureCache.SharedTextureCache.AddImage("Images/grossini_dance_atlas-mono");

            usingTexture1 = true;
        }
예제 #10
0
 public CCQuadCommand(float globalDepth, CCAffineTransform worldTransform, 
     CCTexture2D texture, CCBlendFunc blendType, int quadCount,
     params CCV3F_C4B_T2F_Quad[] quads) 
     : base(globalDepth, worldTransform)
 {
     Quads = quads;
     QuadCount = quadCount;
     Texture = texture;
     BlendType = blendType;
 }
예제 #11
0
 public CCSpriteFrame(CCSize contentSize, CCTexture2D texture, CCRect textureRectInPxls, 
     CCSize originalSizeInPxls, bool rotated=false, CCPoint? offsetInPxls=null)
 {
     TextureRectInPixels = textureRectInPxls;
     ContentSize = contentSize;
     OffsetInPixels = offsetInPxls ?? CCPoint.Zero;
     OriginalSizeInPixels = originalSizeInPxls;
     IsRotated = rotated;
     Texture = texture;
 }
예제 #12
0
 public CCSpriteSheet AddSpriteSheet(string fileName, CCTexture2D texture)
 {
     CCSpriteSheet result;
     if (!_spriteSheets.TryGetValue(fileName, out result))
     {
         result = new CCSpriteSheet(fileName, texture);
         _spriteSheets.Add(fileName, result);
     }
     return result;
 }
예제 #13
0
 public CCSpriteSheet AddSpriteSheet(PlistDictionary dictionary, CCTexture2D texture, string name)
 {
     CCSpriteSheet result;
     if (!_spriteSheets.TryGetValue(name, out result))
     {
         result = new CCSpriteSheet(name, texture);
         _spriteSheets.Add(name, result);
     }
     return result;
 }
예제 #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="bgFile"></param>
 public BackgroungLayer(string bgFile, byte opacity = 255)
     : base()
 {
     BackgroundSprite =
         new CCSprite(BackgroundTexture =
             new CCTexture2D(BACKGROUND_FOLDER + bgFile));
     BackgroundSprite.AnchorPoint = CCPoint.AnchorLowerLeft;
     BackgroundSprite.Opacity = opacity;
     Opacity = opacity;
     AddChild(BackgroundSprite);
 }
예제 #15
0
        public static void InitializeTTFAtlas(int width, int height)
        {
            m_nWidth = width;
            m_nHeight = height;
            m_nDepth = 4;

            m_pTexture = new CCTexture2D();
            m_pData = new int[width * height];

            m_pNodes.Clear();
            m_pNodes.Add(new ivec3() { x = 1, y = 1, z = m_nWidth - 2 });
        }
예제 #16
0
        public CCSpriteBatchNode(CCTexture2D tex, int capacity=defaultSpriteBatchCapacity)
        {
            BlendFunc = CCBlendFunc.AlphaBlend;

            if (capacity == 0)
            {
                capacity = defaultSpriteBatchCapacity;
            }

            TextureAtlas = new CCTextureAtlas(tex, capacity);

            // no lazy alloc in this node
            Children = new CCRawList<CCNode>(capacity);
            Descendants = new CCRawList<CCSprite>(capacity);
        }
예제 #17
0
        public DrawCacheUnit (VertexPositionColorTexture[] vertexBuffer, int vertexOffset, int vertexCount, short[] indexBuffer, int indexOffset, int indexCount, CCTexture2D texture)
        {
            if (vertexCount > vertexBuffer.Length - vertexOffset)
                throw new ArgumentException("vertexBuffer is too small for the given vertexOffset and vertexCount.");
            if (indexCount > indexBuffer.Length - indexOffset)
                throw new ArgumentException("indexBuffer is too small for the given indexOffset and indexCount.");

            _texture = texture;

            _vertexBuffer = new VertexPositionColorTexture[vertexCount];
            _indexBuffer = new short[indexCount];

            Array.Copy(vertexBuffer, vertexOffset, _vertexBuffer, 0, vertexCount);
            Array.Copy(indexBuffer, indexOffset, _indexBuffer, 0, indexCount);
        }
예제 #18
0
        public CCTextureAtlas(CCTexture2D texture, int capacity)
        {
            Texture = texture;

            // Re-initialization is not allowed
            Debug.Assert(Quads == null);

            if (capacity < 4)
            {
                capacity = 4;
            }

            vertexBuffer = new CCQuadVertexBuffer(capacity, CCBufferUsage.WriteOnly);
            Quads = vertexBuffer.Data;

            Dirty = true;
        }
예제 #19
0
        public GameLayer ()
        {
            var touchListener = new CCEventListenerTouchAllAtOnce ();
            touchListener.OnTouchesEnded = OnTouchesEnded;

            AddEventListener (touchListener, this);
            Color = new CCColor3B (CCColor4B.White);
            Opacity = 255;

            visibleBananas = new List<CCSprite> ();
            hitBananas = new List<CCSprite> ();

            // batch node for physics balls
            ballsBatch = new CCSpriteBatchNode ("balls", 100);
            ballTexture = ballsBatch.Texture;
            AddChild (ballsBatch, 1, 1);
	
            AddGrass ();
            AddSun ();
            AddMonkey ();

            Schedule (t => {
                visibleBananas.Add (AddBanana ());
                elapsedTime += t;
                if (ShouldEndGame ()) {
                    EndGame ();
                }
                AddBall ();
            }, 1.0f);

            Schedule (t => CheckCollision ());

            Schedule (t => {
                world.Step (t, 8, 1);

                foreach (CCPhysicsSprite sprite in ballsBatch.Children) {
                    if (sprite.Visible && sprite.PhysicsBody.Position.x < 0f || sprite.PhysicsBody.Position.x * PTM_RATIO > ContentSize.Width) { //or should it be Layer.VisibleBoundsWorldspace.Size.Width
                        world.DestroyBody (sprite.PhysicsBody);
                        sprite.Visible = false;
                        sprite.RemoveFromParent ();
                    } else {
                        sprite.UpdateTransformedSpriteTextureQuads ();
                    }
                }
            });
        }
예제 #20
0
        public TextureFill()
        {
            
            var _xor6 = BuildXorTexture(6);
            _xor6.SamplerState = SamplerState.LinearWrap;
            _brush1 = new TextureBrush(_xor6);
            _brush2 = new TextureBrush(_xor6)
            {
                Transform = Matrix.CreateTranslation(-50f / _xor6.XNATexture.Width, -175f / _xor6.XNATexture.Height, 0)
            };
            _brush3 = new TextureBrush(_xor6)
            {
                Transform = Matrix.CreateScale(.25f, .5f, 1f)
            };
            _brush4 = new TextureBrush(_xor6)
            {
                Transform = Matrix.CreateRotationZ((float)Math.PI / 4)
            };
            _brush5 = new TextureBrush(_xor6, .5f);

            _brush6 = new TextureBrush(_xor6)
            {
                Color = Microsoft.Xna.Framework.Color.Purple
            };

            var pattern = new CCTexture2D("images/pattern1");

            var state = new SamplerState();
            state.AddressU = TextureAddressMode.Mirror;
            state.AddressV = TextureAddressMode.Wrap;
            pattern.SamplerState = state;

            mirrorBrush = new TextureBrush(pattern)
            {
                Color = Microsoft.Xna.Framework.Color.White
            };

            var pattern2 = new CCTexture2D("images/pattern2");
            pattern2.SamplerState = SamplerState.LinearWrap;
            repeatBrush = new TextureBrush(pattern2);


        }
예제 #21
0
        public CCRenderTexture(CCSize contentSize, CCSize textureSizeInPixels, 
            CCSurfaceFormat colorFormat=CCSurfaceFormat.Color, 
            CCDepthFormat depthFormat=CCDepthFormat.None, 
            CCRenderTargetUsage usage=CCRenderTargetUsage.DiscardContents)
        {
            int textureWidth = (int)textureSizeInPixels.Width;
            int textureHeight = (int)textureSizeInPixels.Height;

            firstUsage = true;
            renderTarget2D = CCDrawManager.SharedDrawManager.CreateRenderTarget(textureWidth, textureHeight, colorFormat, depthFormat, usage);

            Texture = new CCTexture2D(renderTarget2D, colorFormat, true, false);
            Texture.IsAntialiased = false;

            Sprite = new CCSprite(Texture);
            Sprite.ContentSize = contentSize;
            Sprite.BlendFunc = CCBlendFunc.AlphaBlend;

            AddChild(Sprite);
        }
예제 #22
0
        /// <summary>
        /// Constructor to create a Bitmap Font configuration object from a .FNT configuration file
        /// string to be parsed and a Stream object of the Atlas Texture to be used.
        /// </summary>
        /// <param name="configInfo">String representation read from a .FNT configuration</param>
        /// <param name="atlasTexture">CCTexture2D Atlas to be used.</param>
        /// <param name="imageOffset">Image Offset</param>
        public CCFontFNT(string configInfo, CCTexture2D atlasTexture, CCVector2? imageOffset = null)
        {

            try
            {
                Configuration = new CCBMFontConfiguration(configInfo, string.Empty);
            }
            catch (Exception exc)
            {
                throw new ContentLoadException("Bitmap Font Configuration is invalid: " + exc.Message);
            }

            this.imageOffset = CCVector2.Zero;

            if (imageOffset.HasValue)
                this.imageOffset = imageOffset.Value;

            AtlasTexture = atlasTexture;

            if (Configuration != null)
                IsFontConfigValid = true;
        }
예제 #23
0
        protected static CCTexture2D BuildXorTexture(int bits)
        {
            if (bits < 1 || bits > 8)
                throw new ArgumentException("Xor texture must have between 1 and 8 bits", "bits");

            CCTexture2D tex2 = new CCTexture2D(1 << bits, 1 << bits);
            var tex = tex2.XNATexture;

            Microsoft.Xna.Framework.Color[] data = new Microsoft.Xna.Framework.Color[tex.Width * tex.Height];

            for (int y = 0; y < tex.Height; y++)
            {
                for (int x = 0; x < tex.Width; x++)
                {
                    float lum = ((x << (8 - bits)) ^ (y << (8 - bits))) / 255f;
                    data[y * tex.Width + x] = new Microsoft.Xna.Framework.Color(lum, lum, lum);
                }
            }

            tex.SetData(data);

            return tex2;
        }
예제 #24
0
        public CCQuadCommand(float globalZOrder, CCTexture2D texture, CCBlendFunc blendType, 
            CCV3F_C4B_T2F_Quad[] quads, int quadCount, CCAffineTransform modelViewTransform, int flags = 0) 
            : base(globalZOrder, modelViewTransform, flags)
        {
            CommandType = CommandType.QUAD_COMMAND;
            Quads = quads;
            QuadCount = quadCount;
            Texture = texture;
            BlendType = blendType;

            var textureId = texture == null ? 0 : texture.TextureId;

            // +=========================================================+
            // | Material Id 24 bits                                     |
            // +============================+============================+
            // | Texture ID                 | BlendFunc (Src ^ Dest)     |
            // | 12 bits                    | 12 bits                    |
            // +============================+============================+
            MaterialId = textureId << 12 | BlendType.GetHashCode();

            System.Diagnostics.Debug.Assert(MaterialId != 0, "Material Id not set");
                
        }
예제 #25
0
        public void createParticleSystem()
        {
            CCParticleSystem particleSystem = null;

            /*
             * Tests:
             * 1: Point Particle System using 32-bit textures (PNG)
             * 2: Point Particle System using 16-bit textures (PNG)
             * 3: Point Particle System using 8-bit textures (PNG)
             * 4: Point Particle System using 4-bit textures (PVRTC)
             *
             * 5: Quad Particle System using 32-bit textures (PNG)
             * 6: Quad Particle System using 16-bit textures (PNG)
             * 7: Quad Particle System using 8-bit textures (PNG)
             * 8: Quad Particle System using 4-bit textures (PVRTC)
             */
            RemoveChildByTag(PerformanceParticleTest.kTagParticleSystem, true);

            // remove the "fire.png" from the TextureCache cache.
            CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire");

            CCTextureCache.SharedTextureCache.RemoveTexture(texture);

            particleSystem = new CCParticleSystemQuad();

            switch (subtestNumber)
            {
            case 1:
                CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA8888;
                particleSystem.InitWithTotalParticles(quantityParticles);
                particleSystem.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire");
                break;

            case 2:
                CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA4444;
                particleSystem.InitWithTotalParticles(quantityParticles);
                particleSystem.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire");
                break;

            case 3:
                CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.A8;
                particleSystem.InitWithTotalParticles(quantityParticles);
                particleSystem.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire");
                break;

            //     case 4:
            //         particleSystem->initWithTotalParticles(quantityParticles);
            //         ////---- particleSystem.texture = [[CCTextureCache sharedTextureCache] addImage:@"fire.pvr"];
            //         particleSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png"));
            //         break;
            case 4:
                CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA8888;
                particleSystem.InitWithTotalParticles(quantityParticles);
                particleSystem.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire");
                break;

            case 5:
                CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA4444;
                particleSystem.InitWithTotalParticles(quantityParticles);
                particleSystem.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire");
                break;

            case 6:
                CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.A8;
                particleSystem.InitWithTotalParticles(quantityParticles);
                particleSystem.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire");
                break;

            //     case 8:
            //         particleSystem->initWithTotalParticles(quantityParticles);
            //         ////---- particleSystem.texture = [[CCTextureCache sharedTextureCache] addImage:@"fire.pvr"];
            //         particleSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png"));
            //         break;
            default:
                particleSystem = null;
                CCLog.Log("Shall not happen!");
                break;
            }
            AddChild(particleSystem, 0, PerformanceParticleTest.kTagParticleSystem);

            doTest();

            // restore the default pixel format
            CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA8888;
        }
예제 #26
0
 public CCGrid3D(CCGridSize gridSize, CCTexture2D texture, bool flipped=false) : base(gridSize, texture, flipped)
 {
 }
예제 #27
0
파일: Ball.cs 프로젝트: KerwinMa/CocosSharp
 public Ball(CCTexture2D tex): base(tex)
 {
 }
예제 #28
0
파일: Ball.cs 프로젝트: KerwinMa/CocosSharp
        public static Ball ballWithTexture(CCTexture2D aTexture)
        {
            Ball pBall = new Ball(aTexture);
            //pBall->autorelease();

            return pBall;
        }
예제 #29
0
        protected void InitSpriteFont(string theString, string fntFile, float fontSize, CCSize dimensions, CCLabelFormat labelFormat, 
            CCPoint imageOffset, CCTexture2D texture)
        {
            Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null),
                "Invalid params for CCLabel SpriteFont");

            if (!String.IsNullOrEmpty(fntFile))
            {
                try
                {
                    FontAtlas = CCFontAtlasCache.GetFontAtlasSpriteFont(fntFile, fontSize, imageOffset);
                    Scale = FontAtlas.Font.FontScale;
                }
                catch {}

                if (FontAtlas == null)
                {
                    CCLog.Log("SpriteFont CCLabel: Impossible to create font. Please check file: '{0}'", fntFile);
                    return;
                }

            }

            AnchorPoint = CCPoint.AnchorMiddle;

            LabelType = CCLabelType.SpriteFont;

            if (String.IsNullOrEmpty(theString))
            {
                theString = String.Empty;
            }

            // Initialize the TextureAtlas along with children.
            var capacity = theString.Length;

            BlendFunc = CCBlendFunc.AlphaBlend;

            if (capacity == 0)
            {
                capacity = defaultSpriteBatchCapacity;
            }

            UpdateBlendFunc();

            // no lazy alloc in this node
            Children = new CCRawList<CCNode>(capacity);
            Descendants = new CCRawList<CCSprite>(capacity);

            this.labelDimensions = dimensions;

            horzAlignment = labelFormat.Alignment;
            vertAlignment = labelFormat.LineAlignment;

            IsOpacityCascaded = true;

            ContentSize = CCSize.Zero;

            IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha;
            AnchorPoint = CCPoint.AnchorMiddle;

            ImageOffset = imageOffset;

            Text = theString;
        }
예제 #30
0
        protected void InitBMFont(string theString, string fntFile, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, 
            CCPoint imageOffset, CCTexture2D texture)
        {
            Debug.Assert(FontConfiguration == null, "re-init is no longer supported");
            Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null),
                "Invalid params for CCLabelBMFont");

            if (!String.IsNullOrEmpty(fntFile))
            {
                try
                {
                    FontAtlas = CCFontAtlasCache.GetFontAtlasFNT(fntFile, imageOffset);
                }
                catch {}

                if (FontAtlas == null)
                {
                    CCLog.Log("Bitmap Font CCLabel: Impossible to create font. Please check file: '{0}'", fntFile);
                    return;
                }

            }

            AnchorPoint = CCPoint.AnchorMiddle;

            FontConfiguration = CCBMFontConfiguration.FontConfigurationWithFile(fntFile);

            LabelType = CCLabelType.BitMapFont;

            if (String.IsNullOrEmpty(theString))
            {
                theString = String.Empty;
            }

            // Initialize the TextureAtlas along with children.
            var capacity = theString.Length;

            BlendFunc = CCBlendFunc.AlphaBlend;

            if (capacity == 0)
            {
                capacity = defaultSpriteBatchCapacity;
            }

            UpdateBlendFunc();

            // no lazy alloc in this node
            Children = new CCRawList<CCNode>(capacity);
            Descendants = new CCRawList<CCSprite>(capacity);

            this.labelDimensions = dimensions;

            horzAlignment = hAlignment;
            vertAlignment = vAlignment;

            IsOpacityCascaded = true;

            // We use base here so we do not trigger an update internally.
            base.ContentSize = CCSize.Zero;

            IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha;
            AnchorPoint = CCPoint.AnchorMiddle;

            ImageOffset = imageOffset;

            Text = theString;
        }
예제 #31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
        /// </summary>
        /// <param name="str">Initial text of the label.</param>
        /// <param name="fntFile">Font definition file to use.</param>
        /// <param name="size">Font point size.</param>
        /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param>
        /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
        /// <param name="imageOffset">Image offset.</param>
        /// <param name="texture">Texture atlas to be used.</param>
        public CCLabel(string str, string fntFile, float size, CCSize dimensions, CCLabelFormat labelFormat, CCPoint imageOffset, CCTexture2D texture)
        {
            quadCommand = new CCQuadCommand(str.Length);

            this.labelFormat = (size == 0 && labelFormat.FormatFlags == CCLabelFormatFlags.Unknown) 
                ? CCLabelFormat.BitMapFont 
                : labelFormat;

            if (this.labelFormat.FormatFlags == CCLabelFormatFlags.Unknown)
            {
                // First we try loading BitMapFont
                CCLog.Log("Label Format Unknown: Trying BitmapFont ...");
                InitBMFont(str, fntFile, dimensions, labelFormat.Alignment, labelFormat.LineAlignment, imageOffset, texture);
                // If we do not load a Bitmap Font then try a SpriteFont
                if (FontAtlas == null)
                {
                    CCLog.Log("Label Format Unknown: Trying SpriteFont ...");
                    InitSpriteFont(str, fntFile, size, dimensions, labelFormat, imageOffset, texture);
                }
                // If we do not load a Bitmap Font nor a SpriteFont then try the last time for a System Font
                if (FontAtlas == null)
                {
                    CCLog.Log("Label Format Unknown: Trying System Font ...");
                    LabelType = CCLabelType.SystemFont;
                    SystemFont = fntFile;
                    SystemFontSize = size;
                    Dimensions = dimensions;
                    AnchorPoint = CCPoint.AnchorMiddle;
                    BlendFunc = CCBlendFunc.AlphaBlend;
                    Text = str;
                }
            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.BitmapFont)
            {
                // Initialize the BitmapFont
                InitBMFont(str, fntFile, dimensions, labelFormat.Alignment, labelFormat.LineAlignment, imageOffset, texture);
            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.SpriteFont)
            {
                // Initialize the SpriteFont
                InitSpriteFont(str, fntFile, size, dimensions, labelFormat, imageOffset, texture);

            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.SystemFont)
            {
                LabelType = CCLabelType.SystemFont;
                SystemFont = fntFile;
                SystemFontSize = size;
                Dimensions = dimensions;
                AnchorPoint = CCPoint.AnchorMiddle;
                BlendFunc = CCBlendFunc.AlphaBlend;
                Text = str;
            }

        }