1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| onEnter:function() { this._super(); cc.log("初始化完成"); cc.eventManager.addListener({ event:cc.EventListener.TOUCH_ONE_BY_ONE, swallowTouches:true, onTouchBegan:this.touchbegan, onTouchMoved:this.touchmoved, onTouchEnded:this.touchended },this);
}, onExit:function() { this._super(); cc.log("即将消失"); }, touchbegan:function(touch,event){ cc.log("按下"); var nownpc=event.getCurrentTarget().getChildByTag(1); var attack=event.getCurrentTarget().getChildByTag(2); var startHp = nownpc.hp; if(touch.getLocation().x>=attack.getPositionX()-attack.width&&touch.getLocation().x<=attack.getPositionX()+attack.width &&touch.getLocation().y>=attack.getPositionY()-attack.height&&touch.getLocation().y<=attack.getPositionY()+attack.height){ nownpc.attacked(2,event.getCurrentTarget()); var reduceHp = nownpc.hp-startHp; var num = new cc.LabelTTF(""+Math.round(reduceHp),"",40); num.setColor(cc.color(255,0,0,255)); num.setPosition(nownpc.getPositionX(),nownpc.getPositionY()+nownpc.height/2); event.getCurrentTarget().addChild(num); num.runAction( new cc.sequence( new cc.spawn( cc.moveBy(0.5,cc.p(0,50)),cc.fadeOut(0.5) ),new cc.callFunc(function(num){ num.removeFromParent(); },num) ) ); attack.runAction(new cc.sequence(cc.scaleTo(0.2,1.1),cc.scaleTo(0.1,0.9),cc.scaleTo(0.1,1))); } return true; }, touchmoved:function(touch,event) { cc.log("移动"); }, touchend:function(touch,event) { cc.log("抬起"); }
|