nvminhtu / LearnPhaser

Tutorial, Experience, Coding with Phraser
1 stars 2 forks source link

Khai báo physic arcade trong boiler es2015 #27

Open lamanhdai opened 7 years ago

lamanhdai commented 7 years ago

@nvminhtu : Đại dùng bolier template week1 và dùng code trong file play.js sprites = this.game.add.physicsGroup(Phaser.Physics.ARCADE); để hỗ trợ arcade nhưng bị lỗi. Làm cách nào để thêm hỗ trợ ARCADE trong template ?

code https://github.com/lamanhdai/lamanhdai.github.io/blob/master/game_1/src/states/play.js

lamanhdai commented 7 years ago

@nvminhtu Dai gui source code game_1.zip

nvminhtu commented 7 years ago

this.game.physics.startSystem(Phaser.Physics.ARCADE); @lamanhdai phải thêm đoạn code này trước khi chạy Physics, ngoài ra có thể debug từng cái một = cách consoler Phaser rồi lần lượt vì tất cả đều là dạng Object, dễ coi

nvminhtu commented 7 years ago

@lamanhdai khi cần khởi tạo biến xài chung trong 1 Class, sử dụng init() function, xem trong Phaser.State class (http://phaser.io/docs/2.4.4/Phaser.State.html#init) vì thế trong class extend của Phaser.State chỉ được call các hàm đã kế thừa, việc gọi constructor() sẽ bị lỗi (đang kiểm tra xem tại sao)

class Play extends Phaser.State {

// init() { // khởi tạo các giá trị dùng chung this.greeting = 'hello'; // test thử console this.sprite = null; this.sprites = null; }