Search the Community

Showing results for tags 'detection'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 12 results

  1. Platformer collision problem

    Hi guys! I'm new to Phaser, with basic knowledge of JS. I have a problem with my platform game, which I've started with this tutorial. The code is different from every tutorial I've seen on Phaser main webpage, so It's hard for me to get in to. (no update, create, preload function in main is the beggining of all my problems)... I wanted to add a shooting system, which I learned from this: I applied this code to the platformer engine, and I am not sure if I did it correctly. I have created shooting system in Player object, because I didn't know how to do it other way. This code look like this: //In player: Platformer.Player = function (game_state, position, properties) { "use strict";, game_state, position, properties); (...) //bullets bullets =; bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.callAll('events.onOutOfBounds.add', 'events.onOutOfBounds', resetBullet, this); bullets.setAll('checkWorldBounds', true); bullets.createMultiple(100, 'pocisk'); function resetBullet (bullet) { bullet.kill(); } //In player.prototype.update : Platformer.Player.prototype = Object.create(Platformer.Prefab.prototype); Platformer.Player.prototype.constructor = Platformer.Player; Platformer.Player.prototype.update = function () { "use strict";, this.game_state.layers.collision);, this.game_state.groups.enemies, this.hit_enemy, null, this); (...) //bullets if (this.spaceKey.isDown) { this.fireBullet(); } this.fireBullet = function() { if ( > bulletTime) { bullet = bullets.getFirstExists(false); if (bullet) {, Platformer.Enemy, this.zderzenie, null, this); bullet.reset(this.body.x + 6, this.body.y - 8); bullet.body.allowGravity = false; if (this.profil==1) //direction of shooting bullet.body.velocity.x = 300; else bullet.body.velocity.x = -300; if(bullet.body.x==Platformer.Enemy.x && bullet.body.y==Platformer.Enemy.y) bullet.kill(); bulletTime = + 250; } } } And it works, the player is shooting circles in left or right direction. The problem starts now. I need to somehow code the collision between the bullet and the enemy. As you can see above, I wrote thing like this : if(bullet.body.x==Platformer.Enemy.x && bullet.body.y==Platformer.Enemy.y) bullet.kill(); But this don't work. What can I do? It is the problem with seperate objects? Or maybe I know nothing and made serious stupid mistakes?
  2. onBeginContact not firing every time

    Hello, Making a basket ball game and I want to increase the score when I detect that the ball has been sunk in the basket. I place a rectangular sensor body under the net so it doesn't stop the ball from passing through it but can detect collisions. I create the sensor in the create() function: //Setting up checker physics, true);[0].sensor = true; this.checker.body.static = true; And I add this onBeginContact callback, also in the create() function: this.checker.body.onBeginContact.add(this.checkIfScored, this); And since I only want to increase the score if the ball is travelling downwards through the net: checkIfScored : function () { console.log(this.ball.body.velocity.y); if (this.ball.body.velocity.y > 0) { console.log("SCORED!"); this.score++; this.scoreText.setText('Score: ' + this.score); } } My problem is: onBeginContact is only firing on the ball's way up, but it doesn't fire again on the way down and I don't know why. You can see the image below of it's setup on the stage. I've been in and out of the forums, digging for an answer. Any help is very much appreciated!!
  3. For simplicity I have a game and I'm trying to get my car to hit a wall. I've tried searching and I've tried several things as you'll see below, I'm not sure why I can't get it to work. Here is the code in my create function: create: function () { game.physics.startSystem(Phaser.Physics.ARCADE); this.carSprite = game.add.sprite(,, 'car'); game.physics.arcade.enable(this.carSprite); this.timer =, this.addRoad, this); } Then in my update function: update: function () { game.physics.arcade.overlap(this.carSprite, this.wallSprite, this.scoring, null, this); } I am creating the wallSprite like this: addOneRoadSection: function (x, y) { this.scoreCalculator += 1; if (this.scoreCalculator == 10) { this.scoreCalculator = 0; this.wallSprite = game.add.sprite(x + 100, y, 'wall'); game.physics.arcade.enable(this.wallSprite); this.wallAnimation = this.wallSprite .animations.add('wallAnimation');'wallAnimation', 30, true); this.wallSprite.body.velocity.y = 100; this.wallSprite.checkWorldBounds = true; this.wallSprite.outOfBoundsKill = true; } } I am calling addOneRoadSection like this: addRoad: function () { this.addOneRoadSection(this.xValue, 0); } addRoad is being called in create using this.timer` So in summary what this is doing is that when the scoreCalculator is ten, it add's a wall. That works fine, the wall is animated fine, but the collision detection does not work at all. I tried moving the code inside of the if statement to my create function and it works fine with collision detection (but other things break so I can't keep it there). What am I doing wrong? I have a suspicion that this.wallSprite may be referring to something else at the time it is called in update?
  4. Collide Against Multiple Objects

    I am currently working on a procedural generation program in Phaser, which generates the environment by stitching together a series of tiles in a grid format. Think along the lines of a roguelike. At the moment the collision detection is a bit wonky under certain circumstances. When I move against a set of solid tiles horizontally with Arcade physics turned on and the walls set to immovable, it moves along smoothly; The black line is just there to illustrate where the non-solid tiles end and the solid ones begin. Each tile on screen is an individual sprite. When moving vertically though, the movement gets "stuck" as if the item is catching against the solid items. Again as above, each tile is a sprite; I'm using moveToPointer to move the object on screen. Here's a screenshot with some debug collision bodies turned on for reference; Any help is greatly appreciated, thank you.
  5. Collision detection problem [SOLVED]

    Hi, I'm writing my first projects with Panda.js. My problem is collision detection, which does not work. Looking at flyingdog, I developed some basic code for collisions for AI enemy and projectile (both): this.body = new game.Body({ position : { x : x, y : y }, collisionGroup : 0, collideAgainst : 1, mass : 0 }); this.body.collide = this.collide.bind(this); remove : function(obj) { obj.isRemoved = true;; game.scene.stage.removeChild(obj.sprite); game.scene.removeObject(obj); }, collide : function() { console.log('Hit!'); this.remove(this); return true; }, But it does not hit - even no message on console log - so it seems, that collide function was never called. What did I wrong or what did I miss? Thx in advance! PP
  6. Hi! I'm currently working with a project where I decided to use babylon.js, and is a newbie on the framework. I have imported a BIM-model which consists of hundred of meshes into babylon, and wondered if there is a way to check collisions for all these meshes without have to get each mesh by name, var mesh = getMeshByName("meshName"); and then assign it mesh.checkCollisions = true;Is there a way to loop through all the importet meshes without getting them by name?
  7. Hey! I'm working further on with the first tutorial from Phaser, the platform game. I've changed a few things, such as different sprites. I'm trying to get a different image for the ground and the 2 platforms, but now my collision isn't working anymore... Also it won't show the platforms anymore. Complete beginner here, hope to get some help! Thanks in advance index.html
  8. My site has not been thoroughly tested in Internet Explorer. So for the time being I detect Internet Explorer and redirect the user to another page using this method: if(window.ActiveXObject || "ActiveXObject" in window){ // Always true if browser is Internet Explorer window.location = 'pages/core/ie.htm';}Works flawlessly. Except.... Google's spiders must use activeX because on the Google results page it always shows the ie.htm page. Is there another simple, rock solid method to detect Internet Explorer in Javascript?
  9. Hello, I was wondering how could I implement collision detection and not when one of the sprites/images has transparent pixels (and these should not trigger overlap/collide). Consider the following image: So that should only trigger the overlap/collide when the ball touches the part of the oktagon where there is no transparency. Is this possible with Phaser and I would really appreciate an example or snipper or anything you can share. Thanks.
  10. Phaser one-sided overlap detection?

    Hi guys, At the moment I'm having some issues detecting which sprite is overlapping another sprite. The overlap function works fine, but I would like to know which of the 2 sprites goes over the other sprite. I only want to execute a certain function if sprite A walks over sprite B, and not if sprite B walks over sprite A. Is there any way I could check this inside of the overlap function? Thanks, Kevin
  11. Collision Exit Detection

    I need to find a way to detect when a sprite exits collisions. My goal here is that when a sprite enters a collision an animation is played and when the sprite exits the collision the animation is paused leaving the sprite at a different frame from a sprite sheet. If there a simple built in function to phaser to achieve this? Or do I need to find a different solution. Here is my simple code so far: function update() { game.physics.collide(cup, sprite2, collisionHandler, null, this);}function collisionHandler (obj1, obj2) {'fill', 10);}