Jump to content

TrinityCore
 Share

Recommended Posts

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

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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

@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;

 

Link to comment
Share on other sites

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;

 

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...