【问题标题】:Make text appear and disappear in processing使文本在处理中出现和消失
【发布时间】:2013-05-06 08:45:31
【问题描述】:

所以,我想知道是否有办法让文本出现然后消失,因为它被不同的文本替换。我目前找到了一个代码,可以让我一个一个慢慢地出现文本,但我不知道当新文本出现时可以让我摆脱以前的文本的代码。请帮帮我!

// creates the window with white background
import ddf.minim.*;

Minim minim;
AudioSnippet snip;
color c1 = color(0,0,0), c2 = color(0,0,0), current;

void setup(){
  size(1200, 800);
  current = c1;
  smooth();
  minim = new Minim(this);
  snip = minim.loadSnippet("LoudGun.mp3");
}

void mousePressed() {
  snip.play();
if(current==c1) { current = c2; } else { current = c1; }
}

// draw "Charlotte"  
void CharlotteBacon() {
  frameRate(5);
  fill(255);
  textSize(50);
  text("Charlotte Bacon, Age 6", 600, 275);
}

// draw "Daniel" 
void DanielBarden() {
  frameRate(5);
  fill(255);
  textSize(50);
  text("Daniel Barden, Age 7", 20, 50);
}

int col = 0;
// main method where all above methods are executed on the white window
void draw() {
   background(current);
  if(mouseX != pmouseX && mouseY != pmouseY){

  }
  if (mousePressed) { 

  }
  // each phrase is printed at intervals of 2 seconds
  if (mouseX == pmouseX && mouseY == pmouseY && mousePressed != true) {
    ;
    int currentTime = millis();
    int timeLapse = 2000;
    if (currentTime > timeLapse) {
      CharlotteBacon();
    }
    if (currentTime > timeLapse*2) {
      DanielBarden();
    }
  }
}

【问题讨论】:

    标签: text processing


    【解决方案1】:

    这样做的一种方法是使用一个字符串来保存要显示的文本,并将您要显示的文本分配给它,这样它就会替换它。 我根据您的代码的时间制作了示例。

    String oneName = "Carol";
    String otherName = "Chartllote";
    String displayed ="";
    
    int interval = 2000; // 2s
    int time;
    
    PFont font;
    
    void setup() {
      size(300, 300);
      font = createFont("arial", 26);
      background(0);
      displayed = oneName;
      time = millis();
      textFont(font);
      fill(255);
    }
    
    void draw() {
      background(0);
      text(displayed, width/2 - textWidth(displayed)/2, height/2);
      if (millis() - time > interval) {
        displayed = displayed.equals(oneName)? otherName:oneName;
        time  = millis();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 2018-04-16
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多