如何解决如何在p5.js中调用作为按钮参数传递给Button类的函数?
这是我的Button类:
class Button {
constructor(x,y,width,height,color,msg,action) {
this.x = x
this.y = y
this.width = width
this.height = height
this.color = color
this.msg = msg
this.action = action
fill(this.color)
rect(this.x,this.y,this.width,this.height)
textSize(30)
fill(255)
noStroke()
text(this.msg,this.x + this.width / 2 - 30,this.y + this.height / 2 + 10)
if (mouseX >= this.x && mouseX <= this.x + this.width && mouseY >= this.y && mouseY <= this.y + this.height) {
stroke(255)
if (mouseIsPressed)
//this.action.call() ?
}
}
}
这是我创建的新按钮:
let startBtn = new Button(width/2 - width/4,height/6 + 100,300,100,'#404040','Start',changeScene(1))
我的问题是如何在我的changeScene(1)
代码中单击按钮时调用class Button {...}
?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。