Time Object กับ Phaser 3

#HelloGameDev #HelloErmine #HelloWorld2021

Time คือ รูปแบบเวลาที่ผ่านไปใน scene มีการนับเป็น millisecond Delta ซึ่งก็คือค่าสำหรับคำนวณการเคลื่อนที่ให้สมูทหรือไหลลื่นมากขึ้น

create(){
    timer = this.add.text(16,16,"Time : 0");
}

update(){
    timer.setText("time: "+ time);
}
Result

ตัวอย่างการใช้ Delta

speed = Phaser.Math.GetSpeed(300,1)
bullet = this.physics.add.image(100,100,'bullet')
bullet.x += speed * delta

คำสั่งหาค่าความเร็วที่ต้องการ

Phaser.Math.GetSpeed(300, 1)  //Parameter ตัวเเรกคือ ระยะทางที่ต้องการ (Pixel)
                              //Parameter ตัวเที่สองคือ ระยะเวลาที่ต้องการ (Second)

และน้อง ๆ สามารถดูคำสั่ง Math เพิ่มเติมได้ที่ลิงก์ด้านล่างนี้เลย!

Last updated

Was this helpful?