Creator打地鼠游戏hitmouse.zip

Creator打地鼠游戏hitmouse.zipr // Learn cc.Class:r // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.htmlr // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.htmlr // Learn Attribute:r // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.htmlr // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.htmlr // Learn life-cycle callbacks:r // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.htmlr // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.htmlr r cc.Class({r extends: cc.Component,r r properties: {r mouse: [cc.Node],r hammer: cc.Node,r txtCount: cc.Label,r },r r // LIFE-CYCLE CALLBACKS:r r onLoad () {r var manager = cc.director.getCollisionManager();r manager.enabled = true;r r this.count = 0;r this.txtCount.string = this.count;r },r r start () {r cc.director.getScheduler().schedule(this.logic, this, 0.5, false);r r this.node.on(cc.Node.EventType.TOUCH_START, function(event){r for(let i = 0; i < this.mouse.length; i++){r if(this.mouse[i].opacity == 0){r continue;r }r r let parent = this.mouse[i].parent;r let maskPos = parent.convertToWorldSpaceAR(parent.position);r let maskRect = cc.rect(maskPos.x - parent.width / 2 , maskPos.y , parent.width, parent.height);r r let mouse = this.mouse[i];r let mousePos = parent.convertToWorldSpaceAR(mouse.position);r let mousRect = cc.rect(mousePos.x - mouse.width / 2, mousePos.y - mouse.height / 2, mouse.width, mouse.height);r r let mixRect = new cc.Rect();r maskRect.intersection(mixRect, mousRect);r r if(mixRect.contains(event.getLocation())){r this.hammer.position = parent.position;r this.hammer.active = true;r r this.count++;r this.txtCount.string = this.count;r break;r }, this);r r this.node.on(cc.Node.EventType.TOUCH_END, function(event){r this.hammer.active = false;r }, this);r },r r logic(){r let index = Math.floor(Math.random() * 9);r cc.log(`index:${index}`);r if(index < 0 || index >= this.mouse.length){r return;r }r r this.mouse[index].getComponent('mouse').appear();r },r r // update (dt) {},r });
zip 文件大小:468.46KB