We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
You can continue the conversation there. Go to discussion →
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes, collision is not working
my code is here
import Phaser from 'phaser'; export default class MyScene extends Phaser.Scene { player!: Phaser.Physics.Arcade.Sprite; cursors!: Phaser.Types.Input.Keyboard.CursorKeys; constructor() { super('demo'); } preload() { this.load.image('grass', 'assets/grass.png'); this.load.image('background', 'assets/blue_desert.png'); this.load.tilemapTiledJSON('map', 'assets/map01.json'); this.load.atlas('player', 'assets/yellow_ailen.png', 'assets/yellow_ailen.json'); } create() { const map = this.make.tilemap({ key: 'map' }); const backgroundTileset = map.addTilesetImage('colored_land', 'background', 128, 128); const grassTileset = map.addTilesetImage('grass', 'grass', 128, 128); const backgroundLayer = map.createLayer('background', backgroundTileset, 0, 0); const grassLayer = map.createLayer('grass', grassTileset, 0, 0); grassLayer.setCollisionByExclusion([-1]); grassLayer.renderDebug(this.add.graphics(), { tileColor: null, collidingTileColor: new Phaser.Display.Color(244, 255, 36, 100), // Colliding tiles faceColor: new Phaser.Display.Color(255, 0, 0, 255) // Colliding face edges, }); const spawnPoint = map.findObject('objects', obj => obj.name === 'spawn'); this.cursors = this.input.keyboard.createCursorKeys(); this.player = this.physics.add.sprite(spawnPoint.x!, spawnPoint.y!, 'player', 'alienYellow_front.png'); this.player.setSize(90, 150); this.player.setOffset(20, 110); this.player.anims.create({ key: 'walk', frameRate: 7, frames: this.anims.generateFrameNames('player', { prefix: 'alienYellow_walk', suffix: '.png', start: 0, end: 2, zeroPad: 1 }), repeat: -1 }); grassLayer.layer.data.forEach(row => { row.forEach(tile => { if (tile.properties.collides) { tile.setCollision(false, false, true, false); } }); }); this.physics.add.collider(this.player, grassLayer); this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels); const camera = this.cameras.main; camera.startFollow(this.player); camera.setBounds(0, 0, map.widthInPixels, map.heightInPixels); } update(time: number, delta: number): void { if (this.cursors.left.isDown) { this.player.setVelocityX(-600); } else if (this.cursors.right.isDown) { this.player.setVelocityX(600); } else { this.player.setVelocityX(0); } if (this.cursors.up.isDown) { this.player.setVelocityY(-1250); } } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Sometimes, collision is not working
my code is here
The text was updated successfully, but these errors were encountered: