按下键时图像不会改变
Image won't change when key is pressed
我正在制作我自己的马里奥小副本,这是我今天开始做的,我被困在一个小动画上。
当按下UP
时,马里奥跳跃,但精灵不会改变。
我试过 if-else 来设置它,但它不起作用:
PImage brick1;
PImage bg;
PImage Flag;
float playerX;
float playerY;
float brickX;
float Lives;
float Level;
float Time;
void setup(){
size(1000,800);
smooth();
if (keyPressed){
if (keyCode == UP){
bg = loadImage("Mario3.png");
}
}else{
bg = loadImage("Mario1.png");
}
我希望在按住 UP 时图像会发生变化,但它显示 "Mario1.png" 精灵。
您必须实现一个 draw
函数。
加载setup
中的图像:
PImage bg1, bg3;
void setup() {
size(1000, 800);
smooth();
bg1 = loadImage("Mario1.png");
bg3 = loadImage("Mario3.png");
}
并根据 keyPressed
and keyCode
的状态绘制适当的图像。
使用 image()
绘制图像到显示器:
例如
void draw() {
background(0);
if (keyPressed && keyCode == UP) {
image(bg3, 0, 0);
} else {
image(bg1, 0, 0);
}
}
我正在制作我自己的马里奥小副本,这是我今天开始做的,我被困在一个小动画上。
当按下UP
时,马里奥跳跃,但精灵不会改变。
我试过 if-else 来设置它,但它不起作用:
PImage brick1;
PImage bg;
PImage Flag;
float playerX;
float playerY;
float brickX;
float Lives;
float Level;
float Time;
void setup(){
size(1000,800);
smooth();
if (keyPressed){
if (keyCode == UP){
bg = loadImage("Mario3.png");
}
}else{
bg = loadImage("Mario1.png");
}
我希望在按住 UP 时图像会发生变化,但它显示 "Mario1.png" 精灵。
您必须实现一个 draw
函数。
加载setup
中的图像:
PImage bg1, bg3;
void setup() {
size(1000, 800);
smooth();
bg1 = loadImage("Mario1.png");
bg3 = loadImage("Mario3.png");
}
并根据 keyPressed
and keyCode
的状态绘制适当的图像。
使用 image()
绘制图像到显示器:
例如
void draw() {
background(0);
if (keyPressed && keyCode == UP) {
image(bg3, 0, 0);
} else {
image(bg1, 0, 0);
}
}