这章主要介绍怪物AI
1:环境
cococreator2.4.*
2:规则
当前规则很简单,就是跳上,跳下 一个土块
3:上代码
// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var MoveDir = require('utils');
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// // ATTRIBUTES:
// default: null, // The default value will be used only when the component attaching
// // to a node for the first time
// type: cc.SpriteFrame, // optional, default is typeof default
// serializable: true, // optional, default is true
// },
// bar: {
// get () {
// return this._bar;
// },
// set (value) {
// this._bar = value;
// }
// },
curdir:{
type:cc.Enum(MoveDir),
default:MoveDir.DIR_X_SUB,
},
curmovespeed:32, //1秒64 pix
basejumpheight:128,
curstate:0, // 0 idle, 1 walk 2 jump 3 work
curpos:null,
jumppos:null,
curdt:0.0,
node:null,
modelgridwidth:0,
modelgridheight:0,
modelwidth:0,
modelheight:0,
// delaycurdis:0,//pix
// delayopr:[0,0,0,0],//opr, disx,disy,jumpheight
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
if(this.curstate == 1){
let t1 = this.node.getComponent(dragonBones.ArmatureDisplay);
t1.playAnimation('walk', 0);
this.checknextstep_20231019();
}
},
start () {
},
update (dt) {
const mingep = 0.02;
this.curdt += dt ;
if(this.curdt < mingep){
return ;
}
switch(this.curstate){
case 0://idle
break;
case 1:{ //walk
this.walk(this.curdt);
this.checknextstep_20231019();
}
break;
case 2:{ //jump
}
break;
case 3:{ //work
}
break;
case 4://walk before jump 跳前的移动
{
this.walk(this.curdt);
}
break;
}
this.curdt = 0.0 ;
},
getparamsbydir:function(){
switch(this.curdir){//{MIN,MAX}
case MoveDir.DIR_X_ADD: return [1,0 ]; break;
case MoveDir.DIR_Y_ADD: return [0,1] ; break;
case MoveDir.DIR_X_SUB: return [-1,0] ; break;
case MoveDir.DIR_Y_SUB: return [0,-1] ; break;
}
return [0,0];
},
changedir:function(){
switch(this.curdir){
case MoveDir.DIR_X_ADD: {this.curdir = MoveDir.DIR_X_SUB;this.node.scaleX = -this.node.scaleX;} break;
case MoveDir.DIR_Y_ADD:{this.curdir = MoveDir.DIR_Y_SUB; this.node.scaleY = -this.node.scaleY; }break;
case MoveDir.DIR_X_SUB:{this.curdir = MoveDir.DIR_X_ADD; this.node.scaleX = -this.node.scaleX;}break;
case MoveDir.DIR_Y_SUB:{this.curdir = MoveDir.DIR_Y_ADD; this.node.scaleY = -this.node.scaleY;}break;
}
// this.node.scaleX = -this.node.scaleX; //左右翻转 scaleX Number 节点 X 轴缩放
},
walkandjump:function(usebodywidthpix,disx,disy,height){
let [dirx,diry] = this.getparamsbydir();
let t = usebodywidthpix/this.curmovespeed ;
///
var arr = [];
arr.push(cc.spawn(cc.moveBy(t, cc.v2(usebodywidthpix*dirx, 0)),cc.callFunc(function(){
this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('walk', 0);
},this)) );
// arr.push(cc.spawn(cc.delayTime(0.2),cc.callFunc(function(){
// this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('idle', 0);
// },this)) );
arr.push(cc.spawn(cc.jumpBy(0.8, disx, disy,height,1).easing(cc.easeCubicActionOut()),cc.callFunc(function(){
this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('jump', 0);
},this)) );
arr.push(cc.callFunc(this.jumpEndAnimation, this));
var act = cc.sequence(arr);
this.node.runAction(act);
this.curstate = 2 ; //jump
//
// var actionTo = cc.moveBy(t, cc.v2(usebodywidthpix*dirx, 0));//.easing(cc.easeCubicActionOut());
// var walkAnimationCallBack = cc.callFunc(this.jumpEndAnimation, this);
// var actionJumpTO = cc.jumpBy(0.8, disx, disy,height,1).easing(cc.easeCubicActionOut()); //targetx 移动距离 targety 移动距离 jump高度 次数
// var tiaoAnimationCallBack = cc.callFunc(this.jumpEndAnimation, this);
// var animationQueue = cc.sequence(actionTo,actionJumpTO,tiaoAnimationCallBack);
// this.node.runAction(animationQueue) //调用
// this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('walk', 0);
// this.curstate = 2 ; //jump
/
// setJumpAction:function(){
// //跳跃上升
// var jumpUp=cc.moveBy(this.jumpDuration,cc.v2(0,this.jumpHeight)).easing(cc.easeCubicActionOut());
// //下落
// var jumpDown=cc.moveBy(this.jumpDuration,cc.v2(0,-this.jumpHeight)).easing(cc.easeCubicActionOut());
// //不断重复
// return cc.repeatForever(cc.sequence(jumpUp,jumpDown));
// },
},
jumpanimation:function(){
this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('jump', 0);
},
//跳结束动画
walkEndAnimation:function(){
this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('jump', 0);
this.curstate = 2 ; //walk
// let t1 = this.node.getComponent(dragonBones.ArmatureDisplay);
// t1.playAnimation('walk', 0);
// this.checknextstep();
},
jump:function(disx,disy,height){
//向上移动
// var actionJumpTO = cc.jumpBy(2, -64, 128,128,1);
var actionJumpTO = cc.jumpBy(0.8, disx, disy,height,1).easing(cc.easeCubicActionOut());; //targetx 移动距离 targety 移动距离 jump高度 次数
// //向下移动
// var moveDown = cc.moveTo(0.7, cc.v2(-255, -152)).easing(cc.easeCubicActionIn());
var tiaoAnimationCallBack = cc.callFunc(this.jumpEndAnimation, this);
var animationQueue = cc.sequence(actionJumpTO,tiaoAnimationCallBack);
this.node.runAction(animationQueue) //调用
this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('jump', 0);
this.curstate = 2 ; //jump
},
//搞不定 目标坐标
jumpto:function(gepsec,targetx,targety,height){
//向上移动
// var actionJumpTO = cc.jumpBy(2, -64, 128,128,1);
var actionJumpTO = cc.jumpto(gepsec, targetx, targety,height,1); //targetx 移动距离 targety 移动距离 jump高度 次数
// //向下移动
// var moveDown = cc.moveTo(0.7, cc.v2(-255, -152)).easing(cc.easeCubicActionIn());
var tiaoAnimationCallBack = cc.callFunc(this.jumpEndAnimation, this);
var animationQueue = cc.sequence(actionJumpTO,tiaoAnimationCallBack);
this.node.runAction(animationQueue) //调用
this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('jump', 0);
this.curstate = 2 ; //jump
},
idle:function(delay,changedir){
let t1 = this.node.getComponent(dragonBones.ArmatureDisplay);
t1.playAnimation('idle', 0);
this.curstate = 0 ; //idle
// const ms1 = new Date().getTime();
// console.log(ms1+" idle "+ t1.animationName);
if(!!delay && !!changedir){
var self = this;
setTimeout(()=>{
self.changedir();
// const ms2 = new Date().getTime();
// console.log(ms2+" walk");
self.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('walk', 0);
self.curstate = 1 ; //jump
}, delay*1000);
}
},
//跳结束动画
jumpEndAnimation:function(){
// var self = this;
// self.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('idle', 0);
// self.curstate = 0;
// setTimeout(()=>{
// self.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('walk', 0);
// self.curstate = 1 ; //walk
// }, 300);
this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('walk', 0);
this.curstate = 1 ; //walk
// this.checknextstep();
},
walk:function(dt){
//由于Math函数接受的是孤度,所以我们先节节点的旋转转化为弧度
// var angle = node.rotation / 180 * Math.PI;
// //合成基于 X正方向的方向向量
// var dir = cc.v2(Math.cos(angle),Math.sin(angle));
// //单位化向量
// dir.normalizeSelf();
// //根据方向向量移动位置
// var moveSpeed = -32;
// node.x += dt * dir.x * moveSpeed;
// node.y += dt * dir.y * moveSpeed; 直径 30CM 总高不到 70cm 自重17 KG
// switch(this.curidr){
// case MoveDir.DIR_X_ADD://
// case MoveDir.DIR_Y_ADD://
// case MoveDir.DIR_X_SUB://
// case MoveDir.DIR_Y_SUB://
// break;
// }
// let t1 = this.getparamsbydir();
if(dt > 1){
dt = 1;
}
let [dirx,diry] = this.getparamsbydir();
let newx = this.node.x + dt * dirx * this.curmovespeed;
let newy = this.node.y + dt * diry * this.curmovespeed;
this.node.x = Math.floor(newx) ;
this.node.y = Math.floor(newy) ;
},
checknextstep_1:function(){
if(this.curstate != 1) return ;
let [dirx,diry] = this.getparamsbydir();
let worldpos = this.node.parent.convertToWorldSpaceAR(new cc.Vec2(this.node.x, this.node.y)); //convertToWorldSpaceAR
let [gridx,gridy] = cc.map_js.getgridbypix(worldpos.x,worldpos.y);
let nextgridx = gridx+1*dirx ;
let newxgridy = gridy+1*diry ;
// let newx = worldpos.x + 2* dirx * this.curmovespeed;
// let newy = worldpos.y + 2 * diry * this.curmovespeed;
const basegridsize = cc.map_js.getbasegridsize();
// let bodywidthpix = this.modelgridwidth*basegridsize /2 ;
// let bodyheightpix = this.modelgridheight*basegridsize /2 ;
let bodywidthpix = Math.ceil(this.modelwidth/2) ; //floor 向下取整 ceil 向上取整
let bodyheightpix = Math.ceil(this.modelheight/2);
let usebodywidthpix = bodywidthpix;//Math.min(bodywidthpix,basegridsize) ;//bodywidthpix;//
let newx = worldpos.x + dirx * usebodywidthpix;
let newy = worldpos.y + diry * bodyheightpix ;
const mapwidth = cc.map_js.getmapwidth()
const mapheight = cc.map_js.getmapheight()
if(newx < 1 || newy < 1 || newx+1 >= mapwidth* basegridsize || newy+1 >= mapheight* basegridsize){ //到边缘了
this.idle(3,true);
return ;
}
// let gridx,gridy = cc.map_js.getgridbypix(worldpos.x,worldpos.y);
let [newgridx,newgridy] = cc.map_js.getgridbypix(newx,newy);
if(gridx != newgridx || gridy != newgridy){ //跨格子了
let [nextopr,disx,disy] = cc.map_js.findnextstep_x_jump_2_grid(newgridx,newgridy,dirx); //iscanwalk(newgridx,newgridy,dirx,diry)
if(nextopr == 0){
return this.idle(2,true);
}else if(nextopr == 2){
//需要jump
// let absdis = Math.abs(disy)*basegridsize ;
let [jumpx,jumpy] = cc.map_js.getpixbygrid(gridx+disx,gridy+disy) //node worldpos 576 128
// let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx+bodywidthpix, jumpy));
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:64);
// let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx+bodywidthpix, jumpy));
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx, jumpy));//+usebodywidthpix
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);//+dirx*basegridsize
this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
// if(dirx >= 0){
// this.jump(jumplocalpos.x-this.node.x+dirx*bodywidthpix+appendpix,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
// }else{
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize+appendpix,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
// }
}
}else{
//保持原有状态
}
},
checknextstep_20231018:function(){
//瞄点 x 0 往右移 半个 width 1 左移 半个 y 1向下移 半个高度 0 上移半个高度
if(this.curstate != 1) return ;
let [dirx,diry] = this.getparamsbydir();
let worldpos = this.node.parent.convertToWorldSpaceAR(new cc.Vec2(this.node.x, this.node.y)); //convertToWorldSpaceAR
let [gridx,gridy] = cc.map_js.getgridbypix(worldpos.x,worldpos.y);
let nextgridx = gridx+1*dirx ;
let newxgridy = gridy+1*diry ;
// let newx = worldpos.x + 2* dirx * this.curmovespeed;
// let newy = worldpos.y + 2 * diry * this.curmovespeed;
const basegridsize = cc.map_js.getbasegridsize();
// let bodywidthpix = this.modelgridwidth*basegridsize /2 ;
// let bodyheightpix = this.modelgridheight*basegridsize /2 ;
let bodywidthpix = Math.ceil(this.modelwidth/2) ; //floor 向下取整 ceil 向上取整
let bodyheightpix = Math.ceil(this.modelheight/2);
let usebodywidthpix = Math.min(bodywidthpix,basegridsize) ;//bodywidthpix;//
let newx = worldpos.x + dirx * usebodywidthpix;
let newy = worldpos.y + diry * bodyheightpix ;
const mapwidth = cc.map_js.getmapwidth()
const mapheight = cc.map_js.getmapheight()
if(newx < 1 || newy < 1 || newx+1 >= mapwidth* basegridsize || newy+1 >= mapheight* basegridsize){ //到边缘了
this.idle(3,true);
return ;
}
// let gridx,gridy = cc.map_js.getgridbypix(worldpos.x,worldpos.y);
let [newgridx,newgridy] = cc.map_js.getgridbypix(newx,newy);
if(gridx != newgridx || gridy != newgridy){ //跨格子了
let [nextopr,disx,disy] = cc.map_js.findnextstep_x_jump_2_grid(newgridx,newgridy,dirx); //iscanwalk(newgridx,newgridy,dirx,diry)
if(nextopr == 0){
return this.idle(2,true);
}else if(nextopr == 2){
//需要jump
// let absdis = Math.abs(disy)*basegridsize ;
let [jumpx,jumpy] = cc.map_js.getpixbygrid(gridx+disx,gridy+disy) //node worldpos 576 128
// let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx+bodywidthpix, jumpy));
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:64);
// let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx+bodywidthpix, jumpy));
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx, jumpy));//+usebodywidthpix
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
let jumpdir = disy >=0?1:(disy==0?0:-1);
switch(jumpdir){
case -1:{
let defaultpix = basegridsize;
if(dirx < 0) defaultpix /= 2 ;
this.jump(jumplocalpos.x-this.node.x+dirx*(bodywidthpix+defaultpix),jumplocalpos.y-this.node.y,bodyheightpix);
}
break;
case 0:{
this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
} break;
case 1:{
this.jump(jumplocalpos.x-this.node.x+dirx*bodywidthpix,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
}
break;
}
}
}else{
//保持原有状态
}
},
checknextstep_20231019:function(){
//瞄点 x 0 往右移 半个 width 1 左移 半个 y 1向下移 半个高度 0 上移半个高度
if(this.curstate != 1) return ;
let [dirx,diry] = this.getparamsbydir();
let worldpos = this.node.parent.convertToWorldSpaceAR(new cc.Vec2(this.node.x, this.node.y)); //convertToWorldSpaceAR
let [gridx,gridy] = cc.map_js.getgridbypix(worldpos.x,worldpos.y);
let nextgridx = gridx+1*dirx ;
let newxgridy = gridy+1*diry ;
const basegridsize = cc.map_js.getbasegridsize();
let bodywidthpix = Math.ceil(this.modelwidth/2) ; //floor 向下取整 ceil 向上取整
let bodyheightpix = Math.ceil(this.modelheight/2);
const mapwidth = cc.map_js.getmapwidth()
const mapheight = cc.map_js.getmapheight()
const halfmodelcount = bodywidthpix > basegridsize ? 2:1;
const usebodywidthpix = Math.min(bodywidthpix,basegridsize) ;//bodywidthpix;//
const edge_x = worldpos.x + dirx * usebodywidthpix;
// let edge_y = worldpos.y + diry * bodyheightpix ;
if(edge_x < 1 || edge_x+1 >= mapwidth* basegridsize ){ //到边缘了 //只需要检查X 方向 || edge_y < 1 || edge_y+1 >= mapheight* basegridsize
this.idle(3,true);
return ;
}
let newx = worldpos.x + dirx * usebodywidthpix; //当前最多跨1格
let newy = worldpos.y ;//+ diry * bodyheightpix ;
// let gridx,gridy = cc.map_js.getgridbypix(worldpos.x,worldpos.y);
let [newgridx,newgridy] = cc.map_js.getgridbypix(newx,newy); //世界坐标变为格子坐标
if(gridx != newgridx || gridy != newgridy){ //跨格子了
let [nextopr,disx,disy] = cc.map_js.findnextstep_x_jump_2_grid_bigmodel(newgridx,newgridy,dirx,halfmodelcount); //findnextstep_x_jump_2_grid
if(nextopr == 0){
return this.idle(2,true);
}else if(nextopr == 2){
//需要jump
let [jumpx,jumpy] = cc.map_js.getpixbygrid(gridx+disx,gridy+disy) //node worldpos 576 128
// let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx+bodywidthpix, jumpy));
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:64);
// let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx+bodywidthpix, jumpy));
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
let jumplocalpos = this.node.getParent().convertToNodeSpaceAR(new cc.v2(jumpx, jumpy));//+usebodywidthpix
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
// this.walkandjump(usebodywidthpix,jumplocalpos.x-this.node.x,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
if(disy < 0 && dirx > 0){
this.walkandjump(usebodywidthpix,jumplocalpos.x-this.node.x+dirx*usebodywidthpix,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
}else {
let appendpix = 0;
if(dirx > 0 && usebodywidthpix < basegridsize){
appendpix = Math.floor(usebodywidthpix/2) ;
}
this.jump(jumplocalpos.x-this.node.x+dirx*usebodywidthpix+appendpix,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
}
// let jumpdir = disy >=0?1:(disy==0?0:-1);
// switch(jumpdir){
// case -1:{
// let defaultpix = basegridsize;
// if(dirx < 0) defaultpix /= 2 ;
// this.jump(jumplocalpos.x-this.node.x+dirx*(bodywidthpix+defaultpix),jumplocalpos.y-this.node.y,bodyheightpix);
// }
// break;
// case 0:{
// this.jump(jumplocalpos.x-this.node.x+dirx*basegridsize,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
// } break;
// case 1:{
// this.jump(jumplocalpos.x-this.node.x+dirx*bodywidthpix,jumplocalpos.y-this.node.y,jumplocalpos.y>this.node.y?64:32);
// }
// break;
// }
}
}else{
//保持原有状态
}
},
born:function(x,y,dir,movespeed,jumpheigth){
this.curpos = cc.v2(x,y);
this.node.setPosition(x,y); //(i *128+128, -192);
// this.node.rotationY = 90; //rotationY
// this.node.scaleX = -this.node.scaleX; //左右翻转 scaleX Number 节点 X 轴缩放
if(!!dir){
this.curdir = dir ;
}
// this.curmovespeed = 64;
if(!!movespeed){
this.curmovespeed = movespeed;
}
if(!!jumpheigth){
this.basejumpheight = jumpheigth ;
}
this.modelwidth = this.node.width ;
this.modelheight = this.node.height ;
const basegridsize = cc.map_js.getbasegridsize();
this.modelgridwidth = Math.floor((this.modelwidth+ basegridsize -1)/basegridsize);
this.modelgridheight= Math.floor((this.modelheight+ basegridsize -1)/basegridsize);
// let t1= this.node.getComponent(dragonBones.ArmatureDisplay);
// t1.playAnimation('walk', 0);
// t1._animationName =
//this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('walk', 0);
// t1.node.getComponent(dragonBones.ArmatureDisplay).playAnimation('walk', 0);
this.curstate = 1; //walk
// this.checknextstep();
//将红色方块局部位置转成世界位置
// var worldPos = this.red.parent.convertToWorldSpaceAR(new cc.Vec2(this.red.x, this.red.y));
// console.log(worldPos); //(690,470)
// let t1 = this.node.getComponent(dragonBones.ArmatureDisplay);
// let t3 = t1.armature();
// let t2 = t1._armature.getSlot("hand_l");
// console.log("11");
//龙骨工厂实例
// let factory = dragonBones.CCFactory.getInstance();
// //通过插槽名称获取需要改变的骨骼插槽
// let needChangeSlot = needChangeArmature.armature().getSlot("changeSlotName");
// //替换插槽显示(需要改变的骨骼数据值,骨骼名称,插槽名称,显示名称,需要改变的插槽)
// factory.replaceSlotDisplay(toChangeArmature.getArmatureKey(), "armatureName", "slotName", "displayName", needChangeSlot);
},
findnextgrid:function(){
//先知管X 方向
const maxgriddis = 2 ; //最大2格 //后面可以传参数进来
if(x>= 0 && x< this.groupwidth && y>= 0 && y<this.groupheight){
if(y== 0){
if(this.ground[y][x] ==0){
return [1,0,0];
}
return [0,0,0];
}else if(this.ground[y][x] ==0 ){
if(this.ground[y-1][x] == 1){
return [1,0,0];
}else{
}
}else if(this.ground[y][x] ==0 ){}
// if(this.ground[y][x] ==0 ){
// if(y == 0 ) return 1 ;
// if(this.ground[y-1][x] == 1){
// return 1; //可以走
// }else {
// //需要跳下 或飞几格
// }
// }
}
return [0,0,0];
}
/*
https://blog.csdn.net/HYNN12/article/details/109220489
https://blog.csdn.net/weixin_40968046/article/details/118683290
*/
});
/*
onCastSpell(event){
var animName = event.target.__meta;
if(this._isSpelling){
return;
}
this._isSpelling = true;
var arr = [];
//切换成冲刺动画,并移动到目标跟前
arr.push(cc.spawn(cc.moveTo(0.3,this.target.node.position.sub(cc.v2(120,0))),cc.callFunc(function(){
this.hero.playAnim('rush');
},this)) );
//播放攻击动画
arr.push(cc.callFunc(function(){
this.hero.playAnim(animName);
},this));
var animInfo = AnimConfig.getRoleInfo(this.hero.roleId)[animName];
var playTime = animInfo.frames / animInfo.fps;
//等待攻击完成
arr.push(cc.delayTime(0.5 + playTime));
//移回原来位置
arr.push(cc.moveTo(0.1,this.hero.node.position));
arr.push(cc.callFunc(function(){
this._isSpelling = false;
},this));
var act = cc.sequence(arr);
this.hero.node.runAction(act);
}
*/
4:运行结果
资源网上找的,使用的是龙骨骼
5:DEMO工程
有需要再上传
如果觉得有用,麻烦点个赞,加个收藏