Jump to content

Search the Community

Showing results for tags 'overlap problem collision'.

  • 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. hello ! so let's introduce myself quickly before any misunderstanding i'm a french student (i hope i will not make too much mistakes in my sentences), who learn coding and how to make awesome movies ! So, I discover the Phaser framework last week (god, thanks for making so good people who build awesome things on this planet ! ) And i try to make my first game ! OK ... i try to make this game : pretty simple I know.... but for my first game, it makes me think a lot. So, here is my code... (I know, there is probably different ways to make it better ! but it's mine !) var game = new Phaser.Game(350, 500, Phaser.AUTO, 'game_div');var direction = 220;var compteur = 0;//equivalent d'un main en C++ ou Cvar main_state ={ preload: function() { //couleur de fond ==> backgroundColor this.game.stage.backgroundColor = "#d7d7d7"; //charger l'image du piaf this.game.load.image('piaf', 'images/pigeon.png'); this.game.load.image('spikes', 'images/pikes.png'); this.game.load.image('under_spikes', 'images/pikes_down.png'); this.game.load.image('murDroit', 'images/mur.png'); this.game.load.image('murGauche', 'images/mur.png'); }, create: function() { //chargement des paramètres de physique du jeu => arcade game.physics.startSystem(Phaser.Physics.ARCADE); //ajouter le piaf sur l'ecran, avec les images des PIKES ! //this.truc = this.game.add.sprite(positionX, positionY, 'truc'); this.piaf = this.game.add.sprite(game.world.centerX, game.world.centerY, 'piaf');//je centre mon piaf au debut du jeu this.spikes = this.game.add.sprite(0, 470, 'spikes'); this.under_spikes = this.game.add.sprite(0, 0, 'under_spikes'); this.murDroit = this.game.add.sprite(game.width-5, 0, 'murDroit'); this.murGauche = this.game.add.sprite(-27, 0, 'murGauche'); var sprite = this.piaf; var spikes = this.spikes; var under_spikes = this.under_spikes; var murDroit = this.murDroit; var murGauche = this.murGauche; //ajout des physiques a mes images game.physics.enable(sprite, Phaser.Physics.ARCADE); murDroit.enableBody = true; murGauche.enableBody = true; spikes.enableBody = true; under_spikes.enableBody = true; sprite.enableBody = true; //redimensionnement de mon sprite / image de piaf sprite.scale.x = 0.37; sprite.scale.y = 0.37; //je centre l'ancre de mon piaf au centre de son sprite sprite.anchor.setTo(0.5, 0.5); //une variable clique qui correspond au clique de ma souris var clique = this.game.input; //lors d'un, on lance la fonction jump clique.onDown.add(this.jump, this); //space_key.onDown.add(this.jump, this); //attribution d'une vélocité linéaire horizontale sprite.body.velocity.x = direction; //ajout des bords physique du cadre sprite.body.collideWorldBounds = true; //influence de la gravité sur mon pigeon sprite.body.gravity.set(0, 1000); //ajout de la puissance de rebond sur les bords sprite.body.bounce.set(1); //on check les rebonds / collision sur tous les murs sauf le haut et le bas game.physics.arcade.checkCollision.down = false; game.physics.arcade.checkCollision.up = false; }, update: function() //equivalent d'un RequestAnimFrame = optimisation cadence affichage { //si le piaf est trop bas ou trop haut, on appel une fonction de redemarrage. if(this.piaf.inWorld == false) { this.piaf.kill(); compteur = 0; document.getElementById("message").innerHTML = "Vous avez mouru ..."; if(game.input.mousePointer.isDown) { this.restart_game(); } } //je redefini mes variables var sprite = this.piaf; var spikes = this.spikes; var under_spikes = this.under_spikes; var murDroit = this.murDroit; var murGauche = this.murGauche; if(checkOverlap(sprite, spikes) || checkOverlap(sprite, under_spikes)) { sprite.inWorld = false; } else if(checkOverlap(sprite, murDroit)) { sprite.body.velocity.x = -direction; compteur++; document.getElementById("score").innerHTML = compteur + " points"; } else if(checkOverlap(sprite, murGauche)) { sprite.body.velocity.x = direction; compteur++; document.getElementById("score").innerHTML = compteur + " points"; } }, jump : function() { var sprite = this.piaf; sprite.body.velocity.y = -300; }, checkOverlap: function(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB); }, restart_game : function() { document.getElementById("message").innerHTML = ""; document.getElementById("score").innerHTML = ""; this.game.state.start('main'); }};//demarrage du jeugame.state.add('main', main_state);game.state.start('main');my problem : i want my "piaf"/ my "sprite" (=my main character) to detect collision with the spikes at the top and at the bottom of my game world. So i wrote the above code. But it tells me that the function "checkOverlap" is not defined. and i don't understand why ... I check the overlap of my sprite and my walls (murDroit & murGauche) in my "update" function. Have you got any ideas ? thanks
×
×
  • Create New...