Jump to content

[Problem] TypeError: game.physics.startSystem is not a function


Emsel
 Share

Recommended Posts

Hello :D I'm a little noob trying to make a very simple game with Phaser :D
When I add the line for enabling arcade physics, the code stop working and then the errror "TypeError: game.physics.startSystem is not a function" is throwed u.u

<!DOCTYPE HTML><html lang="es"><head>    <meta charset="utf-8"/>    <title> Pyroprobando cosas (? XD</title>    <script src="js/phaser.min.js"></script></head><body><!-- Game code -->    <script>/* Pruebas PhaserJS - Emilio Salvador Grisolía   PyroJazz - */game = new Phaser.Game(800, 600,                            Phaser.AUTO, '', {                            preload: preload,                            create: create,                            update: update}                            );var minSpeed = 0;var maxSpeed = 200;var cursors; //For the arrow keysvar baddies; //For the Pinkatz baddies :Dvar player;var elixirs; //For the life elixirs :Dfunction preload() {    game.load.spritesheet('crazyArmor', 'res/spritesheets/crazy.png', 25, 45);    game.load.spritesheet('baddie', 'res/spritesheets/baddie.png', 32, 32);    game.load.image('elixir', 'res/images/firstaid.png');}function create() {    game.physics.startSystem(Phaser.Physics.ARCADE);    baddies = game.add.group();    elixirs = game.add.group();    player = game.add.sprite(400, 300, "crazyArmor");    player.animations.add('left', [12, 13, 14, 15, 16], 8, true);    player.animations.add('right',[18, 19, 20, 21, 22], 8, true);    player.animations.add('down', [0, 1, 2, 3, 4, 5], 8, true);    player.animations.add('up',   [6, 7, 8, 9, 10], 8, true);    cursors = game.input.keyboard.createCursorKeys();}function update() {    //Vericar teclas presionadas    if (cursors.up.isDown) {        // Llendo hacia arriba        player.animations.play('up');        player.body.velocity.x = minSpeed;        player.body.velocity.y = -maxSpeed;    } else if (cursors.left.isDown) {        // Llendo hacia la izquierda        player.animations.play('left');        player.body.velocity.y = minSpeed;        player.body.velocity.x = -maxSpeed;    } else if (cursors.down.isDown) {        // LLendo hacia abajo        player.animations.play('down');        player.body.velocity.x = minSpeed;        player.body.velocity.y = maxSpeed;    } else if (cursors.right.isDown) {        // Llendo hacia la derecha        player.animations.play('right');        player.body.velocity.y = minSpeed;        player.body.velocity.x = maxSpeed;    } else {        player.animations.stop();        player.body.velocity.y = minSpeed;        player.body.velocity.x = minSpeed;    }}    </script><!-- End game code --></body></html>If i remove the "game.physics.startSystem(Phaser.Physics.ARCADE);" everything works fine. Also, when adding the code for enabling physics, an error says "cursors is not defined" line 70 :\What im doing wrong? And search this on Google, but nothing came up. Also, i am not a good english writer/reader heheAnyway, thanks for help :)n.n

 

Link to comment
Share on other sites

Give me a few days hehe, i call it "The Crazy Armor vs 16bit Pinkatz", it's a medieval armor that one day woke up, and realized that its alpha blending was gone, so it start fighting with the pink baddies that came with the phaser examples >.<
Now seriously :P i have some doubts... Are the examples updated? They work on 2.0.5? I'm trying to create baddies in random positions when the player collide with a baddie, but it doesn't work. It only collide with the first baddie, but no with the others created when the player collides.

 

game = new Phaser.Game(800, 600,                             Phaser.AUTO, '', {                             preload: preload,                             create: create,                             update: update,                        	render: render}                            );var minSpeed = 0;var maxSpeed = 200;var cursors; //For the arrow keysvar baddies; //For the Pinkatz baddies :Dvar player; //For the player madafaca ;Dvar elixirs; //For the life elixirs :Dfunction preload() {    game.load.spritesheet('crazyArmor', 'res/spritesheets/crazy.png', 25, 45);    game.load.spritesheet('baddie', 'res/spritesheets/baddie.png', 32, 32);    game.load.image('elixir', 'res/images/firstaid.png');}function create() {	game.physics.startSystem(Phaser.Physics.ARCADE);    baddies = game.add.group();    elixirs = game.add.group();    // Agregamos el player, y los cuadros de animación    player = game.add.sprite(400, 300, "crazyArmor");    player.animations.add('left', [12, 13, 14, 15, 16], 8, true);    player.animations.add('right',[18, 19, 20, 21, 22], 8, true);    player.animations.add('down', [0, 1, 2, 3, 4, 5], 8, true);    player.animations.add('up',   [6, 7, 8, 9, 10], 8, true);    baddies.create(200, 200, 'baddie');    // Habilitar las físicas para los elementos del juego    game.physics.enable(player,  Phaser.Physics.ARCADE);    game.physics.enable(baddies, Phaser.Physics.ARCADE);    // Teclas hereee     cursors = game.input.keyboard.createCursorKeys();}function newBaddie() {	baddies.create( Math.random()*(1000 - 200)-200,                                   Math.random()*(1000 - 200)-200,				   'baddie');}function update() {	game.physics.arcade.collide(player, baddies, newBaddie, null, this);    //Vericar teclas presionadas    if (cursors.up.isDown) {        // Llendo hacia arriba        player.animations.play('up');        player.body.velocity.x = minSpeed;        player.body.velocity.y = -maxSpeed;    } else if (cursors.left.isDown) {        // Llendo hacia la izquierda        player.animations.play('left');        player.body.velocity.y = minSpeed;        player.body.velocity.x = -maxSpeed;    } else if (cursors.down.isDown) {        // LLendo hacia abajo        player.animations.play('down');        player.body.velocity.x = minSpeed;        player.body.velocity.y = maxSpeed;    } else if (cursors.right.isDown) {        // Llendo hacia la derecha        player.animations.play('right');        player.body.velocity.y = minSpeed;        player.body.velocity.x = maxSpeed;    } else {        player.animations.stop();        player.body.velocity.y = minSpeed;        player.body.velocity.x = minSpeed;    }}function render() {	// Luego del update xD}

Is just for testing and learning purposes :P

Link to comment
Share on other sites

It looks like you're enabling physics on all of the baddies that are in the group when you start, but not on subsequent baddies when you create new ones. You should replace the following:

baddies.create(200, 200, 'baddie');// Habilitar las físicas para los elementos del juegogame.physics.enable(baddies, Phaser.Physics.ARCADE);

With this:

baddies.enableBody = true;baddies.physicsBodyType = Phaser.Physics.ARCADE;baddies.create(200, 200, 'baddie');

This will enable physics on all sprites added to the group, rather than only on the sprites that are already in the group.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...