AmbitiousIndie Posted June 3, 2020 Share Posted June 3, 2020 (edited) // hello again lads! I've got another problem. I was working on a game and I was specifically // working on a Gameplay scene and there was no specific error in the console but the physics // collider between my platform and the player wasn't working and my player fell through the // platform. Can somebody point out the mistake I've made? Any help will be greatly appreciated :) // The code from my 'Gameplay' scene: var platform; var player; class gamePlay extends Phaser.Scene{ constructor(){ super({key: 'playing'}); } preload(){ this.load.image('sky', 'assets/sky.png'); this.load.image('sun', 'assets/sun.png'); this.load.image('ground', 'assets/platform.png'); this.load.image('cubey', 'assets/cubey(1).png', {frameWidth: 32, frameHeight: 32} ); } create(){ this.add.image(400, 300, 'sky'); this.add.image(400, 100, 'sun'); platform = this.physics.add.staticGroup(); platform.create(400, 500, 'ground'); platform.create(250, 500, 'ground'); platform.create(500, 500, 'ground'); player = this.physics.add.sprite(400, 300, 'cubey'); player.setBounce(0.3); player.setCollideWorldBounds(true); this.physics.add.collider(player, platform); // not working } update(){ } } Edited June 3, 2020 by AmbitiousIndie Link to comment Share on other sites More sharing options...
DarkMoon_Lander Posted June 4, 2020 Share Posted June 4, 2020 Instead of defining `player` from a `var` keyword, try defining it in the class you called using: class example extends Phaser.Scene { constructor() { super('example'); } create() { this.player = this.physics.add.sprite(x, y, "key"); this.physics.add.collider(this.player, this.collidingThing); } Link to comment Share on other sites More sharing options...
Recommended Posts