클릭하면 사운드 효과를 내기 위해 stormTrooper 이미지를 얻으려고합니다 - 지금까지 행운이 없습니다 ... p5.js 웹 사이트를 확인했지만 할 수 없습니다. 그것을 알아 내라.오브젝트에 대한 사운드 효과 p5.js
폭풍 개체 안에 mousePressed 함수를 포함해야하는지 궁금하십니까?
당신은Storm
객체의 내부로 스케치 - 레벨
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();
}
}
귀하의 조언을 많이 주셔서 감사합니다, 대단히 감사합니다! –