pubgv3/assets/scripts/teach/teachGamePanel.js
zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

71 lines
1.5 KiB
JavaScript

cc.Class({
extends: cc.Component,
properties: {
joyMoveNd: {
default: null,
type: cc.Node,
},
joyShootNd: {
default: null,
type: cc.Node,
},
playerNd: {
default: null,
type: cc.Node,
},
playerSpine: {
default: null,
type: sp.Skeleton,
},
},
onLoad() {
this.moveJoy = this.joyMoveNd.getComponent('Joystick');
this.shootJoy = this.joyShootNd.getComponent('Joystick');
this.selfPlayer = this.playerNd.getComponent('playerCtrl');
//
this.moveJoy.bindStartCb(this.joyMoveBegin.bind(this));
this.moveJoy.bindMoveCb(this.joyMove.bind(this));
this.moveJoy.bindEndCb(this.joyMoveEnd.bind(this));
},
joyMoveBegin() {
this.selfPlayer && this.selfPlayer.joyMoveBegin();
this.playerSpine.setAnimation(0, 'throw_run', true);
},
joyMove(ag, dis) {
this.selfPlayer && this.selfPlayer.joyMove(ag, dis);
this.moveing = true;
this.ag = ag;
},
joyMoveEnd() {
this.selfPlayer && this.selfPlayer.joyMoveEnd();
this.moveing = false;
this.playerSpine.setAnimation(0, 'throw_idle', true);
},
update() {
if (this.moveing) {
//ag += 45
var dir = cc.v2(
Math.cos(this.ag * (Math.PI / 180)),
Math.sin(this.ag * (Math.PI / 180))
);
this.dir = dir.normalize();
if (this.dir.x >= 0) {
this.playerSpine.node.parent.scaleX = 1;
} else {
this.playerSpine.node.parent.scaleX = -1;
}
this.playerNd.x += this.dir.x;
this.playerNd.y += this.dir.y;
}
},
});