123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- const ArtistManager = require('../utils/ArtistManager')
- cc.Class({
- extends: cc.Component,
- properties: {
-
- nickLabel: cc.Label,
- runMan: cc.Node,
- artistSkeleton: sp.Skeleton,
- direction: {
- get: function () {
- if (!this._direction) {
- this._direction = 1;
- }
- return this._direction;
- },
- set: function(value) {
- this._direction = value;
- if (this.runMan) {
- }
- }
- },
- _accSpeed: 50,
- _maxX: 270,
- },
- init(artistData) {
- this.artistData = artistData;
- this.nickLabel.string = artistData.nick;
- this.animList = []
- // this.artistData.jobId 固定为2吧, 暂时只有舞者的骨骼动画
- ArtistManager.loadArtist(false, this.artistData.gender, 2)
- .then((skeletonData) => {
- this.artistSkeleton.skeletonData = skeletonData;
- this.artistSkeleton.setAnimation(0, 'walk1', true);
- }).catch((err) => {
- console.log(err);
- });
- },
- onLoad () {
- this.node.y = 20;
- this.isStand = false;
- this.totalDistance = 0;
- },
- update (dt) {
- if (this.isStand) { return; }
- // 每一帧移动多少距离, 这是固定的
- let distance = this._accSpeed * dt;
- this.totalDistance += distance;
-
- if (Math.floor(this.totalDistance) == 340) {
-
- this.totalDistance = 0;
- let random = Math.floor(Math.random() * 2);
- if (random === 0) { // walk
-
- let animKeyArray = ['walk1', 'walk2'];
- let walk = Math.floor(Math.random() * 2);
- if (walk === 0) {
- this.artistSkeleton.setAnimation(0, animKeyArray[walk], true);
- } else {
- this.artistSkeleton.setAnimation(0, animKeyArray[walk], false);
- this.artistSkeleton.setCompleteListener(() => {
- this.artistSkeleton.setAnimation(0, 'walk1', true);
- this.artistSkeleton.completeListener = null;
- });
- }
- } else { // stand
- let animKeyArray = ['stand1', 'stand2'];
- let stand = Math.floor(Math.random() * 2);
- this.artistSkeleton.setAnimation(0, animKeyArray[stand], false);
- this.artistSkeleton.setCompleteListener(() => {
- this.isStand = false;
- this.artistSkeleton.completeListener = null;
- this.artistSkeleton.setAnimation(0, 'walk1', true);
- });
- this.isStand = true;
- return;
- }
- }
- // 判断方向
- if (this.direction < 0) {
- this.runMan.scaleX = -1;
- if ((this.node.x + distance) > this._maxX) {
- this.direction = 1;
- this.artistSkeleton.setAnimation(0, 'walk1', true);
- } else {
- this.node.x = this.node.x + distance;
- }
- } else {
- this.runMan.scaleX = 1;
- if ((this.node.x - distance) < -this._maxX) {
- this.direction = -1;
- this.artistSkeleton.setAnimation(0, 'walk1', true);
- } else {
- this.node.x = this.node.x - distance;
- }
- }
- },
- });
|