在 Java 中旋转图像/处理
Roating Image in Java / Processing
我已经开始制作一个基本的小行星游戏。
我试图在小行星在屏幕上移动时旋转它。
这是我的目标代码。
class Asteroid {
PImage lrgAsteroid;
float xpos, ypos;
float yDirection = 1;
float xDirection = 1;
float radians = 0;
Asteroid() {
lrgAsteroid = loadImage("largeAsteroid.png");
xpos = random(0,710);
ypos = random(0,710);
}
void display() {
image(lrgAsteroid, xpos, ypos);
}
void move() {
imageMode(CENTER);
translate(xpos, ypos);
rotate(radians);
image(lrgAsteroid, xpos, ypos);
radians += 1;
xpos += xDirection;
ypos += yDirection;
}
}
我认为问题出在翻译语句上,但我不知道如何解决它。
任何帮助都会很棒。谢谢!
翻译将小行星放到了它的位置。 image()
中的位置也不需要设置。
用 imageMode(CENTER)
. Rotate the image around its center (0. 0) by rotate
and move the image to its location in the window by translate()
:
在 (0, 0) 绘制图像
imageMode(CENTER);
translate(xpos, ypos);
rotate(radians);
image(lrgAsteroid, 0, 0);
注意像rotate
and translate()
这样的操作定义了一个变换矩阵并将当前变换矩阵乘以新矩阵。
我已经开始制作一个基本的小行星游戏。 我试图在小行星在屏幕上移动时旋转它。
这是我的目标代码。
class Asteroid {
PImage lrgAsteroid;
float xpos, ypos;
float yDirection = 1;
float xDirection = 1;
float radians = 0;
Asteroid() {
lrgAsteroid = loadImage("largeAsteroid.png");
xpos = random(0,710);
ypos = random(0,710);
}
void display() {
image(lrgAsteroid, xpos, ypos);
}
void move() {
imageMode(CENTER);
translate(xpos, ypos);
rotate(radians);
image(lrgAsteroid, xpos, ypos);
radians += 1;
xpos += xDirection;
ypos += yDirection;
}
}
我认为问题出在翻译语句上,但我不知道如何解决它。
任何帮助都会很棒。谢谢!
翻译将小行星放到了它的位置。 image()
中的位置也不需要设置。
用 imageMode(CENTER)
. Rotate the image around its center (0. 0) by rotate
and move the image to its location in the window by translate()
:
imageMode(CENTER);
translate(xpos, ypos);
rotate(radians);
image(lrgAsteroid, 0, 0);
注意像rotate
and translate()
这样的操作定义了一个变换矩阵并将当前变换矩阵乘以新矩阵。