Jump to content

Search the Community

Showing results for tags 'reload level'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. Hi, i'm new to phaser and i'm making a game to practice, i separated the different sections of the game in files: Boot, Preload, GameTitle (or menu) and finally TheGame... TheGame as you may imagine contains the game map, player and all the physics stuff I will make a short version of my problem after posting the code: I want a map layer (made with tilemap) to collide with player that makes the player lose a life or something like that.. i want the level to reset, so i do this: this.game.physics.arcade.collide(player, layer3, this.restartLevel);the code for that function is: restartLevel: function(){ this.game.state.start(game.state.current);} But i get an error in the chrome console: Uncaught TypeError: Cannot read property 'state' of undefined I saw in some posts on the forum that the "game.state.start(game.state.current);" should be at the "create" function but as you see below it's inside the "restartLevel" function. Here is the whole code of "TheGame" (then i have the other files that load sprites, images and all those things), hope anyone can help me. Thanks! MyGame.TheGame = function(game){var map = null; var player = null; var layer = null; var layer2 = null; var collidetiles = null; var playerGravity = null; var doubleJump = null;}MyGame.TheGame.prototype = { create: function(){ //gravedad this.game.physics.startSystem(Phaser.Physics.P2JS); //PROPERTIES collidetiles = [20, 34, 90, 62]; //tile numbers that collide with player playerGravity = 1200; doubleJump = false; //add tiles to mapmap = this.game.add.tilemap('map', 32, 32); map.addTilesetImage('tiles', 'tiles'); map.addTilesetImage('hills', 'hills'); //create layer & resize world layer1 = map.createLayer('background'); layer2 = map.createLayer('objects'); layer3 = map.createLayer('damage'); layer4 = map.createLayer('extra'); layer1.resizeWorld(); layer2.resizeWorld(); layer3.resizeWorld(); layer4.resizeWorld(); //allow cursors to scroll around the map cursors = this.game.input.keyboard.createCursorKeys(); //set map collision map.setCollision(collidetiles, true, layer2); map.setCollision(collidetiles, true, layer3); map.setCollision(collidetiles, true, layer4); //spawn player this.spawnPlayer(); //make camera follow player this.game.camera.follow(player); //player properties this.game.physics.arcade.enable(player); //add physics to player player.body.gravity.y = playerGravity; player.body.setSize(30, 30, 0, 0); player.body.collideWorldBounds = true;},update: function(){ //collide player with objects in the map layer this.game.physics.arcade.collide(player, layer2); this.game.physics.arcade.collide(player, layer3, this.restartLevel); this.game.physics.arcade.collide(player, layer4);player.body.velocity.x = 0; //reset velocity when moving left or right //keyboard move left and right (A & D) if (this.game.input.keyboard.isDown(Phaser.Keyboard.A) && !this.game.input.keyboard.isDown(Phaser.Keyboard.D)){ this.moveLeft(); } else if (this.game.input.keyboard.isDown(Phaser.Keyboard.D) && !this.game.input.keyboard.isDown(Phaser.Keyboard.A)){ this.moveRight(); } //keyboard jump and action (W) jumpButton = this.game.input.keyboard.addKey(Phaser.Keyboard.W); jumpButton.onDown.add(this.checkJump, this); //when you touch floor let jump again if you don't jump first if(player.body.onFloor()) doubleJump = true;},render: function(){ //show camera infothis.game.debug.cameraInfo(this.game.camera, 32, 32); //show fps this.game.debug.text("FPS:" + this.game.time.fps, 748, 16, 'rgb(255,255,255)', '14px Courier');}, checkJump: function(){ //if on floor, jump and give another jump if(player.body.onFloor()){ player.body.velocity.y = -500; doubleJump = true; } //if in air and can jump again, jump and don't let jump again if(!player.body.onFloor() && doubleJump){ player.body.velocity.y = -500; doubleJump = false; } //console.log(doubleJump); }, moveLeft: function(){ player.body.velocity.x = -220; }, moveRight: function(){ player.body.velocity.x = 220; }, spawnPlayer: function(){ player = this.game.add.sprite(70, 280, 'player'); player.anchor.set(0.5); }, restartLevel: function(){ this.game.state.start(game.state.current); }}
×
×
  • Create New...