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에 this.xspeed를 추가하면 안됩니다. 일부 함수에서는 this.ySpeed가 this.ySpeed에 추가됩니까? 그것이 이미지가 움직이는 방법입니다. 또한 this.dir() 함수에서 이미지를 이동하려는 위치를 this.x와 this.y에 각각 추가해야합니다. –
죄송합니다. 아직 추가하지 않았습니다. 아직 이동하지 않았습니다. –