after I tried to make the pipes move I got this error in phaser.js:1:
Uncaught TypeError: Cannot read properties of undefined (reading 'setCollideWorldBounds')
at initialize.createCallbackHandler (phaser.js:1:646743)
at initialize.add (phaser.js:1:241318)
at initialize.addMultiple (phaser.js:1:241594)
at initialize [as constructor] (phaser.js:1:238256)
at new initialize (phaser.js:1:646577)
at initialize.group (phaser.js:1:642623)
at initialize.update (game.js:72:37)
at initialize.step (phaser.js:1:966940)
at initialize.update (phaser.js:1:954010)
at initialize.step (phaser.js:1:76119)
here is the code I used:
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
pixelArt: true,
backgroundColor: '#4488aa',
scene: {
preload: preload,
create: create,
update: update
},
physics: {
default: 'arcade',
arcade: {
debug: true
}
}
};
const game = new Phaser.Game(config);
function preload() {
this.load.spritesheet('player-sheet', 'assets/player-sheet.png', {frameWidth: 16, frameHeight: 16});
this.load.image('top-pipe', 'assets/top-pipe.png');
this.load.image('btm-pipe', 'assets/btm-pipe.png');
}
function create() {
// GENERAL //
this.spacebarkey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE)
// this.PLAYER //
this.player = [];
this.player.x = 400;
this.player.y = 300;
const jumpAnim = {
key: 'jump',
defaultTextureKey: "player-sheet",
duration: 1,
frames: [
{frame: 0, duration: 1 },
{ frame: 1, duration: 50},
{ frame: 2, duration: 75},
{ frame: 1, duration: 20},
{frame: 0, duration: 1 }
]
};
this.anims.create(jumpAnim);
this.player.sprite = this.physics.add.sprite(this.player.x, this.player.y, 'player-sheet', 0);
this.player.sprite.setScale(4);
this.player.sprite.smoothed = false;
this.player.sprite.setGravityY(950);
// PIPES //
this.pipes = this.physics.add.group();
}
function update() {
// PLAYER //
if (Phaser.Input.Keyboard.JustDown(this.spacebarkey)) {
this.player.sprite.play("jump", true)
this.player.sprite.setVelocity(0, -500)
var twoPipes = this.physics.add.group(this.pipes);
var yOffset = ((Math.random() - 0.5) * 100) * 2
twoPipes.create(700, -50, 'top-pipe');
twoPipes.create(700, 650, 'btm-pipe');
twoPipes.children.iterate(function(child) {
child.setScale(4)
child.setPosition(child.x , child.y + yOffset)
this.pipes.create(child)
})
//this.pipes.create(twoPipes)
}
if (this.player.sprite.y < 0 || this.player.sprite.y > config.height) {
this.scene.restart();
}
// Pipes //
this.pipes.children.iterate(function(pipe) {
pipe.setPosition(pipe.x - 1, pipe.y);
});
}