身体没有变化,眼睛也没有眨

来源:1-4 身体变白

qq_我在呢_0

2016-06-22 16:53

var babyObj = function() {

this.x;

this.y;

this.angle;

this.babyEye = new Image();

this.babyBody = new Image();

this.babyTail = new Image();


this.babyTailTimer = 0;

this.babyTailCount = 0;


this.babyEyeTimer = 0;

this.babyEyeCount = 0;

this.babyInterval = 1000;


this.babyBodyTimer = 0;

this.babyBodyCount = 0;



}

babyObj.prototype.init =function(){

this.x = canWidth*0.5 -50;

this.y = canHeight*0.5 +50;

this.angle = 0;

// this.babyEye.src = "./src/babyEye0.png";

// this.babyBody.src = "./src/babyFade0.png";

// this.babyTail.src = "./src/babyTail0.png";

}

babyObj.prototype.draw = function(){

// mom

this.x = lerpDistance(mom.x,this.x,0.98);

this.y = lerpDistance(mom.y,this.y,0.98);


var deltaY = mom.y - this.y;

var deltaX = mom.x - this.x;

var beta = Math.atan2(deltaY,deltaX)+Math.PI;


this.angle = lerpAngle(beta,this.angle,0.5);


//尾巴摆动

this.babyTailTimer += deltaTime;

if (this.babyTailTimer>50) {

this.babyTailCount = (this.babyTailCount + 1)%8;

this.babyTailTimer %=50;

};


//眨眼睛

this.babyEyeTimer += deltaTime;

if (this.babyEyeTimer > this.babyEyeIntervel) {

this.babyEyeCount =(this.babyEyeCount + 1)%2;

this.babyEyeTimer %= this.babyEyeIntervel;


if (this.babyEyeCount == 0) {

this.babyEyeIntervel = Math.random()*1500 + 2000;

}else{

this.babyEyeIntervel =200;

}

};


//身体变白

this.babyBodyTimer += deltaTime;

if (this.BabyBodyTimer > 300) {

this.babyBodyCount = this.babyBodyCount +1;

this.babyBodyTimer %=300;

if(this.babyBodyCount >19){

this.babyBodyCount = 19;

}

};


ctx1.save();

ctx1.translate(this.x,this.y);

ctx1.rotate(this.angle);

var babyTailCount = this.babyTailCount;

ctx1.drawImage(babyTail[babyTailCount],-babyTail[babyTailCount].width*0.5+23,-babyTail[babyTailCount].height*0.5);

var babyBodyCount = this.babyBodyCount;

ctx1.drawImage(babyBody[babyBodyCount],-babyBody[babyBodyCount].width*0.5,-babyBody[babyBodyCount].height*0.5);


var babyEyeCount = this.babyEyeCount;

ctx1.drawImage(babyEye[babyEyeCount],-babyEye[babyEyeCount].width*0.5,-babyEye[babyEyeCount].height*0.5);


ctx1.restore();

}


写回答 关注

1回答

  • 尐调_
    2016-06-25 17:41:02
    已采纳

    第一步,在main.js中加载资源,以眼睛为例子

    var babyEye=[];

    init(){

    for(var i=0;i<2;i++){
       babyEye[i]= new Image();
       babyEye[i].src = "images/babyEye"+i+".png";
    }

    }


    第二步,删除baby.js中的眼睛定义

    this.babyEye = new Image();

    this.babyEye.src = "./src/babyEye0.png";


    看你的代码,应该是因为没有去除babyObj()中的资源定义:

    this.babyEye = new Image();

    this.babyBody = new Image();

    this.babyTail = new Image();


    qq_我在呢...

    后来看了一下,if (this.BabyBodyTimer > 300) 大小写写错了。。。。

    2016-06-28 10:53:49

    共 2 条回复 >

HTML5小游戏---爱心鱼(下)

通过一个清新美好的小游戏教程,熟悉游戏开发流程

46272 学习 · 189 问题

查看课程

相似问题