Java处理中的漫游图像

问题描述 投票:1回答:1

我已经开始制作一个基本的小行星游戏。我试图旋转我的小行星,而它在屏幕上移动。

这是我的对象代码。

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;

  }

}

我相信问题出在翻译语句上,但我不知道如何解决。

任何帮助将是巨大的。谢谢!我已经开始制作一个基本的小行星。

java rotation processing
1个回答
0
投票

翻译是将小行星放到它的位置。不需要在 image(),也是。在(0, 0)处画出图像,用 imageMode(CENTER). 绕着中心点(0. 0)旋转图像,方法是: 1. rotate 并将图像移动到其在窗口中的位置,方法是 translate():

imageMode(CENTER);
translate(xpos, ypos);
rotate(radians);
image(lrgAsteroid, 0, 0);

注意到以下操作: rotatetranslate() 定义一个变换矩阵,并将当前变换矩阵乘以新矩阵。

© www.soinside.com 2019 - 2024. All rights reserved.