Dragonfly3r Posted February 26, 2015 Share Posted February 26, 2015 So currently in process of making a platformer game and using a mario sprite as temporary sprite. Now I want to make collisions between the sprite (player) and the spikes in my game (tile id= 12,13,14,15) and when it collides with the spikes it will destory current sprite and redraw a new 1 at the x & y axis I've chosen (135,110) but when I run the code I get line 73 error saying that PlayerDie is not being defined. The code is below and the line that is causing the error is this: // Sets up collision with Tile ID 12 (The Spike) to call the PlayerDie function when collided with map.setTileIndexCallback(12,13,14,15 PlayerDie, this);BasicGame.Game = function (game) { // When a State is added to Phaser it automatically has the following properties set on it, even if they already exist: this.game; // a reference to the currently running game this.add; // used to add sprites, text, groups, etc this.camera; // a reference to the game camera this.cache; // the game cache this.input; // the global input manager (you can access this.input.keyboard, this.input.mouse, as well from it) this.load; // for preloading assets this.math; // lots of useful common math operations this.sound; // the sound manager - add a sound, play one, set-up markers, etc this.stage; // the game stage this.time; // the clock this.tweens; // the tween manager this.state; // the state manager this.world; // the game world this.particles; // the particle manager this.physics; // the physics manager this.rnd; // the repeatable random number generator this.map; this.layer; this.player; this.cursors; this.spikes; // You can use any of these from any function within this State. // But do consider them as being 'reserved words', i.e. don't create a property for your own game called "world" or you'll over-write the world reference.};BasicGame.Game.prototype = { create: function () { console.log("Creating game state!"); //Change the stagebackgroundColour to classic Mario blue. //this.stage.backgroundColor = '#6888ff'; //Populate the local map attribute with the tilemap with they key "level" map = this.add.tilemap('level'); //Assign the "level_tiles" tileset to the tilemap data map.addTilesetImage('level_design', 'level_tiles'); //Populate the local layer with the combined level data. layer = map.createLayer('level_design'); //Resize the game world to fit the level data. layer.resizeWorld(); this.physics.startSystem(Phaser.Physics.ARCADE); map.setCollision([0,1,2,3,4,5,19,25,26,27,28], true); player = this.add.sprite(135, 110, 'mario'); this.physics.arcade.enable([player]); this.physics.arcade.gravity.y = 500; player.body.collideWorldBounds =true; player.body.setSize(12, 16, 2, 0); cursors = this.input.keyboard.createCursorKeys(); player.animations.add('run',[0,1,2],10,true); player.animations.add('stand',[6]); // Sets up collision with Tile ID 12 (The Spike) to call the PlayerDie function when collided with map.setTileIndexCallback(12,13,14,15 PlayerDie, this); // Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out! }, PlayerDie: function (player, layer) { player = this.sprite.destroy('mario'); player = this.add.sprite(135, 110, 'mario'); //add 1 to death counter }, update: function () { // Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out! this.physics.arcade.collide(player, layer); if (cursors.left.isDown) { //Give the player's physics body some velocity on the x (horizontal axis). player.body.velocity.x = -175; //Play the run animation player.animations.play('run'); } //Check if the right arrow is down else if (cursors.right.isDown) { //Give the player's physics body some velocity on the x (horizontal axis). player.body.velocity.x = 175; //Play the run animation player.animations.play('run'); } //Neither direction is pressed. else { //Remove the player's physics body's horizontal velocity. player.body.velocity.x = 0; //Play the Stand animation player.animations.play('stand'); } //if the up arrow is pressed and mario is touching another physics body below. if (cursors.up.isDown && player.body.onFloor()) { //Give the player's physics body some vertical velocity. player.body.velocity.y = -375; } }, quitGame: function (pointer) { // Here you should destroy anything you no longer need. // Stop music, delete sprites, purge caches, free resources, all that good stuff. // Then let's go back to the main menu. this.state.start('MainMenu'); },};Anyone be able to tell me what is going wrong as been looking over it numerous times & looking at other sites for ideas with no luck. Link to comment Share on other sites More sharing options...
ZeroGravity Posted February 27, 2015 Share Posted February 27, 2015 If I am not wrong you are missing , from the code above ... so it probably says missing method 15 PlayerDie. So fix that, and it probably works.. map.setTileIndexCallback(12,13,14,15 , /* <--- this here*/ PlayerDie, this); Link to comment Share on other sites More sharing options...
Recommended Posts