HTML and CSS Reference
In-Depth Information
Figure 24-17. HalloweenDefence menu items
Creating Towers and Bullets
There are two different towers and two different types of bullets. The low-level tower attacks monsters with low-level
bullets, while the high-level tower attacks monsters with high-level bullets.
The towers are created by four properties: tower building, weapon type, attackable range, and bullet speed. You
will create a Monster layer to contain all of the monsters and add it to Game layer. The towers support positional
movement with touch input and automatically generated bullets with monsters robotically attacking when they enter
the attack range.
The towers need to register an input delegate when you want to use touch to control tower positions. You use
TargetedTouchDelegate and enable the target type API cc.registerTargetedDelegate() to swallow the input event.
Listing 24-14 provides the code to register touch for tower.
Listing 24-14. Register Touch for Towrers in Tower.js
var Tower = cc. Layer.extend ( {
onEnter : function ( ) {
this ._super ( ) ;
cc.registerTargetedDelegate ( 0 , true , this ) ; //Register input delegate
} ,
onExit : function ( ) {
this ._super ( ) ;
cc.unregisterTouchDelegate ( this ) ; // Unregister input delegate
} ,
onTouchBegan : function ( touch , event ) {
// check rect
if ( ! this.containsTouchLocation ( touch ) )
return false ;
this ._curPosition.x = this.getPositionX ( ) ;
this ._curPosition.y = this.getPositionY ( ) ;
this ._beganTouch = touch. getLocation ( ) ;
return true ;
} ,
 
Search WWH ::




Custom Search