本文整理汇总了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);
})
);
}
示例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);
}