【发布时间】:2021-10-24 21:34:53
【问题描述】:
我拥有的图像是一个右上角的箭头,我希望它在与屏幕的角或边缘发生碰撞时改变方向,这样我的箭头图片就可以朝向它前进的方向。
int x;
int y;
int xspeed;
int yspeed;
PImage dvd;
void setup() {
size(800, 600);
x = 400;
y = 100;
dvd = loadImage("topright.png");
xspeed = 10;
yspeed = 10;
}
void draw() {
background(50);
image(dvd, x, y, 80, 60);
x = x + xspeed;
y = y + yspeed;
if (x + 80 == width || x == 0) {
xspeed = xspeed * -1;
}
if (y + 60 == height || y == 0) {
yspeed = -yspeed;
}
}
【问题讨论】:
-
你还有其他预画的图标吗?
-
我会考虑改用类似
if (x + 80 >= width || x == 0) {的东西
标签: java image processing collision