我在处理时遇到问题。我已经创建了类“石头”,然后我已经创建了3个对象石头石头1,石头2,石头3在主要的权杖。我需要的是让石头透明,当用户移动它。问题是,当石头被移动时,所有3块石头都变得透明,而不是被移动的那块石头。你能给我一个提示吗,我怎样才能只对移动的石头应用透明度?
我班的石头
class Stone {
Playfield p;
PImage stone;
boolean overStone = false;
boolean locked = false;
boolean stoneMoved;
int positionX;
int positionY;
int stoneXOld;
int stoneYOld;
int stoneSize;
boolean transparencyOn;
Stone(int stoneXtemp, int stoneYtemp, int stoneSizeTemp, Playfield pf) {
stone = loadImage("stone.png");
positionX = stoneXtemp;
positionY = stoneYtemp;
stoneXOld = positionX;
stoneYOld = positionY;
imageMode(CENTER);
stoneSize = stoneSizeTemp;
p = pf;
}
void display() {
if (transparencyOn == true) {
tint(255, 126);
} else {
noTint();
}
image(stone, stoneX, stoneY, stoneSize, stoneSize);
}
void update() {
if (mouseX > positionX - stoneSize / 2 && mouseX < positionX + stoneSize / 2 &&
mouseY > positionY - stoneSize / 2 && mouseY < positionY + stoneSize / 2) {
overStone = true;
if (!locked) {
tint(160);
}
} else {
noTint();
overStone = false;
}
}
void interact() {
if (overStone && mousePressed) {
locked = true;
tint(230);
positionX = mouseX;
positionY = mouseY;
} else {
locked = false;
noTint();
}
}
boolean stoneMoved() {
return stoneMoved = (!overStone && !locked && positionX > stoneXOld + 100 && positionY > stoneYOld + 100);
}
void afterMove() {
if (stoneMoved()) {
p.stoneAfterMove(stoneSize * 2);
}
transparencyOn = true;
}
}
以及操场:
import processing.video.*;
aaMovie water;
Stone stone1,stone2,stone3;
PImage img;
void setup()
{
size(800,800);
water=new Movie(this,"Water.mp4");
water.loop();
stone1=new Stein(70,70,100,this);
stone2=new Stein(180,70,80,this);
stone3=new Stein(270,70,60,this);
}
void draw(){
background(water);
stone1.display();
stone2.display();
stone3.display();
stone1.update();
stone2.update();
stone3.update();
stone1.interact();
stone2.interact();
stone3.interact();
}
void movieEvent(Movie m){
m.read();
}
void mouseReleased(){
stone1.afterMove();
stone2.afterMove();
stone3.afterMove();
}
1条答案
按热度按时间t9eec4r01#
找到了解决办法。我需要全局变量
boolean moved
控制两个类中移动的石头,然后设置transparencyOn
在代码的正确位置