Last active
August 29, 2015 14:07
-
-
Save chaosddp/3ec7000b329973107223 to your computer and use it in GitHub Desktop.
Handle click/tap event of Image using WaveEngine, image resource is from examples of PhaserJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Using Statements | |
using System; | |
using WaveEngine.Common; | |
using WaveEngine.Common.Graphics; | |
using WaveEngine.Common.Math; | |
using WaveEngine.Components.Cameras; | |
using WaveEngine.Components.Gestures; | |
using WaveEngine.Components.Graphics2D; | |
using WaveEngine.Components.Graphics3D; | |
using WaveEngine.Framework; | |
using WaveEngine.Framework.Graphics; | |
using WaveEngine.Framework.Physics2D; | |
using WaveEngine.Framework.Resources; | |
using WaveEngine.Framework.Services; | |
#endregion | |
namespace ClickImageProject | |
{ | |
public class MyScene : Scene | |
{ | |
protected override void CreateScene() | |
{ | |
var camera = new FixedCamera2D("camera"); | |
EntityManager.Add(camera); | |
var imgTouchComp = new TouchGestures(); | |
imgTouchComp.TouchTap += (sender, e) => | |
{ | |
// 点击了这个Entity,做点什么? | |
System.Diagnostics.Debug.WriteLine("Yes, you clicked on me."); | |
}; | |
var img = new Entity() | |
.AddComponent(new Transform2D()) // 这个是必须的,否则谁知道画在哪? | |
.AddComponent(new RectangleCollider()) // Entity必须是可碰撞的才能使用TouchGestures,这里用的矩形碰撞 | |
.AddComponent(new Sprite("Content/ein")) | |
.AddComponent(new SpriteRenderer(DefaultLayers.Opaque)) | |
.AddComponent(imgTouchComp); | |
EntityManager.Add(img); | |
} | |
protected override void Start() | |
{ | |
base.Start(); | |
// This method is called after the CreateScene and Initialize methods and before the first Update. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment