/**
* 敌人
*/
export default class Enemy {
enemy = wx.createImage();
constructor(ctx){
this.enemy.src = 'images/enemy.png';
this.enemy.width = ctx.canvas.width / 6;
this.enemy.height = this.enemy.width / 3 * 2;
this.visible = true;
this.top = -this.enemy.height;
this.left = Math.random() * (ctx.canvas.width - this.enemy.width);
ctx.fillStyle = '#ffffff'
ctx.font = '20px Arial'
ctx.stroke = 5;
}
update(ctx, frameRate){
ctx.fillText((this.enemy.width = (ctx.canvas.width / 6)), 30, 420);
ctx.fillText(ctx.canvas.width, 30, 120);
ctx.fillText(ctx.canvas.height, 30, 180);
ctx.fillText(this.enemy.width, 30, 240);
ctx.fillText(this.enemy.height, 30, 300);
ctx.fillText(ctx.canvas.width / 7, 30, 360);
if (!this.visible){ return; }
if (this.top >= ctx.canvas.height) {
this.visible = false;
return;
}
/*
判断碰撞
if (){
}
*/
//向下移动
this.top = this.top + 120 / frameRate * 2
ctx.drawImage(this.enemy, this.left, this.top + 120 / frameRate, this.enemy.width, this.enemy.height);
}
}
在开发工具里显示正常,在手机上真机调试就显示原图大小
这两句不起作用
this.enemy.width = ctx.canvas.width / 6;
this.enemy.height = this.enemy.width / 3 * 2;
背景图片没问题,到敌机就不行了