Making assets react to clicks and touches
There are two ways to pick a tile, irrespective of whether you are playing with a touch or mouse-driven device. You can tap on a tile or you can click on it.
Picking a tile as an initial attempt
No matter the way you use Cocos2d-JS, all in all you are creating cross-platform games. You have to tell Cocos2d-JS you are going to let the user touch or click on some tiles, so the MemoryTile
class will change this way:
var MemoryTile = cc.Sprite.extend({
ctor:function() {
this._super();
this.initWithFile("assets/cover.png");
cc.eventManager.addListener(listener.clone(), this);
}
})
What just happened? You just added an event listener to the event manager. The event manager is the entity that triggers events fired by the game or by the player. The addListener
method adds a listener to the event manager, but you don't have a listener at the moment. Let's create one:
var listener = cc.EventListener.create({ event: cc.EventListener...