thebatq100 Posted February 11, 2021 Share Posted February 11, 2021 var game = new Phaser.Game(config); var speed = 200; var map; var player; var cursors; var text; var noSpike = true; var spikes; function preload() { this.load.image('player', 'assets/squareBoy.png'); this.load.image('spike', 'assets/Enemy-1.png'); // map made with Tiled in JSON format } function create() { cursors = this.input.keyboard.createCursorKeys(); //player player = this.physics.add.sprite(200, 200, 'player'); player.setBounce(.87); // our player will bounce from items player.setCollideWorldBounds(true); // don't go out of the map //Enemy spikes = this.physics.add.group(); //when player touches spikes destroy that spike this.physics.add.collider(player, spikes, function (spike) { spike.destroy(); }) } function update() { if(noSpike) { for (var i = 0; i <= 6; i++) { var x = Phaser.Math.Between(0, 1000); var spike = spikes.create(x, 16, 'spike'); spike.setBounce(1); spike.setCollideWorldBounds(true); spike.setVelocity(Phaser.Math.Between(-200, 200), 20); spike.setScale(1.5); spike.allowGravity = false; } noSpike = false; } } Every time I try to make a collision between my player and a spike the whole game just stops/freezes. no matter what I do or what the interaction is it always freezes. Help please. Am I doing that incorrectly? Link to comment Share on other sites More sharing options...
Recommended Posts