|
var walk = qc.defineBehaviour('qc.engine.walk', qc.Behaviour, function() {
// need this behaviour be scheduled in editor
//this.runInEditor = true;
this.zy = 0,
this.zx = 0,
this.speed = 0,
this.f = '上',
this.time = 0,
this.time2 = 0
}, {
开始xy: qc.Serializer.POINT,
结束xy: qc.Serializer.POINT,
速度: qc.Serializer.NUMBER,
时间1: qc.Serializer.NUMBER,
方向: qc.Serializer.NUMBER,
时间2: qc.Serializer.NUMBER
// fields need to be serialized
});
walk.prototype.update = function(){
this.anchoredX = this.x
this.anchoredY = this.y
switch(this.f){
case '上':
this.s()
break;
case '下':
this.x()
break;
case '左':
this.z()
break;
case '右':
this.y()
break;
case '左右':
this.zy()
break;
case '上下':
this.sx()
break;
default:
return;
}
},
walk.prototype.s = function(){
while(this.anchoredY > this.zy){
this.anchoredY -= this.speed
}
setTimeout(() => {
this.anchoredY = this.y
this.s()
}, this.time);
},
walk.prototype.x = function(){
while(this.anchoredY < this.zy){
this.anchoredY += this.speed
}
setTimeout(() => {
this.anchoredY = this.y
this.x()
}, this.time);
},
walk.prototype.z = function(){
while(this.anchoredX > this.zx){
this.anchoredX -= this.speed
}
setTimeout(() => {
this.anchoredX = this.x
this.z()
}, this.time);
},
walk.prototype.y = function(){
while(this.anchoredX < this.zx){
this.anchoredX += this.speed
}
setTimeout(() => {
this.anchoredX = this.x
this.y()
}, this.time);
},
walk.prototype.sx = function(){
while(this.anchoredY > this.zy){
this.anchoredY -= this.speed
}
setTimeout(() => {
while(this.anchoredY < this.zy){
this.anchoredY += this.speed
}
setTimeout(() => {
this.sx()
}, this.time);
}, this.time2);
},
walk.prototype.zy = function(){
while(this.anchoredX > this.zx){
this.anchoredX -= this.speed
}
setTimeout(() => {
while(this.anchoredX < this.zx){
this.anchoredX += this.speed
}
setTimeout(() => {
this.zy()
}, this.time);
}, this.time2);
};
//Called when the script instance is being loaded.
//walk.prototype.awake = function() {
//
//};
// Called every frame, if the behaviour is enabled.
//walk.prototype.update = function() {
//
//};
|
|