[英]Phaser applying physics to child class of Phaser.Sprite (ES6)
我正在嘗試將Gravity.Y Arcade Physics應用於角色類(Phaser.Sprite)。 但是重力沒有影響Sprite並保持在原位。
是否有應用物理的特定順序? 注意:我也嘗試在game.add.existing(char)之前和之后啟用/應用物理。
1)失敗
擴展的Phaser.Sprite字符類的示例,
已應用ARCADE物理,但無法正常運行:
class Char extend Phaser.Sprite {
constructor(game,x,y){
super(game,x,y,'dude')
game.add.existing(this)
game.physics.arcade.enable(this)
this.body.gravity.y = 300
}
}
// calling it in create()
create(game){
game.physics.startSystem(Phaser.Physics.ARCADE)
var x = new Char(game,0,0)
}
2)工作
然后嘗試正常的Sprite創作和引力工作。
create(game){
game.physics.startSystem(Phaser.Physics.ARCADE)
var x = game.add.sprite(0,0,'dude')
game.physics.arcade.enable(x)
x.body.gravity.y=300
}
我的錯
該代碼實際上在工作,這是由於另一個設置“ fixedToCamera = true”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.