クリックしたときに効果音を出すためにstormTrooperイメージを取得しようとしています - これまでの運がない... p5.jsのウェブサイトをチェックしましたが、それを理解する。オブジェクトへのサウンドエフェクトp5.js
嵐のオブジェクトの中にmousePressed関数を含める必要があるのだろうか?
var img;
var trooper;
var sound;
function preload() {
img = loadImage("stormy3.png");
sound = loadSound("sounds/Followme.mp3");
}
function setup() {
// background(255, 0, 0, 0.4);
background(255, 0, 0, 0.4);
var myCanvas = createCanvas(windowWidth,windowHeight);
myCanvas.parent('myContainer');
myCanvas.position(0, 0);
trooper = new storm(300,400);
}
function draw() {
clear();
trooper.show();
trooper.movement();
trooper.bounce();
}
function storm(x,y) {
this.x = x;
this.y = y;
this.xSpeed = 3;
this.ySpeed = 3;
this.img = img;
this.show = function() {
image(img,this.x,this.y);
};
this.movement = function() {
this.x = this.x + this.xSpeed;
this.y = this.y + this.ySpeed;
};
this.bounce = function() {
if(this.x > width || this.x < 0) {
this.xSpeed = this.xSpeed * -1;
}
if(this.y > height || this.y < 0) {
this.ySpeed = this.ySpeed * -1;
}
};
}
function mousePressed() {
if (trooper.contains(trooper.x, trooper.y)) {
sound.play();
}
}
あなたのアドバイスをいただき、ありがとうございました。 –