我有一些处理代码,我需要在按下某个键时创建一个新的矩形框,我需要在屏幕上有多个这些。我有所有的代码设置,以便当我按下某个键时可能会发生某些事情,但我已经尝试无限制地创建新对象而我无法使其工作。
代码:
public float translateX = 0;
public float translateY = 260;
public float translateZ = 10000;
float bulletX, bulletY, bulletZ;
public int rotationBlue = 1;
public int rotationGreen = 1;
public int rotationRed = 1;
public boolean shootBool = false;
public boolean shootBoolVal = true;
void setup() {
size(1280, 720, P3D);
frameRate(60);
}
void draw() {
background(0);
translate(640, 360, -10000);
fill(0);
box(100000);
ship();
control();
}
void control() {
if (keyPressed) {
if (key == 'a' || key == 'A') {
translateX = translateX - 5;
}
if (key == 'd' || key == 'D') {
translateX = translateX + 5;
}
if ((key == 's' || key == 'S')) {
translateZ = translateZ + 5;
}
if ((key == 'w' || key == 'W')) {
translateZ = translateZ - 5;
}
if ((key == 'q' || key == 'Q')) {
translateY = translateY - 5;
}
if ((key == 'e' || key == 'E')) {
translateY = translateY + 5;
}
if (key == 'f' || key == 'F') {
}
}
}
public void ship() {
fill(0, 0, 255);
stroke(255);
strokeWeight(3);
translate(translateX, translateY, translateZ);
//translate(mouseX, mouseY, 0);
rotateX(radians(rotationBlue));
rotateY(radians(rotationBlue));
rotateZ(radians(rotationBlue));
rotationBlue++;
box(100);
fill(0, 255, 0);
rotateX(radians(rotationGreen));
rotateY(radians(rotationGreen));
rotateZ(radians(rotationGreen));
rotationGreen--;
box(100);
fill(255, 0, 0);
rotateX(radians(rotationRed));
rotateY(radians(rotationRed));
rotateZ(radians(rotationRed));
rotationRed = rotationRed + 2;
box(100);
//translateZ = translateZ - 5;
}
这是我到目前为止的所有代码。我需要能够拥有它,以便当我按下" F"键(已在功能控件中定义),在船的坐标处创建一个新的框,使其自身的Z方向不断减小。请记住,我必须能够同时拥有多个这样的盒子。
我希望有人告诉我必须采取哪些步骤才能做到这一点。
答案 0 :(得分:1)
这些是获得所需内容所需的步骤:
Bullet
对象,也可能是绘制函数Bullet
个对象的集合draw()
方法update()
方法,该方法更新每个项目符号的速度,位置等,也由draw()
函数调用