TrinityCore Posted November 19, 2016 Share Posted November 19, 2016 Hello guys! I must mention that I am new, and that I am Latin, so sorry for my English. Okay.. my question is the following. How to collision normal image and polygonal image.? What a clash with each other. In short, that's what I need to know. I hope you can help me, thank you all!. Link to comment Share on other sites More sharing options...
CharlesCraft50 Posted November 22, 2016 Share Posted November 22, 2016 If you want to just check if the normal image overlap or touch to the polygonal image without physics you can use this function: function checkOverlap(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB); } function update() { if(checkOverlap(normalImage, polygonalImage)) { //do something... normalImage.destroy(); } } But if you want to use physics on it you can use: game.physics.arcade.collide(normalImage, polygonalImage, function(){normalImage.destroy();}); I don't really know what you mean, can you explain it a little bit? CodeSpeed101 1 Link to comment Share on other sites More sharing options...
TrinityCore Posted November 23, 2016 Author Share Posted November 23, 2016 On 22/11/2016 at 8:07 AM, CharlesCraft50 said: I'm sorry I did not explain myself better. What I try is that the player can not pass over the polygonal house Link to comment Share on other sites More sharing options...
CharlesCraft50 Posted November 23, 2016 Share Posted November 23, 2016 Maybe you forgot to enable their physics, Try to enable it: player = game.add.sprite(0, 0, 'sprite'); game.physics.arcade.enable(player); polygonalImage = game.add.sprite(20, 0, 'sprite'); game.physics.arcade.enable(polygonalImage); If you already enabled it and still didn't work, just paste your whole code in this link so I can recognize what is the problem in your code:https://gist.github.com/ or https://jsfiddle.net/ Don't forget to send the link of your code. CodeSpeed101 1 Link to comment Share on other sites More sharing options...
TrinityCore Posted November 23, 2016 Author Share Posted November 23, 2016 8 hours ago, CharlesCraft50 said: If you already enabled it and still didn't work, just paste your whole code in this link so I can recognize what is the problem in your code: https://gist.github.com/ or https://jsfiddle.net/ Don't forget to send the link of your code. Thank you, it has served me. But another doubt ... How to immovable polygon image? house.body.immovable = true; -> It does not work, the house goes flying Link to comment Share on other sites More sharing options...
CharlesCraft50 Posted November 24, 2016 Share Posted November 24, 2016 @dami5200 Try this: house.body.immovable = true; house.body.moves = false; CodeSpeed101 1 Link to comment Share on other sites More sharing options...
TrinityCore Posted November 24, 2016 Author Share Posted November 24, 2016 10 hours ago, CharlesCraft50 said: @dami5200 Try this: house.body.immovable = true; house.body.moves = false; Does not work... var controles; Level2 = { preload: function(){ game.load.spritesheet("player", "../images/characters/char1.png", 32, 48); game.load.image("casa", "../images/casa.png"); game.load.physics("casajson", "../images/casa.json"); }, create: function(){ game.physics.startSystem(Phaser.Physics.P2JS); casa = game.add.sprite(500, 200, "casa"); player = game.add.sprite(200, 200, "player"); game.physics.p2.enable([player, casa], true); casa.body.clearShapes(); casa.body.loadPolygon('casajson', 'casa'); casa.body.immovable = true; casa.body.moves = false; //game.physics.arcade.enable(player); controles = game.input.keyboard.createCursorKeys(); }, update: function(){ player.body.velocity.x = 0; // Condiciones de movimientos. if(controles.left.isDown){ player.body.velocity.x = -200; player.animations.play("left"); PlayerFrame = 7; }else if(controles.right.isDown){ player.body.velocity.x = 200; player.animations.play("right"); PlayerFrame = 6; }else{ player.body.velocity.x = 0; player.animations.stop(); player.frame = PlayerFrame; } } } Here is the image: image Link to comment Share on other sites More sharing options...
CharlesCraft50 Posted November 25, 2016 Share Posted November 25, 2016 @dami5200 Oh, remove the immovable and moves in your code because it is only for arcade, you choose what you want in this code, this code is for p2 physics which you are using: //To make it immovable: casa.body.static = true; //If you just want to ignore the gravity, use this: casa.body.data.gravityScale= 0; //With this, the body can't be moved by any other bodies: casa.body.kinematic = true; Like thi TrinityCore 1 Link to comment Share on other sites More sharing options...
TrinityCore Posted November 26, 2016 Author Share Posted November 26, 2016 On 25/11/2016 at 7:16 AM, CharlesCraft50 said: @dami5200 Oh, remove the immovable and moves in your code because it is only for arcade, you choose what you want in this code, this code is for p2 physics which you are using: //To make it immovable: casa.body.static = true; //If you just want to ignore the gravity, use this: casa.body.data.gravityScale= 0; //With this, the body can't be moved by any other bodies: casa.body.kinematic = true; Like thi Perfect, so far the truth that everything works well. Now, how to do so that the player does not turn when hitting the house? before: Before collision of the element After: After collision of the element And also to remove those lines and the color of the elements. And really thank you for answering my questions, which have helped me a lot! Link to comment Share on other sites More sharing options...
CharlesCraft50 Posted November 27, 2016 Share Posted November 27, 2016 @dami5200 You can use this to fix the rotation: casa.body.fixedRotation = true To remove the lines, just change the second param into false in p2 enable: game.physics.p2.enable([player, casa], false); TrinityCore 1 Link to comment Share on other sites More sharing options...
TrinityCore Posted November 27, 2016 Author Share Posted November 27, 2016 9 hours ago, CharlesCraft50 said: @dami5200 You can use this to fix the rotation: casa.body.fixedRotation = true To remove the lines, just change the second param into false in p2 enable: game.physics.p2.enable([player, casa], false); Thank you very much for everything, you have helped me a lot. CharlesCraft50 1 Link to comment Share on other sites More sharing options...
Recommended Posts