Emsel Posted May 27, 2014 Share Posted May 27, 2014 Hello I'm a little noob trying to make a very simple game with Phaser 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 More sharing options...
marvster Posted May 27, 2014 Share Posted May 27, 2014 Your objects do have a body until it's enabled on them with like:game.physics.arcade.enableBody(player); Link to comment Share on other sites More sharing options...
rich Posted May 27, 2014 Share Posted May 27, 2014 "TypeError: game.physics.startSystem is not a function" Which version of Phaser are you using? It will say when open the dev tools in your browser. My guess would be it's an old one. Link to comment Share on other sites More sharing options...
Emsel Posted May 27, 2014 Author Share Posted May 27, 2014 Phaser version is 1.1.3I guess i'm missing something big here, no? xDSorry my bad english D: Link to comment Share on other sites More sharing options...
lewster32 Posted May 27, 2014 Share Posted May 27, 2014 You will need a newer version of Phaser to use the above. The latest version of Phaser is 2.0.5. You can download the minified version directly from here. Link to comment Share on other sites More sharing options...
Emsel Posted May 27, 2014 Author Share Posted May 27, 2014 Oh man, 2.0.5? i was using 1.1.3 jaja i don't know how to say it, but i'm very sorry for creating a topic for this. Thanks to all. Now it is working I will be uploading a little game this days Abrazo desde Argentina lewster32 1 Link to comment Share on other sites More sharing options...
lewster32 Posted May 27, 2014 Share Posted May 27, 2014 No problem - it looks like a lot of people are still on old versions, clearly coming here from outdated tutorials! Welcome to the community, and I'm looking forward to seeing your game Link to comment Share on other sites More sharing options...
Emsel Posted May 27, 2014 Author Share Posted May 27, 2014 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 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 Link to comment Share on other sites More sharing options...
lewster32 Posted May 27, 2014 Share Posted May 27, 2014 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 More sharing options...
Emsel Posted May 28, 2014 Author Share Posted May 28, 2014 It works! Thanks In a few days i will be uploading the game n.n Link to comment Share on other sites More sharing options...
Recommended Posts