File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export class Obstacle {
1010 private flutterAmplitude : number = 0 ;
1111 private flutterFrequency : number = 0 ;
1212 private flutterOffset : number = 0 ;
13+ private body ! : Phaser . Physics . Arcade . Body ;
1314
1415 constructor (
1516 scene : Phaser . Scene ,
@@ -24,6 +25,12 @@ export class Obstacle {
2425 this . sprite = this . scene . physics . add . sprite ( x , - 16 , obstacleType ) ;
2526 this . sprite . play ( `${ obstacleType } -fall` , true ) ;
2627 this . sprite . setOrigin ( 0.5 , 1 ) ;
28+ this . body = this . sprite . body as Phaser . Physics . Arcade . Body ;
29+ this . body . setSize ( this . sprite . width * 0.7 , this . sprite . height * 0.7 ) ;
30+ this . body . setOffset (
31+ ( this . sprite . width - this . body . width ) / 2 ,
32+ ( this . sprite . height - this . body . height ) / 2
33+ ) ;
2734
2835 const minSpeed = 30 + score * 0.5 ;
2936 const maxSpeed = 60 + score ;
Original file line number Diff line number Diff line change @@ -4,11 +4,18 @@ export class Player {
44 private scene : Phaser . Scene ;
55 private sprite : Phaser . Physics . Arcade . Sprite ;
66 private horizontal : number = 0 ;
7+ private body ! : Phaser . Physics . Arcade . Body ;
78
89 constructor ( scene : Phaser . Scene , x : number , y : number , spriteName : string ) {
910 this . scene = scene ;
1011 this . sprite = this . scene . physics . add . sprite ( x , y , spriteName ) ;
1112 this . sprite . play ( `${ spriteName } -walk` ) ;
13+ this . body = this . sprite . body as Phaser . Physics . Arcade . Body ;
14+ this . body . setSize ( this . sprite . width * 0.7 , this . sprite . height * 0.7 ) ;
15+ this . body . setOffset (
16+ ( this . sprite . width - this . body . width ) / 2 ,
17+ ( this . sprite . height - this . body . height ) / 2
18+ ) ;
1219 }
1320
1421 update ( horizontal : number ) {
You can’t perform that action at this time.
0 commit comments