japanese-drum-game/public/src/js/titlescreen.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-09-18 06:37:59 +08:00
class Titlescreen{
constructor(){
loader.changePage("titlescreen")
this.titleScreen = document.getElementById("title-screen")
2018-09-27 02:30:57 +08:00
pageEvents.keyOnce(this, 13, "down").then(this.onPressed.bind(this))
2018-10-06 01:03:59 +08:00
pageEvents.once(this.titleScreen, "mousedown").then(this.onPressed.bind(this))
pageEvents.once(this.titleScreen, "touchstart").then(this.onPressed.bind(this))
2018-09-18 06:37:59 +08:00
assets.sounds["title"].play()
2018-09-27 02:30:57 +08:00
this.gamepad = new Gamepad({
2018-10-09 04:32:25 +08:00
"start": ["a", "b", "x", "y", "start", "ls", "rs"]
}, pressed => {
2018-09-27 02:30:57 +08:00
if(pressed){
this.onPressed()
}
})
2015-07-17 16:22:46 +08:00
}
onPressed(event){
if(event && event.type === "touchstart"){
event.preventDefault()
this.touched = true
}
2018-10-06 01:03:59 +08:00
this.titleScreen.style.cursor = "auto"
2018-09-18 06:37:59 +08:00
this.clean()
assets.sounds["don"].play()
2018-09-27 02:30:57 +08:00
setTimeout(this.goNext.bind(this), 500)
}
goNext(){
if(this.touched || localStorage.getItem("tutorial") === "true"){
new SongSelect(false, false, this.touched)
}else{
new Tutorial()
2018-09-18 06:37:59 +08:00
}
}
clean(){
2018-09-27 02:30:57 +08:00
this.gamepad.clean()
2018-09-18 06:37:59 +08:00
assets.sounds["title"].stop()
pageEvents.keyRemove(this, 13)
2018-10-06 01:03:59 +08:00
pageEvents.remove(this.titleScreen, "mousedown")
pageEvents.remove(this.titleScreen, "touchstart")
2018-09-18 06:37:59 +08:00
delete this.titleScreen
}
}