• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Cocos2D.CCSpriteFrame类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: OnHandlePropTypeSpriteFrame

 protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame,
                                                     CCBReader reader)
 {
     if (propertyName == PROPERTY_NORMALDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetNormalSpriteFrame(spriteFrame);
         }
     }
     else if (propertyName == PROPERTY_SELECTEDDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetSelectedSpriteFrame(spriteFrame);
         }
     }
     else if (propertyName == PROPERTY_DISABLEDDISPLAYFRAME)
     {
         if (spriteFrame != null)
         {
             ((CCMenuItemImage) node).SetDisabledSpriteFrame(spriteFrame);
         }
     }
     else
     {
         base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader);
     }
 }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:29,代码来源:CCMenuItemImageLoader.cs


示例2: SpriteAnimationSplit

        public SpriteAnimationSplit()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation");

            // manually add frames to the frame cache
            CCSpriteFrame frame0 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 0, 132, 132));
            CCSpriteFrame frame1 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 0, 132, 132));
            CCSpriteFrame frame2 = new CCSpriteFrame(texture, new CCRect(132 * 2, 132 * 0, 132, 132));
            CCSpriteFrame frame3 = new CCSpriteFrame(texture, new CCRect(132 * 3, 132 * 0, 132, 132));
            CCSpriteFrame frame4 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 1, 132, 132));
            CCSpriteFrame frame5 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 1, 132, 132));

            //
            // Animation using Sprite BatchNode
            //
            CCSprite sprite = new CCSprite(frame0);
            sprite.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2));
            AddChild(sprite);

            var animFrames = new List<CCSpriteFrame>(6);
            animFrames.Add(frame0);
            animFrames.Add(frame1);
            animFrames.Add(frame2);
            animFrames.Add(frame3);
            animFrames.Add(frame4);
            animFrames.Add(frame5);

            CCAnimation animation = new CCAnimation(animFrames, 0.2f);
            CCAnimate animate = new CCAnimate (animation);
            CCActionInterval seq = (CCActionInterval)(new CCSequence(animate,
                               new CCFlipX(true),
                              (CCFiniteTimeAction)animate.Copy(),
                               new CCFlipX(false)
                               ));

            sprite.RunAction(new CCRepeatForever (seq));
            //animFrames->release();    // win32 : memory leak    2010-0415
        }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:40,代码来源:SpriteAnimationSplit.cs


示例3: LoadCocos2DDictionary

		private void LoadCocos2DDictionary(PlistDictionary dict, CCTexture2D texture)
		{
			
			PlistDictionary metadataDict = null;

			if (dict.ContainsKey("metadata"))
			{
				metadataDict = dict["metadata"].AsDictionary;
			}

			PlistDictionary framesDict = null;
			if (dict.ContainsKey("frames"))
			{
				framesDict = dict["frames"].AsDictionary;
			}

			// get the format
			int format = 0;
			if (metadataDict != null)
			{
				format = metadataDict["format"].AsInt;
			}

			// check the format
			if (format < 0 || format > 3)
			{
				throw (new NotSupportedException("PList format " + format + " is not supported."));
			}

			foreach (var pair in framesDict)
			{
				PlistDictionary frameDict = pair.Value.AsDictionary;
				CCSpriteFrame spriteFrame = null;

				if (format == 0)
				{
					float x = 0f, y = 0f, w = 0f, h = 0f;
					x = frameDict["x"].AsFloat;
					y = frameDict["y"].AsFloat;
					w = frameDict["width"].AsFloat;
					h = frameDict["height"].AsFloat;
					float ox = 0f, oy = 0f;
					ox = frameDict["offsetX"].AsFloat;
					oy = frameDict["offsetY"].AsFloat;
					int ow = 0, oh = 0;
					ow = frameDict["originalWidth"].AsInt;
					oh = frameDict["originalHeight"].AsInt;
					// check ow/oh
					if (ow == 0 || oh == 0)
					{
						CCLog.Log(
							"cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag");
					}
					// abs ow/oh
					ow = Math.Abs(ow);
					oh = Math.Abs(oh);

					// create frame
					spriteFrame = new CCSpriteFrame(
						texture,
						new CCRect(x, y, w, h),
						false,
						new CCPoint(ox, oy),
						new CCSize(ow, oh)
						);
				}
				else if (format == 1 || format == 2)
				{
					var frame = CCRect.Parse(frameDict["frame"].AsString);
					bool rotated = false;

					// rotation
					if (format == 2)
					{
						if (frameDict.ContainsKey("rotated"))
						{
							rotated = frameDict["rotated"].AsBool;
						}
					}

					var offset = CCPoint.Parse(frameDict["offset"].AsString);
					var sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString);

					// create frame
					spriteFrame = new CCSpriteFrame(texture, frame, rotated, offset, sourceSize);
				}
				else if (format == 3)
				{
					var spriteSize = CCSize.Parse(frameDict["spriteSize"].AsString);
					var spriteOffset = CCPoint.Parse(frameDict["spriteOffset"].AsString);
					var spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString);
					var textureRect = CCRect.Parse(frameDict["textureRect"].AsString);

					bool textureRotated = false;

					if (frameDict.ContainsKey("textureRotated"))
					{
						textureRotated = frameDict["textureRotated"].AsBool;
					}

//.........这里部分代码省略.........
开发者ID:GrimDerp,项目名称:cocos2d-xna,代码行数:101,代码来源:CCSpriteSheet.cs


示例4: CCMaskedSprite

 public CCMaskedSprite(CCSpriteFrame pSpriteFrame, byte[] mask)
     : base(pSpriteFrame)
 {
     _MyMask = mask;
 }
开发者ID:huaqiangs,项目名称:cocos2d-xna,代码行数:5,代码来源:CCMaskedSprite.cs


示例5: InitWithSpriteFrame

        public virtual bool InitWithSpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets)
        {
            Debug.Assert(spriteFrame != null, "Sprite frame must be not nil");

            CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9);
            bool pReturn = InitWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, capInsets);
            return pReturn;
        }
开发者ID:liwq-net,项目名称:UIFactory,代码行数:8,代码来源:CCScale9Sprite.cs


示例6: AddSpriteFrame

 public void AddSpriteFrame(CCSpriteFrame pobFrame, string pszFrameName)
 {
     if (!_AllowFrameOverwrite && m_pSpriteFrames.ContainsKey(pszFrameName))
     {
         throw (new ArgumentException("The frame named " + pszFrameName + " already exists."));
     }
     m_pSpriteFrames[pszFrameName] = pobFrame;
 }
开发者ID:nilcrabaniel,项目名称:cocos2d-xna,代码行数:8,代码来源:CCSpriteFrameCache.cs


示例7: AddSpriteFrameWithTexture

 public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect)
 {
     CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect);
     AddSpriteFrame(pFrame);
 }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:5,代码来源:CCAnimation.cs


示例8: AddSpriteFrame

        public void AddSpriteFrame(CCSpriteFrame pFrame)
        {
            var animFrame = new CCAnimationFrame();
            animFrame.InitWithSpriteFrame(pFrame, 1.0f, null);
            m_pFrames.Add(animFrame);

            // update duration
            m_fTotalDelayUnits++;
        }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:9,代码来源:CCAnimation.cs


示例9: SetBackgroundSpriteFrameForState

        /**
     * Sets the background spriteFrame to use for the specified button state.
     *
     * @param spriteFrame The background spriteFrame to use for the specified state.
     * @param state The state that uses the specified image. The values are described
     * in "CCControlState".
     */

        public virtual void SetBackgroundSpriteFrameForState(CCSpriteFrame spriteFrame, CCControlState state)
        {
            CCScale9Sprite sprite = new CCScale9SpriteFrame(spriteFrame);
            SetBackgroundSpriteForState(sprite, state);
        }
开发者ID:rtabbara,项目名称:cocos2d-xna,代码行数:13,代码来源:CCControlButton.cs


示例10: SetSelectedSpriteFrame

 public void SetSelectedSpriteFrame(CCSpriteFrame frame)
 {
     SelectedImage = new CCSprite(frame);
 }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:4,代码来源:CCMenuItemImage.cs


示例11: LoadAppleDictionary

		private void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture)
		{

			var version = dict.ContainsKey ("version") ? dict ["version"].AsInt : 0; 

			if (version != 1)
				throw (new NotSupportedException("Binary PList version " + version + " is not supported."));


			var images = dict.ContainsKey ("images") ? dict ["images"].AsArray : null;

			foreach (var imageEntry in images) 
			{
				// we only support one image for now
				var imageDict = imageEntry.AsDictionary;

				var path = imageDict ["path"].AsString;

				path = Path.Combine(plistFilePath, CCFileUtils.RemoveExtension(path));

				if (!CCTextureCache.SharedTextureCache.Contains (path))
					texture = CCTextureCache.SharedTextureCache.AddImage (path);
				else
					texture = CCTextureCache.SharedTextureCache[path];



				// size not used right now
				//var size = CCSize.Parse(imageDict ["size"].AsString);

				var subImages = imageDict ["subimages"].AsArray;

				foreach (var subImage in subImages) {
					CCSpriteFrame spriteFrame = null;

					var subImageDict = subImage.AsDictionary;
					var name = subImageDict ["name"].AsString;
					var alias = subImageDict ["alias"].AsString;
					var isFullyOpaque = true;

					if (subImageDict.ContainsKey ("isFullyOpaque"))
						isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool;

					var textureRect = CCRect.Parse (subImageDict ["textureRect"].AsString);
					var spriteOffset = CCPoint.Parse (subImageDict ["spriteOffset"].AsString);

					// We are going to override the sprite offset for now to be 0,0
					// It seems the offset is calculated off of the original size but if 
					// we pass this offset it throws our center position calculations off.
					spriteOffset = CCPoint.Zero;

					var textureRotated = false;
					if (subImageDict.ContainsKey ("textureRotated")) {
						textureRotated = subImageDict ["textureRotated"].AsBool;
					}
					var spriteSourceSize = CCSize.Parse (subImageDict ["spriteSourceSize"].AsString);
					var frameRect = textureRect;
					if (textureRotated)
						frameRect = new CCRect (textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width);

#if DEBUG
					CCLog.Log ("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize);
#endif

					// create frame
					spriteFrame = new CCSpriteFrame (
						texture,
						frameRect,
						textureRotated,
						spriteOffset,
						spriteSourceSize
					);


					_spriteFrames [name] = spriteFrame;
				}
			}
		}
开发者ID:GrimDerp,项目名称:cocos2d-xna,代码行数:78,代码来源:CCSpriteSheet.cs


示例12: InitWithSpriteFrame

 protected virtual bool InitWithSpriteFrame(CCSpriteFrame pSpriteFrame)
 {
     mSpriteFrame = pSpriteFrame;
     return true;
 }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:5,代码来源:CCBAnimationManager.cs


示例13: CCBSetSpriteFrame

 public CCBSetSpriteFrame(CCSpriteFrame pSpriteFrame)
 {
     InitWithSpriteFrame(pSpriteFrame);
 }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:4,代码来源:CCBAnimationManager.cs


示例14: CreateAnimateAction

        public CCAnimate CreateAnimateAction()
        {
            var frameList = new List<CCSpriteFrame>();

            for (var i = 0; i < 7; i++)
            {
                var texture = CreateCharacterTexture();

                var sprite = new CCSpriteFrame(texture, new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height));
                frameList.Add(sprite);
            }
            var animation = new CCAnimation(frameList, 0.1f);
            var animate = new CCAnimate (animation);

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


示例15: SetSpriteFrame

        public void SetSpriteFrame(CCSpriteFrame spriteFrame)
        {
            CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9);
            UpdateWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, CCRect.Zero);

            // Reset insets
            _insetLeft = 0;
            _insetTop = 0;
            _insetRight = 0;
            _insetBottom = 0;
        }
开发者ID:liwq-net,项目名称:UIFactory,代码行数:11,代码来源:CCScale9Sprite.cs


示例16: SetNormalSpriteFrame

 public void SetNormalSpriteFrame(CCSpriteFrame frame)
 {
     NormalImage = new CCSprite(frame);
 }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:4,代码来源:CCMenuItemImage.cs


示例17: OnHandlePropTypeSpriteFrame

 protected virtual void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame,
                                                    CCBReader reader)
 {
     CCLog.Log("Unexpected property type: '{0}'!", propertyName);
     Debug.Assert(false);
 }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:6,代码来源:CCNodeLoader.cs


示例18: SetDisabledSpriteFrame

 public void SetDisabledSpriteFrame(CCSpriteFrame frame)
 {
     DisabledImage = new CCSprite(frame);
 }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:4,代码来源:CCMenuItemImage.cs


示例19: ParsePropTypeSpriteFrame

        protected virtual CCSpriteFrame ParsePropTypeSpriteFrame(CCNode node, CCNode parent, CCBReader reader, string propertyName)
        {
            string spriteSheet = reader.ReadCachedString();
            string spriteFile = reader.ReadCachedString();

            CCSpriteFrame spriteFrame = null;
            if (spriteFile.Length != 0)
            {
                if (spriteSheet.Length == 0)
                {
                    spriteFile = reader.CCBRootPath + spriteFile;
                    CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage(CCFileUtils.RemoveExtension(spriteFile));
                    var bounds = new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height);
                    spriteFrame = new CCSpriteFrame(texture, bounds);
                }
                else
                {
                    CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache;
                    spriteSheet = reader.CCBRootPath + spriteSheet;

                    // Load the sprite sheet only if it is not loaded
                    if (!reader.LoadedSpriteSheet.Contains(spriteSheet))
                    {
                        frameCache.AddSpriteFramesWithFile(spriteSheet);
                        reader.LoadedSpriteSheet.Add(spriteSheet);
                    }

                    spriteFrame = frameCache.SpriteFrameByName(spriteFile);
                }

                if (reader.AnimatedProperties.Contains(propertyName))
                {
                    reader.AnimationManager.SetBaseValue(spriteFrame, node, propertyName);
                }
            }

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


示例20: AddSprite

 public void AddSprite(CCSprite sprite)
 {
     CCSpriteFrame f = new CCSpriteFrame(sprite.Texture, new CCRect(0, 0, sprite.ContentSize.Width, sprite.ContentSize.Height));
     AddSpriteFrame(f);
 }
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:5,代码来源:CCAnimation.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cocos2D.CCTexture2D类代码示例发布时间:2022-05-24
下一篇:
C# Cocos2D.CCSprite类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap