0
画像を画面全体に移動したい。現時点では、イメージはレンダリングされますが、特定のキーが押されたときにページを翻訳しません。それを働かせるために見ることができない - 任意の提案??私はそれがより理にかなっていると信じて、私はコードのブロック全体を含めた。キーを押したときに画像が変換されない
var player;
var img;
function preload() {
img = loadImage("charcter.png");
}
function setup() {
background(255, 0, 0, 0.4);
createCanvas(1000, 600);
player = new Astro(0,0);
}
function draw() {
// clear();
player.show();
player.update();
}
function keyPressed() {
if (keyCode === UP_ARROW) {
player.dir(0, -10);
} else if (keyCode === DOWN_ARROW) {
player.dir(0, 10);
} else if (keyCode === RIGHT_ARROW) {
player.dir(10, 0);
} else if (keyCode === LEFT_ARROW) {
player.dir(-10, 0);
}
}
function Astro(x, y) {
this.x = x;
this.y = y;
this.xSpeed = 0;
this.ySpeed = 0;
this.img = img;
this.show = function() {
image(img, this.x, this.y);
};
this.update = function() {
this.x += this.xSpeed;
this.y += this.ySpeed;
if (this.x > width || this.x < 0) {
this.xSpeed = this.xSpeed * -1;
}
if (this.y > height || this.y < 0) {
this.ySpeed = this.ySpeed * -1;
}
};
this.dir = function(x, y) {
this.xspeed = x;
this.yspeed = y;
}
}
[<] 'を押して、[mcve] – mplungjan
を作成してください。この.x.x.xに追加してください.xではいくつかの関数でthis.ySpeed this.ySpeedを追加してください。それはイメージが動く方法です。また、this.dir()関数では、画像を移動したい位置をthis.xとthis.yにそれぞれ追加する必要があります –
申し訳ありませんが、 –