我是新手的处理,我正在制作一个游戏来回移动的游戏,当它与墙壁碰撞时(xvalue = 10(,它将失去生命。我的顶角有3个心,当精灵与墙壁碰撞时,我希望它去除一颗心,这样它只会显示您剩下的生命。我如何删除图像(心脏(?
这是一些代码:
void loadStuff() {
image(panda, pandaX, pandaY, 80, 112);
image(heart1, 1250, 20, 100, 100);
image(heart2, 1350, 20, 100, 100);
image(heart3, 1450, 20, 100, 100);
if (pandaX<=10) {
//heart1=null;
//for (int l=0; l<=life; l++) {
// xCoord = xCoord - 100;
// yCoord = yCoord - 100;
// image(heart1, 0,0,0,0);
//}
}
}
void keyPressed() {
if (key==CODED) {
if (keyCode==LEFT) {
pandaX = pandaX-20;
}
if (keyCode==RIGHT) {
pandaX = pandaX+20;
}
if (pandaX<=10) {
pandaX=10;
//lives.remove(0);
//image(heart1,1500, 500); //makes another heart
//heart1.clear();
//heart1 = null;
}
if (pandaX>=1500) {
pandaX=1500;
}
}
}
我尝试了几件事使心脏图像消失 - 这无效。我尝试制作一个将所有坐标设置为0的循环,我尝试从程序顶部制作的阵列中删除第一个图像,然后我尝试清除它 - 所有这些都不起作用。p>当精灵碰撞到墙壁时,我将如何去除心脏(x = 10(,将不胜感激。谢谢!
有很多方法可以做到这一点。需要查看更多代码。
,但总的来说,您想在 Processing 中绘制的所有内容都无限期地运行的方法 draw((方法。在方法开始时,清除画布是一种很好的做法,然后您只需绘制所有内容即可。您可以选择不动心。
这是一个非常简单的示例。此应用程序在屏幕上绘制图像。按下任何键后,不再绘制图像。
PImage img;
boolean canDraw = true;
void setup() { // setup() runs once
size(800, 600);
frameRate(30);
loadStuff();
}
void loadStuff() {
img = loadImage("myImage.png");
}
void draw() {
background(204); // clears the screen
if(canDraw) {
image(img, 0, 0);
}
}
void keyPressed() {
canDraw = false;
}