【问题标题】:How do I click on an image change to other image and click to a video如何单击图像更改为其他图像并单击视频
【发布时间】:2016-11-13 11:20:38
【问题描述】:

我在处理 keyPressed/mousePressed 时遇到问题。

例如,如果我有一些图像苹果、狗和猫的数据文件,其中包含两个视频森林和花园。

问题是我想按一个按钮并更改为图像,然后再次按下以更改为视频。

例如以

开头

video = "forest.mp4" > keyPressed = UP > apple.jpg ;

有左或右两种选择>

  • 如果 keyPressed = LEFT > dog.jpg

  • 如果 keyPressed = RIGHT > 猫。 jpg

他们都 keyPressed = UP > video = "garden"

Movie myMovie[];
int index = 0;
boolean start = false;
float t0; //Movie Begin
float t; //current time

void setup(){
 size(1280,720);

img = new Image[2];
img = new Image(this, "apple.jpg");
img = new Image(this, "dog.jpg");
img = new Image(this, "cat.jpg");

myMovie = new Movie[3];
myMovie[0] = new Movie(this, "forest.mp4");
myMovie[1] = new Movie(this, "garden.mp4");
}
void draw(){
image (img, 0 ,0);
image(img, 0 ,height, img.height, img, height);

if (myMovie[index].read();
}

if (start){
 image(myMovie[index],0,0,width,height);

这有点像旧版的 RPG 游戏,冒险类型的游戏。

虽然玩家点击不同的选择会出现不同的结果。

【问题讨论】:

  • 很难阅读。请发布代码和努力。我尝试对其进行一些格式化,但阅读了minimal reproducible example
  • PImage img; Movie myMovie[ ]; int index = 0; boolean start = false; void setup(){ size (1280, 720) im img[3] myMovie = new Movie[2]; myMovie[1] = new Movie(this, "forest.mp4"); myMovie[2] = new Movie(this, "garden.mp4"); }
  • 您的评论没有用。请使用正确的代码和您尝试过的内容更新问题
  • 此外,您的问题的标题至少可以说是混乱的。

标签: javascript video processing


【解决方案1】:

第 1 步:将您的状态存储在一个变量中。

boolean showingMovie = true;

第 2 步:draw() 函数中,检查该变量并绘制正确的东西。

void draw(){
   if(showingMovie){
      //draw your movie
   }
   else{
      //draw your image
   }
}

第 3 步:更改 keyPressed()mousePressed() 函数中的变量以切换显示的内容。

void keyPressed(){
   showingMovie = !showingMovie;
}

您可能需要一些逻辑来仅在变量指示电影正在播放时读取电影,并且您可能需要添加一些逻辑以仅在鼠标单击正确位置时切换变量,或者正确的键被按下。如果您有多个电影/图像组合,您可能还必须有多个变量。如果你有很多这些,你甚至可以使用一个数组或一个类来保存你的所有数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多