我目前得到了一個海報我試圖使一個研究這個代碼(要去把它所有,因爲它可能是相關的):處理,替換文本
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