Jump to content

Search the Community

Showing results for tags 'overlap'.

  • 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

  1. Hi, I am working on my first 2D game with phaser 3. I have set up vscode with node https server and running it to deploy the game on localhost. While the game gets compiled successfully and deployed I get a run time error when executing the collider and overlap function. For the time being I have a title screen with "welcome to my game" text and it is clickable. One you click that you are navigating to play scene. When naigating to play scene I am getting the error displayed in the following scrren shot. I suspect that this is caused by 'this' keyword and the scope of it. But I have no idea how to fix that. I spent 2-3 hours debugging and playing with 'this.' here and there but I am still clueless as to how I can fix this and what I did wrong. I have added my code below as well. Any help will be greatly appriciated. The comment " //Error on "is parent undefined" " is added to mark the lines I get the error. import Phaser from 'phaser'; class PlayScene extends Phaser.Scene { constructor() { super('PlayScene'); } create() { var player; var stars; var bombs; var bomb; var platforms; var cursors; var score = 0; var gameOver = false; var gameOverText; var scoreText; var leftKey; var rightKey; var upKey; var repeatStarCount; this.add.image(400, 300, 'sky'); platforms = this.physics.add.staticGroup(); platforms.create(390, 568, 'ground1'); platforms.create(750, 200, 'ground2'); platforms.create(0, 150, 'ground4'); platforms.create(690, 420, 'ground4'); platforms.create(100, 320, 'ground4'); player = this.physics.add.sprite(100, 450, 'dude'); player.setBounce(0.2); player.setCollideWorldBounds(true); player.setScale(0.15); player.setSize(300, 400, false); player.body.offset.y = 0; player.body.offset.x = 0; // Input Events this.cursors = this.input.keyboard.createCursorKeys(); this.leftKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT); this.rightKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT); this.upKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP); // player animations this.anims.create({ key: 'LeftRun', frames: this.anims.generateFrameNumbers('dude', { start: 14, end: 17 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'LeftJump', frames: [{ key: 'dude', frame: 13 }], frameRate: 10, repeat: -1 }); this.anims.create({ key: 'LeftIdle', frames: this.anims.generateFrameNumbers('dude', { start: 9, end: 10 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'LeftDizzy', frames: this.anims.generateFrameNumbers('dude', { start: 10, end: 11 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'RightRun', frames: this.anims.generateFrameNumbers('dude', { start: 5, end: 8 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'RightJump', frames: [{ key: 'dude', frame: 4 }], frameRate: 10, repeat: -1 }); this.anims.create({ key: 'RightIdle', frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 1 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'RighttDizzy', frames: this.anims.generateFrameNumbers('dude', { start: 2, end: 3 }), frameRate: 10, repeat: -1 }); // Some stars to collect, 12 in total, evenly spaced 70 pixels apart along the x axis repeatStarCount = 10; this.stars = this.physics.add.group({ key: 'star', repeat: repeatStarCount, setXY: { x: 8, y: 0, stepX: 50 }, setScale: { x: 0.05, y: 0.05 } }); this.stars.children.iterate(function(child) { child.setBounceY(Phaser.Math.FloatBetween(0.4, 0.8)); }); this.bombs = this.physics.add.group(); var style = { font: "30px Arial", fill: "#ffff00", stroke: "#535353", align: "center", strokeThickness: 15, }; var style1 = { font: "40px Arial", fill: "#ffff00", stroke: "#535353", align: "center", strokeThickness: 15, }; scoreText = this.add.text(0, 0, "Score: 0", style); gameOverText = this.add.text(300, 250, "Game Over", style1); gameOverText.visible = false; // Collide the player and the stars with the platforms this.physics.add.collider(player, platforms); this.physics.add.collider(stars, platforms); this.physics.add.collider(bombs, platforms); //Error on "is parent undefined" this.physics.add.overlap(player, stars, () => { star.disableBody(true, true); // Add and update the score score += 10; scoreText.setText('Score: ' + score); if (stars.countActive(true) === 0) { repeatStarCount = +3; // A new batch of stars to collect stars.children.iterate(function(child) { child.enableBody(true, child.x, 0, true, true); }); var x = (player.x < 400) ? Phaser.Math.Between(400, 800) : Phaser.Math.Between(0, 400); var bomb = bombs.create(x, 16, 'bomb'); bomb.setBounce(1); bomb.setCollideWorldBounds(true); bomb.setVelocity(Phaser.Math.Between(-200, 200), 20); bomb.allowGravity = false; } }, null, this); //Error on "is parent undefined" this.physics.add.collider(player, bombs, () => { this.physics.pause(); if (player.anims.currentAnim.key === 'RightRun' || player.anims.currentAnim.key === 'RightIdle' || player.anims.currentAnim.key === 'RightJump') { player.anims.play('RighttDizzy'); } if (player.anims.currentAnim.key === 'LeftRun' || player.anims.currentAnim.key === 'LeftIdle' || player.anims.currentAnim.key === 'LeftJump') { player.anims.play('LeftDizzy'); } gameOver = true; let timer = this.time.delayedCall(500, () => { player.anims.stop(); gameOverText.visible = true; }, [], this); }, null, this); } update() { if (this.gameOver) { return; } if (this.cursors.left.isDown) { player.setVelocityX(-160); player.anims.play('LeftRun', true); } else if (this.cursors.right.isDown) { player.setVelocityX(160); player.anims.play('RightRun', true); } else if (Phaser.Input.Keyboard.JustUp(this.leftKey)) { player.setVelocityX(0); player.anims.play('LeftIdle', true); } else if (Phaser.Input.Keyboard.JustUp(this.rightKey)) { player.setVelocityX(0); player.anims.play('RightIdle', true); } else if (Phaser.Input.Keyboard.JustUp(this.upKey) && player.anims.currentAnim != null) { if (player.anims.currentAnim.key === 'LeftJump') { player.anims.play('LeftIdle', true); } if (player.anims.currentAnim.key === 'RightJump') { player.anims.play('RightIdle', true); } } else if (this.cursors.up.isDown && player.anims.currentAnim != null) { if (player.anims.currentAnim.key === 'RightIdle') { player.anims.play('RightJump', true); if (player.body.touching.down) { player.setVelocityY(-350); } } if (player.anims.currentAnim.key === 'LeftIdle') { player.anims.play('LeftJump', true); if (player.body.touching.down) { player.setVelocityY(-350); } } } } } export default PlayScene;
  2. Hi All, I'm new to phaser (using phaser 3.50.1) and trying to generate random objects around the level. The problem is I don't want these objects to be spawned over on the tilemapLayer tiles. Attached is an image of the stars spawning over the tiles. Before I added the tileMap, I was using this.physics.add.staticGroup(); with that I was able to check on the overlap with the walls in my method to add stars. this.scene.physics.overlap(walls, star) Now, with the tileset, I'm passing the tileMapLayer, but overlap is not detecting the tiles (picture, line 29) How is the correct way to check for collisions/overlaps for tileMaps ?
  3. I have this code: scene.physics.add.overlap(spears.children.entries[numberOfSpearThrowerMachines], platforms, stopSpear, null, this); function stopSpear(number) { spears.children.entries[number].setVelocityX(0); } I am trying to send a parameter to the function stopSpear when calling it. Like this: scene.physics.add.overlap(spears.children.entries[numberOfSpearThrowerMachines], platforms, stopSpear(numberOfSpearThrowerMachines), null, this); but this does not work obviously, so how do I do it instead?
  4. I have an endless runner with flies that are enemies flying towards the player. The player jumps into the air and onto the top of the fly to kill it. I would like to enable gravity on the fly on overlap so that it falls to the ground when it dies. However, my problem is that when the fly falls sometimes it overlaps with the player sprite on decent causing the overlapCallback function (killFlies) to be called more than once. How can I have an enemy sprite like this die and adhere to gravity yet not have the overlapCallback function triggered again when it's falling? Any ideas? Is there any way to disable overlap once the overlap occurs? Setting fly.body.enable = false won't work as I then can't set velocity or gravity on the fly sprite when it dies. Please see my overlapCallback function below. Any suggestions would be much appreciated (am new to Phaser). killFlies: function(player, fly){ if (player.body.touching.down) { this.bounce(); //fly.body.enable = false; fly.body.allowGravity = true; this.stompSound.play(); fly.animations.play('die').onComplete.addOnce(function () { fly.kill(); }, this); }else { this.gameOver(); } fly.body.touching = fly.body.wasTouching; },
  5. A collider collides only with set tiles on a tilemap. However, if you are using an overlap with a tilemap, it always callbacks. If you log the index of the Tile, it's 0. So "no set tile". Is that intended behavior?
  6. See updates in below comments I made a collider: this normally works. But however this time it doesn't. There is a collider which lets the player colliding with (this) object. when I move the player on the object, the collideCB is triggered. But there is no collision. Even in debug mode for arcade physics, I can see the body. But they are not colliding, just overlapping. Anyone has an idea why? body: this.scene.physics.world.enable(this); this.setOrigin(0, 0); this.body.setSize(8, 8, false); this.body.setImmovable(true); this.body.allowGravity = false; colliding code: this.scene.physics.add.collider(this.scene.config.player, this, collideCB, () => { return this.getData('active'); }, this) (...) collideCB() { console.log('working') } Also, the debug information seems to clearly address both sprites, that should collide. but it does not collide and the callback is fired. ALl other collisions are working. (attached screenshot)
  7. Hello, If I have a tilemap with a dynamic layer, a player with collisions enabled with this layer - how do I manually check whether the player is overlapping specific tile? I try this way: scene.physics.world.enable(player); scene.physics.add.collider(player, layer); ... var tile = layer.getTileAtWorldXY(Xpos, Ypos, true); console.log(scene.physics.world.overlap(player, tile)); .. but I always get False printed, even if selected tile is right behind the player. Same result with calling collide(), same result if tile's index is -1 or something else. What am I missing?
  8. I'm using a callback function on the overlap method, but it's firing at the wrong time. After a bit of calculation/trial and error I worked out that it is firing where the sprite would have been if the scrollFactor of the sprite was the default setting of 1. I assume this is a bug? See demo on jsFiddle. Update: it also ignores the objects origin and assumes its origin is the default 0.5. I've updated the demo. Update 2: I'm now fairly certain this is not expected behaviour, so I've raised an issue on GitHub. Thanks, Josh
  9. Hi, I hope that I find you well, I am a little stuck. I have a group of sprites, that on overlap of another jump sprite image, I require it to play the jump animation, but only on the individual sprite within the group, when it has overlapped. My code, is pretty much working how I want apart from this issue, in the current build, on overlap the animation will play for all sprites within the group (not an individual basis), and will trigger again (beyond the original, overlap) if another sprite hits the jump image. Appreciate any assistance. var game; var globalParams = { calculatedWidth: 1350, calculatedHeight: 900 } var GameResolution = { _1350: 1350, _960: 960 }; function calculateSize() { // Get Pixel Width and Height of the available space var w_w = window.innerWidth * window.devicePixelRatio; var w_h = window.innerHeight * window.devicePixelRatio; var g_w = w_w; // We prepared all assets according to aspect ratio of 1.5 // Since we are going to use different assets for different resolutions, we are not looking at the resolution here var originalAspectRatio = 1.5; // Get the actual device aspect ratio var currentAspectRatio = g_w / w_h; if (currentAspectRatio > originalAspectRatio) { // If actual aspect ratio is greater than the game aspect ratio, then we have horizontal padding // In order to get the correct resolution of the asset we need to look at the height here // We planned for 1350x900 and 960x640 so if height is greater than 640 we pick higher resolution else lower resolution if(w_h > 640){ globalParams.selectedResolution = GameResolution._1350; globalParams.calculatedHeight = 900; globalParams.calculatedWidth = w_w * (900 / w_h); } else { globalParams.selectedResolution = GameResolution._960; globalParams.calculatedHeight = 640; globalParams.calculatedWidth = w_w * (640 / w_h); } } else { // If actual aspect ratio is less than the game aspect ratio, then we have vertical padding // In order to get the correct resolution of the asset we need to look at the width here if(w_w > 960){ globalParams.selectedResolution = GameResolution._1350; globalParams.calculatedWidth = 1350; globalParams.calculatedHeight = w_h * (1350 / w_w); } else { globalParams.selectedResolution = GameResolution._960; globalParams.calculatedWidth = 960; globalParams.calculatedHeight = w_h * (960 / w_w); } } } window.onload = function () { calculateSize(); game = new Phaser.Game(globalParams.calculatedWidth, globalParams.calculatedHeight, Phaser.AUTO, 'gameDiv'); game.state.add('main', mainState); game.state.start('main'); //game.forceSingleUpdate = true; } var yourGroup; var mainState = { preload: function() { if(!game.device.desktop) { game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; game.scale.setMinMax(game.width/2, game.height/2, game.width, game.height); } game.scale.pageAlignHorizontally = true; game.scale.pageAlignVertically = true; // Background game.stage.backgroundColor = '#71c5cf'; // Horse Sprites for (var i = 1; i <= 3; i++) { this.load.spritesheet('runner'+i, 'assets/horse-'+i+'.png', 368, 300); } // Other Sprites game.load.image('fence', 'assets/jumpfence1.png'); game.load.image('track', 'assets/grasstrack1.png'); }, create: function() { this.jumpGroup = game.add.group(); this.timer = game.time.events.loop(12000, this.addNewJump, this); this.horseGroup = game.add.group(); this.horseGroup.enableBody = true; this.horseGroup.physicsBodyType = Phaser.Physics.ARCADE; this.addHorse(this); }, addHorse: function() { for (var i = 1; i <= 3; i++) { var posY = game.rnd.integerInRange(300, 500); var posX = game.rnd.integerInRange(30, 120); geegee = this.horseGroup.create(posX, posY, 'runner'+i); // Add 'sprite' to the group this.horseGroup.sort('y', Phaser.Group.SORT_ASCENDING); geegee.animations.add('gallop', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 20, true); geegee.animations.add('jump', [4, 11, 12, 13, 14, 15, 16, 17, 4], 14, false); } }, addJump: function(x, y) { var fence = game.add.sprite(x, y, 'fence'); this.jumpGroup.add(fence); game.physics.arcade.enable(fence); fence.body.setSize(50, 350, 105, 0); fence.body.velocity.x = -500; fence.checkWorldBounds = true; fence.outOfBoundsKill = true; }, addNewJump: function() { this.addJump(game.world.width - 40, this.game.height - this.game.cache.getImage('fence').height); }, update: function() { this.horseGroup.forEach(function(item) { // jump fences this.game.physics.arcade.overlap(this.horseGroup, this.jumpGroup, this.fenceJump, null, this); this.hurdle(); // move up and down field if (item.x > game.width - 650) { item.x = game.width - 650; item.body.velocity.x += game.rnd.integerInRange(-5, 0); } else { item.body.velocity.x += game.rnd.integerInRange(-5, 5); } if (item.x < 50) { item.x = 50; item.body.velocity.x = 0; } }.bind(this)); }, fenceJump: function(horseGroup,jumpGroup) { this.horseGroup.forEach(function(item) { item.body.velocity.y = 1; hurdleFence=false; }.bind(this)); }, hurdle: function() { this.horseGroup.forEach(function(item) { if(!this.hurdleFence){ //check if we already have -50 gravity or not if(item.body.velocity.y > 0){ item.events.onAnimationStart.add(airJump, this); function airJump() { item.body.velocity.x = 5; item.body.gravity.x = 100; } item.animations.play('jump'); item.events.onAnimationComplete.add(groundGallop, this); function groundGallop() { item.body.velocity.y = 0; } } else { item.animations.play('gallop'); } } }.bind(this)); }, };
  10. Hi, When we use a tilemap we are able to create callbacks to execute something when overlap/collision happens, with: layer.setTileIndexCallback(5, myFunction, this); But how do I execute something when I leave these specific tiles with ID 5 ?
  11. Hello everyone! I've been a lurker on this site for most of the time and the threads here helped me time and time again to sort things out. I'm currently trying to get a simple Jump'n'Run Game going, but I'm struggling with the collectibles. I'm using a Tiled Object Layer and imported it succesfully into the game. However, the overlap between the objects and the player just isn't working. I've tested the collectPoint1 function on another object and it worked. Also the sprites are all visible in my game. Really, the only problem is the overlap. class Level extends Phaser.Scene { constructor(){ super({ key: 'Level' }); }; create(){ let scene = this; let map = this.make.tilemap({ key: 'Level1'}); let player1_config = {...}; //Player 1 this.player1 = new Player1(this, player1_config); //Setting the score-data this.data.set('player1Score',0); //Animation of the Coins var coinSpin_config = { key: 'spin', frames: this.anims.generateFrameNumbers('coin', { start: 0, end: 7 }), frameRate: 10, repeat: -1 }; this.anims.create(coinSpin_config); //Using createFromObjects to display the coins this.points = map.createFromObjects('HousePoints', 'point', {key: 'coin'}, this); this.points.enableBody = true; this.anims.play('spin', this.points); //Score-text this.scoreText = this.add.text(30, 22, 'Score for ' + this.playerHouse + ': 0'); this.scoreText.setScrollFactor(0); }; //Collecting Points collectPoint1 (player, coin){ var score = this.data.get('player1Score'); this.data.set('player1Score', score + 10); this.scoreText.setText('Score: ' + this.data.get('player1Score')); coin.disableBody(); } update(){ this.player1.move(); this.physics.add.overlap(this.player1, this.points, this.collectPoint1, null, this); } } } As I'm well aware of this post, I've tried it with map.getObjectLayer as well. Didn't work. I'm a huge fan of this template, but its structure is so very different to mine that it down't really help me. . . . . this.housePoints = this.add.group(null); const objects = map.getObjectLayer('HousePoints'); let housePoints_config = { scene: this, collected: false } objects.objects.forEach( (point) => { //Creates a Points Object defined in a Points class (see below) point = new Points(this, housePoints_config); this.housePoints.add(point); }); . . . . . } update(){ this.player1.move(); //This throws the error 'spin is not a function', but that's not my focus this.housePoints.spin(); //This overlap doesn't work either this.physics.add.overlap(this.player1, this.housePoints, this.collectPoint1, null, this); } } ///////////////////////////////////////////// ///This is in another .js file naturally//// /////////////////////////////////////////// class Points extends Phaser.Physics.Arcade.Sprite { constructor(scene, config) { super(config.scene, config.x, config.y); config.scene.physics.world.enable(this); this.scene = config.scene; this.collected = config.collected; this.scene.add.existing(this); this.scene.physics.world.enable(this); var coinSpin_config = { key: 'spin', frames: this.anims.generateFrameNumbers('coin', { start: 0, end: 7 }), frameRate: 10, repeat: -1 }; this.anims.create(coinSpin_config); } spin(){ this.anims.play('spin', true); console.log('point updated'); } } I'd be eternally thankful for every tip! Thanks so much, if you decide to take the time to help me.
  12. Hello, Just a quick question. I want to kill any emitter particles that overlap with a sprite. I've tried: if(this.game.physics.arcade.overlap(this.emitter, this.sprite)) { this.emitter.removeChildAt(0); //and this.emitter.removeChild(); }
  13. Hello, I am making an arena shooter multiplayer game with destroyable obstacles. You can see a pre-alpha here: http://mechsgame.s3-website.eu-west-2.amazonaws.com I have encountered a problem I'm not sure on how to proceed on and I surprisingly couldn't find any information on similar issues. My game will have tall walls and other obstacles which can potentially cover the player's character. I would like to make an effect similar to RTS games, where an outline or a shadow of the player is visible on top of the obstacle. See the below picture to get an idea of what I mean. My player container contains several sprites. I have a few ideas on how to do this, but I do not think they are optimal. One is rendering the player container to a texture and using that a mask for potential overlapping obstacles, along with a filter. Secondly is just placing a simple GUI marker that shows where the player character is. In both cases, I am unsure on how to detect overlapping sprites. Is there an established solution for such cases? Thanks!
  14. Hello, i have this code that should create in the create function if one of the sprites of the "asteroids" group is overlapping the station (so the player doesnt get instant killed when he spawn). It is working in the Asteroid.prototype.update function but to optimize the game i would like to check it in the create function. this.asteroids.forEach(function (item) { if (Phaser.Rectangle.intersects(this.station.getBounds(), item.getBounds())) { item.destroy(); } }, this); It isnt working as exepted, could soweone help me ?
  15. Hi, i'm currently woriking on a litle Phaser side scroller. My problem is, my player can jump on items such as stars, and other things. I tried it with arcade.overlap like this: if (cursors.up.isDown && player1.body.touching.down && !game.physics.arcade.overlap(player1, stars)) { player1.body.velocity.y = -700; } But it didn't work for some reason... I didn't get any errors, but I can still jump on the stars. Does somebody have a solution for this?
  16. I'm trying to add some collectable coins : for(var i=0; i < coins.length; i++){ game.physics.arcade.overlap(coins[i].getSprite(), myPlayer.getSprite(), collectCoin, null, this); } Problem, in my callback function, I need to access to "coins", not only to his attached sprite, what can I do ? function collectCoin(coin, player){ coin.killCoin(); // play a "death animation" and destroy itself after 0.4s }
  17. I'm working on an action game where the player can touch certain switch tiles to turn other enemies off and back on. So the way it is supposed to work is like this: 1. The player overlaps a switch tile 2. Execute the switch action only once 3. Ignore further overlapping with that tile until player moves off 4. When player moves off the switch should wait for the next overlap 5. Repeat from step 1 when player overlaps again I'm using arcade physics and the overlap function and it's working.. sort of. The problem is, the overlap keeps firing over and over again. What would be the best way in Phaser to get the desired result? See screenshot below of what I mean, and I've created a sandox of my code example here: https://phaser.io/sandbox/edit/zEVOQfgA
  18. Hi guys, just a quick question. I'm trying to detect overlap between emitter particles and a group like so: create: function() { this.emitter = this.game.add.emitter(0, 0, 1000); this.emitter.enableBody = true; this.emitter.makeParticles('whiteParticle'); this.emitter.minParticleSpeed.setTo(100); this.emitter.maxParticleSpeed.setTo(800); this.emitter.gravity = 50; this.emitter.maxParticleScale = 3; this.emitter.minParticleScale = 0.1; this.emitter.setYSpeed(-150, 150); this.emitter.flow(1500, 100, 100, -1, false); //lifespan, frequency, quantity, total, immediate this.emitter.checkWorldBounds = true; this.emitter.outOfBoundsKill = true; this.fire = this.game.add.group(); this.fire.enableBody = true; this.fire3 = this.game.add.sprite(1423, 500, 'fireL3'); this.fire2 = this.game.add.sprite(1423, 500, 'fireL2'); this.fire1 = this.game.add.sprite(1423, 500, 'fireL1'); this.fire.add(this.fire3); this.fire.add(this.fire2); this.fire.add(this.fire1); }, update: function(){ this.game.physics.arcade.overlap(this.emitter, this.fire, this.damageFire, null, this); } damageFire: function(){ console.log('fire damaged!'); }, I can get this to work fine if I check for overlap between 2 sprites/groups, but I cannot get it to work for the emitter. Could anyone point me in the right direction? Thanks
  19. Hello Phasers, I'm new to Phaser and I'm starting to have fun with it. But I have an issue with collision using Arcade physics. The problem is that when a collision happens between two bodies, the collision make them overlap a little bit and at some point the bodies pass through each other as you can see in this example. Adding the property bounce = 0 to the line body solve part of the problem. But their is style a slight overlap. Can somebody explain me what's happening and give me a solution to the problem ? Thanks.
  20. I'm currently making my first ever game and am fairly new to coding so I apologize if this code doesn't make much sense. In my game the player sprite changes with the collection of various items. When a certain item is collected I want it so that the score increases when the player is in a certain zone and decreases when the player is out of that zone all while the player sprite is that specific model, and then I want the score to decrease if the player is in that zone while the sprite model isn't correct. (Sorry if that doesn't make sense!) Here is what I have so far: //in the update function: game.physics.arcade.overlap(player, laneC, laneCScoreModifier, null, this); //outside update function: function laneCScoreModifier (player, lane) { if (player.key == 'heroc') { timer = setInterval(plusScore, 1000); if (! game.physics.arcade.overlap(player, laneC)){ clearInterval(timer); } } else { timer = setInterval(minusScore, 1000); if (player.key == 'heroc') { clearInterval(timer); timer = setInterval(plusScore, 1000); if (!game.physics.arcade.overlap(player, laneC)){ clearInterval(timer); } } } } function plusScore(){ score++; } function minusScore(){ score--; } So my first guess is the '!' modifier isn't doing anything there. When I run the game once the player enters the zone while not having the correct sprite the timer never stops, even if they leave. Anyone have any idea how I should approach this? Any help will be greatly appreciated!
  21. I want to check how much of my second sprite is overlapped with first sprite in callback function,so that i can determine if the overlap is enough for(% of overlapping) for further process.But when i check that with overlapY/overlapX .i am getting 0 always .Please help.
  22. Hi, in my finished game I've found a thing, that slows my game from 60 to 30 fps. Too many collisions handlers. Well I need them to control whole game, to call all essentiall functions, but they are sloooooowing game drastically. game.physics.arcade.collide(bullets, layer, resetBullet); game.physics.arcade.collide(grenades, layer, resetBullet); game.physics.arcade.collide(ebullets, layer, resetBullet); game.physics.arcade.collide(chest3, chest5, chesting); game.physics.arcade.overlap(bullets, ebullets, resetBullet); It's for bullets to destroy chests, bullets with themselves and chest with chest. If I delete this, FPS goes from 30 to 60. But I need this. How can I do it? It's interesting, because the bullets aren't even created and they are slowing game. I have much more collision handlers, for every object to collide with layers and with all other objects like player, bullet, chest, another bullet, enemy bullet etc... Full code of game is avaiable here: redplanetgame.prv.pl
  23. Hi friends. I want to activate a function when two objects overlap. For example when I overlap an object I want to change gravity of a specific area. I can do this with overlap but it does it for one time, after that everything is same again. For example in the game, I will overlap a potion and gravity between position x1 and x2 will be equal -50. But when I do this, I mean when I overlap the potion, it occurs for one second and after that the gravity -50 turns back its past value.
  24. Hi, I would like to know if it is possible to create a function which asks if a sprite (playerA) overlaps with an object from a JSON tilemap without sprite? If my playerA overlaps this invisible object a function would be started. I already tried the overlap function between two sprites and it worked: function onDragStop(sprite, pointer) { if (checkOverlap(playerA,sprite)){ console.log("Overlap!"); } else { console.log("Dropped"); } function checkOverlap(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB); } Here is an extract of the JSON tilemap. { "height":10, "layers":[ { "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "height":10, "name":"Calque de Tile 1", "opacity":1, "type":"tilelayer", "visible":true, "width":20, "x":0, "y":0 }, { "image":"..\/world.png", "name":"World base", "opacity":1, "type":"imagelayer", "visible":true, "x":0, "y":0 }, { "draworder":"topdown", "name":"First Object", "objects":[ { "gid":1, "height":64, "id":5, "name":"", "rotation":0, "type":"", "visible":true, "width":64, "x":317.52500448109, "y":195.111668757842 }], "opacity":1, "type":"objectgroup", "visible":true, "x":0, "y":0 }, { "draworder":"topdown", "name":"Second Object", "objects":[ { "gid":1, "height":64, "id":11, "name":"", "rotation":0, "type":"", "visible":true, "width":64, "x":449.212619275898, "y":193.621695658129 }], "opacity":1, "type":"objectgroup", "visible":true, "x":0, "y":0 }, And I would like to play a sound when the player overlaps an object, and each object would have a different effect. And then I don't know how to specificaly call one object and check if it's overlaping with the player. objects = game.add.group(); objects.enableBody=true; game.load.tilemap('world',"assets/map/world.json",null,Phaser.Tilemap.TILED_JSON); game.load.image('tileset',"assets/world.png"); world = this.add.tilemap('world'); world.addTilesetImage('tileset','tileset'); layer = world.createLayer('Calque de Tile 1'); layer.resizeWorld(); world.createFromObjects('First Object',1,'',0,true,false,objects); I don't knwo if these parts of code are enough to understand what I would like to do? I don't know where to get the informations and documentation about that =/ Any information is welcomed ^^.
  25. Hi everyone, I am new to Phaser framework and it's great! I have made a lot of progress on this Street Fighter game I am doing. A little background of my problem: I have my code set up that when I press W (Medium Punch), I increase the width of the sprite by via setRectangle playerKen.body.setRectangle(70, 80, -18); once I expanded the hitbox , I play the sprite, then set the width back to its original size once the animation has finished playing: kenAnimation = playerKen.animations.play('standingMediumPunch', 10, false).onComplete.add(function () { //reset the graphics back playerKen.body.setRectangle(35, 80, -18); playerKen.body.setCollisionGroup(kenCollisionGroup); playerKen.body.collides(mBisonCollisionGroup, hitEnemy, this); kenAttacking = false; playerKen.body.velocity.x = 0; playerKen.animations.play('standing', 7, true); playerKen.body.static = false; //console.log('punching'); }, this); I have also programmed the AI too, won't get into that. But my issue is the overlapping hitboxes. See the attached photo... When a situation like this occurs when I am punching and the AI is punching as well, the health of the player and the AI does not decrease. I looked into https://phaser.io/examples/v2/sprites/overlap-without-physics but the getBounds() method only gets the width of the sprite, not the hitbox. How can I see whether the two hitboxes have intersected? By the way, I am using p2 physics. Thanks a bunch!
×
×
  • Create New...