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


C# CCSprite.AddEventListener方法代码示例

本文整理汇总了C#中CocosSharp.CCSprite.AddEventListener方法的典型用法代码示例。如果您正苦于以下问题:C# CCSprite.AddEventListener方法的具体用法?C# CCSprite.AddEventListener怎么用?C# CCSprite.AddEventListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CocosSharp.CCSprite的用法示例。


在下文中一共展示了CCSprite.AddEventListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnEnter

		public override void OnEnter ()
		{

			spriteSaved = false;

			base.OnEnter ();

			var origin = Layer.VisibleBoundsWorldspace.Origin;
			var size = Layer.VisibleBoundsWorldspace.Size;

			//MenuItemFont::setFontSize(20);

			var sprite = new CCSprite("Images/CyanSquare.png");
			sprite.Position = origin + size.Center;
			AddChild(sprite, 10);

			// Make sprite1 touchable
			var listener1 = new CCEventListenerTouchOneByOne ();
			listener1.IsSwallowTouches = true;

			listener1.OnTouchBegan = (touch, touchEvent) => 
			{
				var target = (CCSprite) touchEvent.CurrentTarget;

				var locationInNode = target.Layer.ScreenToWorldspace(touch.LocationOnScreen);
				var s = target.ContentSize;
				var rect = new CCRect(0, 0, s.Width, s.Height);

				if (rect.ContainsPoint(locationInNode))
				{
					CCLog.Log("sprite began... x = {0}, y = {1}", locationInNode.X, locationInNode.Y);
					target.Opacity = 180;
					return true;
				}
				return false;
			};

			listener1.OnTouchMoved = (touch, touchEvent) =>
			{
				var target = (CCSprite) touchEvent.CurrentTarget;
				target.Position += touch.Delta;
			};

			listener1.OnTouchEnded = (touch, touchEvent) =>
			{
				var target = (CCSprite) touchEvent.CurrentTarget;
				CCLog.Log("sprite onTouchesEnded.. ");
				target.Opacity = 255;
			};

            sprite.AddEventListener(listener1);

			RunActions(new CCDelayTime(5.0f),
				new CCCallFunc(() => 
				{
					spriteSaved = true;
					sprite.RemoveFromParent();
				}),
				new CCDelayTime(5.0f),
				new CCCallFunc(() =>
				{
					spriteSaved = false;
					AddChild(sprite);
				})
			);


		}
开发者ID:netonjm,项目名称:CocosSharp,代码行数:68,代码来源:EventDispatcherTestDemo.cs

示例2: OnEnter

        public override void OnEnter()
        {
            base.OnEnter();

            var visibleBounds = VisibleBoundsWorldspace;
            var origin = VisibleBoundsWorldspace.Origin;
            var size = VisibleBoundsWorldspace.Size;

            var sprite1 = new CCSprite("Images/CyanSquare.png");
            sprite1.Position = origin + size.Center + new CCPoint(-80, 80);
            AddChild(sprite1, 10);

            var follow = new CCFollow(sprite1, new CCRect(0, 0, 3000, 600));
            RunAction(follow);

            sprite1.PositionX = size.Width + 100;
            sprite1.PositionY = size.Height / 2;

            // Make sprite1 touchable
            var listener1 = new CCEventListenerTouchOneByOne();
            listener1.IsSwallowTouches = true;

            listener1.OnTouchBegan = (touch, touchEvent) =>
            {
                var layerOffset = Layer.PositionWorldspace;
                var target = (CCSprite)touchEvent.CurrentTarget;
                var locationInNode = touch.Location;

                CCRect rect = target.BoundingBoxTransformedToWorld;
                rect.Origin += layerOffset;

                if (rect.ContainsPoint(locationInNode))
                {
                    CCLog.Log("sprite began... x = {0}, y = {1}", locationInNode.X, locationInNode.Y);
                    target.Opacity = 180;
                    return true;
                }
                return false;
            };

            listener1.OnTouchMoved = (touch, touchEvent) =>
            {
                var target = (CCSprite)touchEvent.CurrentTarget;
                CCPoint pt = touch.PreviousLocation + touch.Delta;
                target.Position = target.WorldToParentspace(pt);
            };

            listener1.OnTouchEnded = (touch, touchEvent) =>
            {
                var target = (CCSprite)touchEvent.CurrentTarget;
                CCLog.Log("sprite onTouchesEnded..");
                target.Opacity = 255;
            };


            sprite1.AddEventListener(listener1);

        }
开发者ID:Kingwl,项目名称:CocosSharp,代码行数:58,代码来源:EventDispatcherTestDemo.cs


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