Search the Community

Showing results for tags 'collisionGroup'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

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

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 4 results

  1. Hey, I'm developing a Phaser game and been stuck for way too long in this error in my code. Basically I create the player object and everything else from classes to groups and add them to collision groups. Finally I make them collide with body.collides where the callback should happen. I've tried firing the callbacks with just the function name, this.function, function(this.meteors) but nothing seems to work so that the callback gets fired only on contact. Either it fires with every create or never. Here's the main game.js: 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: var playerSpawnX = 300; var playerSpawnY = 300; this.game = game; // a reference to the currently running game (Phaser.Game) this.player = new BasicGame.Player(this.game,playerSpawnX,playerSpawnY); this.gem = new BasicGame.Gem(this.game); this.meteor = new BasicGame.Meteor(this.game); this.hud = new BasicGame.Hud(this.game,this.player); }; BasicGame.Game.prototype = { create: function () { this.timer; this.timer2; this.total = 0; //this.score = 0; var highscore = localStorage.getItem("highscore"); this.game.physics.startSystem(Phaser.Physics.P2JS); this.game.physics.p2.setImpactEvents(true); this.ships = this.add.group(); this.ships.enableBody = true; this.ships.physicsBodyType = Phaser.Physics.P2JS; this.ground = this.game.add.tileSprite(0, 2205, 600, 220, 'layers', 'maa'); this.ship = this.ships.create(this.player.create()); this.game.physics.p2.enable(this.ship, false); this.game.world.setBounds(0, 0, 600, 2400); //this.physics.startSystem(Phaser.Physics.P2JS); //////////////////////////////GLOBAL PHYSICS////////////////////////////////// this.game.physics.p2.setBoundsToWorld(true, false, false, true, false); //GLOBAL PHYSICS GRAVITY this.physics.p2.gravity.y = 250; // Create our collision groups. this.shipCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.meteorsCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.gemsCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.ship.body.setCollisionGroup(this.shipCollisionGroup); // This part is vital if you want the objects with their own collision groups to still collide with the world bounds // (which we do) - what this does is adjust the bounds to use its own collision group. this.shipCollisionGroup.collideWorldBounds = true; this.meteorsCollisionGroup.collideWorldBounds = false; //this.gemsCollisionGroup.collideWorldBounds = false; //to make ship hit the sides of screen this.game.physics.p2.updateBoundsCollisionGroup(); //gems group this.gems = this.game.add.group(); this.gems.enableBody = true; this.gems.physicsBodyType = Phaser.Physics.P2JS; //meteors group this.meteors = this.game.add.group(); this.meteors.enableBody = true; this.meteors.physicsBodyType = Phaser.Physics.P2JS; this.meteors.gravity = 0; this.timer = this.game.time.create(false); // Set a TimerEvent to occur for meteors and gems this.timer.loop(3000, updateScoreCounter, this); this.timer.loop(1000, spawnGems, this); this.timer.loop(7000, spawnaaMeteoriitteja, this); this.timer.loop(5000, spawnaaPaikallisiaMeteoriitteja, this); this.timer.start(); function updateScoreCounter() { this.total++; this.player.score = this.player.score + this.total * 10; console.log(this.player.score); } function spawnaaMeteoriitteja() { for (var i = 0; i < 1; i++) { var meteor = this.meteors.create(this.meteor.create()); this.game.physics.p2.enable(meteor); meteor.body.setCollisionGroup(this.meteorsCollisionGroup); meteor.body.collides([this.meteorsCollisionGroup,this.gemsCollisionGroup, this.shipCollisionGroup]); meteor.body.collideWorldBounds=false; } } function spawnaaPaikallisiaMeteoriitteja() { for (var i = 0; i < 1; i++) { var static = "true"; var meteor = this.meteors.create(this.meteor.create(this.game.world.randomX, this.game.world.randomY, static)); this.game.physics.p2.enable(meteor); meteor.body.setCollisionGroup(this.meteorsCollisionGroup); meteor.body.collides([this.meteorsCollisionGroup, this.gemsCollisionGroup, this.shipCollisionGroup]); meteor.body.collideWorldBounds=false; } } function spawnGems() { for (var i = 0; i < 2; i++) { var static = "false"; var gem = this.gems.create(this.gem.create(this.game.world.randomX, this.game.world.randomY, static)); this.game.physics.p2.enable(gem); gem.body.setCollisionGroup(this.gemsCollisionGroup); gem.body.collides([this.gemsCollisionGroup, this.shipCollisionGroup, this.meteorsCollisionGroup ]); gem.body.collideWorldBounds=false; } } this.hud.create(); this.ship.body.collides([this.shipCollisionGroup,this.meteorsCollisionGroup], hitMeteor, this); this.ship.body.collides([this.shipCollisionGroup,this.gemsCollisionGroup], hitGem, this); function hitMeteor(body1, body2) { //console.log(body1); console.log("hit meteor"); } function hitGem(body1, body2) { console.log("hit gem"); } }, update: function () { this.player.update(); }, render: function() { this.hud.render(); this.player.render(); }, quitGame: function (pointer) { } };
  2. I have a car similar to this demo...it uses P2 physics, CollisionGroup, springs and constraints to simulate the car body and two wheels. http://www.inkfood.com/create-a-car-with-phaser/ Question is how can I make the car "explode" or fall apart when needed? e.g. Collision with object or velocity is too fast, etc. I've tried to remove the springs or constraints but the car flies off the screen unpredictably. Optimally I would like to remove the spring/constraints and just have the 3 car pieces just tumble on the ground disconnected, or I could add random forces to the pieces to simulate a small explosion.
  3. Hi Pandajs experts! I have this 2 bodies in a world. body1 is a rectangle.body2 is a circle. I also have a ground. I want to make these 2 bodies fall in the ground. Rectangle falls and hit the ground. But the circle continues to fall. this.world = new game.World(0, this.gravity);var groundBody = new game.Body({position: {x: game.system.width / 2, y: 750},collisionGroup: 0});var groundShape = new game.Rectangle(game.system.width, 100);groundBody.addShape(groundShape);this.world.addBody(groundBody);var x = game.system.width / 2;var y = 600;body = new game.Body({position: {x: x, y: y},velocityLimit: {x: 100, y: 1000},collideAgainst: 0,collisionGroup: 1,});var bodyShape = new game.Rectangle(200, 30);body.addShape(bodyShape);game.scene.world.addBody(body);body2 = new game.Body({position: {x: x, y: y},velocityLimit: {x: 100, y: 1000},collideAgainst: 0,collisionGroup: 1,});var bodyShape2 = new game.Circle();body2.addShape(bodyShape2);game.scene.world.addBody(body2);body.mass = 1;body2.mass = 1; Do you have any idea?
  4. Hi all, I have some issues with CollisionGroups ( I used to use them for ImpactEvents and am starting to wonder if there are not made just for that) I'll try to make it short and clear : Let's take two collision groups : var playerGroup = game.physics.p2.createCollisionGroup();var groundGroup = game.physics.p2.createCollisionGroup();Now let's take two sprites (assume they are created and physics is enabled) and set their collision groups: player.body.setCollisionGroup(playerGroup);ground.body.setCollisionGroup(groundGroup);With that if I want to enable collisions between these two sprites, I have to do this : player.body.collides(groundGroup);ground.body.collides(playerGroup);So here is the issue : if I put just one of these line, nothing happens. Isn't it enough to tell one body or the other to collide? It seems redundant to me. If that's the way it is, I'll deal with it, but I want to be sure I'm not making any mistake here Thanks