点击图像进行声音播放处理 [英] Click Image to Make Sound Play - Processing
本文介绍了点击图像进行声音播放处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将鼠标按下事件添加到一张图片中,我认为这是可能的,因为我在论坛上看到了关于它的许多问题。然而,我有一个播放按钮的图像。我想将此图像用作播放/暂停音乐的按钮。到目前为止,我还没有在鼠标按键上找到任何可以播放音乐的图像。有谁知道我在哪里可以读到关于这个特定主题的更多信息?仍然在查阅文档,还没有找到任何东西。以下是我的代码的一些摘录:
PImage play;
play = loadImage("play.png"); // in setup
imageMode(CORNER); // in draw
image(pause, 80, 15, 50, 50); // in draw
推荐答案
如果您希望在单击某处时发生某些事情,则必须将该单击的坐标与对象的坐标进行比较。
这里有一个您可以根据需要进行调整的示例:
void mouseClicked() {
if (mouseX >= playButton.x && mouseX <= playButton.x + playButton.width && mouseY >= playButton.y && mouseY <= playButton.height) {
// user clicked on the play button
}
// another image in case you want to check for more than one button:
if (mouseX >= pauseButton.x && mouseX <= pauseButton.x + pauseButton.width && mouseY >= pauseButton.y && mouseY <= pauseButton.height) {
// user clicked on the pause button
}
}
playButton.something
和pauseButton.something
是您要捕捉的任何对象的坐标,点击时不一定是完全打开的对象。
玩得开心!
这篇关于点击图像进行声音播放处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文