当前位置: 首页>>代码示例>>C#>>正文


C# Cocos2D.CCTexture2D类代码示例

本文整理汇总了C#中Cocos2D.CCTexture2D的典型用法代码示例。如果您正苦于以下问题:C# CCTexture2D类的具体用法?C# CCTexture2D怎么用?C# CCTexture2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CCTexture2D类属于Cocos2D命名空间,在下文中一共展示了CCTexture2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateNativeLabel

        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();
			texture.InitWithStream (SaveToStream(), Microsoft.Xna.Framework.Graphics.SurfaceFormat.Bgra4444);

			return texture;
		}
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:60,代码来源:CCLabelUtilities-Gdi.cs

示例2: InitWithSize

        protected virtual bool InitWithSize(CCGridSize gridSize, CCTexture2D 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.X = texSize.Width / m_sGridSize.X;
            m_obStep.Y = texSize.Height / m_sGridSize.Y;

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

            //m_pShaderProgram = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture);
            CalculateVertexPoints();

            return bRet;
        }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:31,代码来源:CCGridBase.cs

示例3: CreateAtlasFromTexture2D

        public static CCTextureAtlas CreateAtlasFromTexture2D(Microsoft.Xna.Framework.Graphics.Texture2D texture2d)
        {
            CCTexture2D texture = new CCTexture2D();
            texture.InitWithTexture(texture2d);

            CCTextureAtlas textureAtlas = CCTextureAtlas.Create(texture, 128);
            return textureAtlas;
        }
开发者ID:netonjm,项目名称:spine-runtimes,代码行数:8,代码来源:spine-cocos2dx.cs

示例4: CreateTexture

 public static Cocos2D.CCTexture2D CreateTexture(Stream stream)
 {
     PngDecoder png = new PngDecoder();
     byte[] colors = png.Decode(stream);
     CCTexture2D cctexture = new CCTexture2D();
     cctexture.InitWithRawData<byte>(colors, Microsoft.Xna.Framework.Graphics.SurfaceFormat.Color, png.Width, png.Height, false);
     return cctexture;
 }
开发者ID:liwq-net,项目名称:UIFactory,代码行数:8,代码来源:Factory.cs

示例5: initWithTexture

 public bool initWithTexture(CCTexture2D aTexture)
 {
     if (base.InitWithTexture(aTexture))
     {
         m_state = PaddleState.kPaddleStateUngrabbed;
     }
     return true;
 }
开发者ID:pekayatt,项目名称:cocos2d-xna,代码行数:8,代码来源:Paddle.cs

示例6: InitWithTexture

        /*
         * init with CCTexture2D
         */

        public bool InitWithTexture(CCTexture2D tex, int capacity)
        {
            TextureAtlas.InitWithTexture(tex, capacity);

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

            m_tBlendFunc = CCBlendFunc.AlphaBlend;

            return true;
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:15,代码来源:CCParticleBatchNode.cs

示例7: InitializeTTFAtlas

        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 });
        }
开发者ID:huaqiangs,项目名称:cocos2d-xna,代码行数:12,代码来源:CCLabel.cs

示例8: InitWithTexture

        /*
         * init with CCTexture2D
         */

        public bool InitWithTexture(CCTexture2D tex, int capacity)
        {
            TextureAtlas.InitWithTexture(tex, capacity);

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

            m_tBlendFunc.Source = CCMacros.CCDefaultSourceBlending;
            m_tBlendFunc.Destination = CCMacros.CCDefaultDestinationBlending;

            //setShaderProgram(CCShaderCache::sharedShaderCache().programForKey(kCCShader_PositionTextureColor));

            return true;
        }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:18,代码来源:CCParticleBatchNode.cs

示例9: MakeTexture

        private void MakeTexture()
        {
            m_pTexture = new CCTexture2D();
            m_pTexture.OnReInit = TextureReInit;
            m_pTexture.IsAntialiased = false;

            m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(m_Width, m_Height, m_ColorFormat, m_DepthFormat, m_Usage);
            m_pTexture.InitWithTexture(m_pRenderTarget2D, m_ColorFormat, true, false);

            m_bFirstUsage = true;

            m_pSprite = new CCSprite(m_pTexture);
            //m_pSprite.scaleY = -1;
            m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend;

            AddChild(m_pSprite);
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:17,代码来源:CCRenderTexture.cs

示例10: InitWithWidthAndHeight

        protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage)
        {
            w = (int)Math.Ceiling(w * CCMacros.CCContentScaleFactor());
            h = (int)Math.Ceiling(h * CCMacros.CCContentScaleFactor());

            m_pTexture = new CCTexture2D();
			m_pTexture.IsAntialiased = false;

            m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage);
            m_pTexture.InitWithTexture(m_pRenderTarget2D, colorFormat, true, false);

            m_bFirstUsage = true;

            m_pSprite = new CCSprite(m_pTexture);
            //m_pSprite.scaleY = -1;
            m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend;

            AddChild(m_pSprite);

            return true;
        }
开发者ID:womandroid,项目名称:cocos2d-xna,代码行数:21,代码来源:CCRenderTexture.cs

示例11: InitWithWidthAndHeight

        protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage)
        {
            w = (w * CCMacros.CCContentScaleFactor());
            h = (h * CCMacros.CCContentScaleFactor());

            m_pTexture = new CCTexture2D();
            m_pTexture.SetAliasTexParameters();

            m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage);
            m_pTexture.InitWithTexture(m_pRenderTarget2D);

            m_bFirstUsage = true;

            m_pSprite = new CCSprite(m_pTexture);
            //m_pSprite.scaleY = -1;
            m_pSprite.BlendFunc = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); // OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);

            AddChild(m_pSprite);

            return true;
        }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:21,代码来源:CCRenderTexture.cs

示例12: InitWithTexture

        protected virtual bool InitWithTexture(CCTexture2D tex, int capacity)
        {
            m_blendFunc = CCBlendFunc.AlphaBlend;

            m_pobTextureAtlas = new CCTextureAtlas();

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

            ContentSize= tex.ContentSize; // @@ TotallyEvil - contentSize should return the size of the sprite sheet
            m_pobTextureAtlas.InitWithTexture(tex, capacity);

            UpdateBlendFunc();

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

            return true;
        }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:22,代码来源:CCSpriteBatchNode.cs

示例13: AddSpriteFramesWithDictionary

 public void AddSpriteFramesWithDictionary(PlistDictionary pobDictionary, CCTexture2D pobTexture)
 {
     AddSpriteFramesWithDictionary(pobDictionary, pobTexture, string.Empty);
 }
开发者ID:nilcrabaniel,项目名称:cocos2d-xna,代码行数:4,代码来源:CCSpriteFrameCache.cs

示例14: AddSpriteFramesWithFile

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pszPlist"></param>
        /// <param name="pobTexture"></param>
        /// <param name="framePrefix"></param>
        /// <returns>The framePrefix parameter</returns>
        public string AddSpriteFramesWithFile(string pszPlist, CCTexture2D pobTexture, string framePrefix)
        {
            PlistDocument document = CCContentManager.SharedContentManager.Load<PlistDocument>(pszPlist);

            PlistDictionary dict = document.Root.AsDictionary;

            AddSpriteFramesWithDictionary(dict, pobTexture, framePrefix);
            return (framePrefix);
        }
开发者ID:nilcrabaniel,项目名称:cocos2d-xna,代码行数:16,代码来源:CCSpriteFrameCache.cs

示例15: updateTexture

        private void updateTexture()
        {
            CCTexture2D tex;

            // Dump the old one
            if (Texture != null)
            {
                Texture.Dispose();
            }

            // let system compute label's width or height when its value is 0
            // refer to cocos2d-x issue #1430
            tex = new CCTexture2D();

            tex.InitWithString(m_pString,
                               CCMacros.CCSizePointsToPixels(m_tDimensions),
                               m_hAlignment,
                               m_vAlignment,
                               m_pFontName,
                               m_fFontSize * CCMacros.CCContentScaleFactor());

            Texture = tex;

            CCRect rect = CCRect.Zero;
            rect.Size = m_pobTexture.ContentSize;
            SetTextureRect(rect);
        }
开发者ID:pekayatt,项目名称:cocos2d-xna,代码行数:27,代码来源:CCLabelTTF.cs


注:本文中的Cocos2D.CCTexture2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。