我目前得到了一个海报我试图使一个研究这个代码(要去把它所有,因为它可能是相关的):处理,替换文本
package interactiveposter;
import processing.core.PApplet;
import processing.core.PImage;
public class InteractivePoster extends PApplet {
// Declare variables:
PImage[] imgs = new PImage[12];
int i = 0;
boolean introduction = true;
boolean storyboardtext = true;
boolean features = true;
int picWidth = 300;
int picHeight = 200;
PImage storyboard;
PImage phone;
// Set size of window and load images:
public void setup() {
size(750,900);
smooth();
storyboard = loadImage("C:/Users/Frederik/Desktop/Medialogy AAU/Images/storyboardfixed.png");
storyboard.resize(270, 757);
phone = loadImage("C:/Users/Frederik/Desktop/Medialogy AAU/Images/phone.PNG");
phone.resize(300, 500);
}
// All that should run continuously goes in draw:
public void draw() {
background(255,255,255);
textAlign(CENTER);
textSize(24);
fill(0);
text("Creative Play - Applied Technology",width/2,50);
textSize(16);
fill(120);
text("B-341",width/2,900);
image(storyboard, 50, 100);
image(phone, 385, 140);
int tboxPos = 50;
tboxPos=tboxPos+335;
if(introduction == false) {
features = true;
text("Text 1...Introduction", 490, 230);
}
if(storyboardtext == false) {
text("Text 2...Storyboard", 480, 230);
}
if(features == false) {
text("Text 3...Features", 480, 230);
introduction = true;
}
fill(0,0,0);
rect(tboxPos,700, 300, 100, 7); //FrameRect
fill(102,204,255);
rect(tboxPos, 700, 300, 50, 7); //IntroductionRect
fill(255,255,255);
textSize(20);
text("Introduction", tboxPos+150, 730);
fill(102,204,255);
rect(tboxPos, 750, 150, 50, 7); // StoryboardRect
fill(255,255,255);
textSize(20);
text("Storyboard", tboxPos+75, 780);
fill(102,204,255);
rect(tboxPos+150, 750, 150, 50, 7); //FeaturesRect
fill(255,255,255);
textSize(20);
text("Features", tboxPos+225, 780);
}
// Check if mouse is clicked on one of the images, then change that variable from true to false or opposite
public void mouseClicked() {
if(mouseX > 385 && mouseX < 685 && mouseY > 700 && mouseY < 750)
{
if(introduction == true) introduction = false;
else introduction = true;
}
if(mouseX > 385 && mouseX < 535 && mouseY > 750 && mouseY < 800)
{
if(storyboardtext == true) storyboardtext = false;
else storyboardtext = true;
}
if(mouseX > 535 && mouseX < 685 && mouseY > 750 && mouseY < 800)
{
if(features == true) features = false;
else features = true;
}
}
}
因此,当您按下智能手机下方的按钮时,应显示相关文本。现在它单独工作,我点击介绍,但看到其他人之一,我必须再次点击介绍,使其消失。 我需要做的是使文本替换另一个按钮时单击。
我试图在if语句中将其他文本设置为true,但只对其中的一些有效,其他文本则被阻止。
另一个想法是在void mouseClicked()中做一些事情,但我不确定是什么。
帮助非常感谢,谢谢=)
所以对于故事板的点击处理程序,您应该简单地做'storyboard = true; introduction = false;特点=假;'你不需要if语句等 – aioobe
我认为你的意思是我所说的是我所尝试的,你可以尝试显示你是如何做的,我可能错过了代码 – KrownScripter
我更新了我的评论。只要做'prop1 = true; prop2 = false; prop3 = false;'为'prop1',对于其他属性也是类似的。 – aioobe