Jump to content

Sprite Collision Detection in Phaser v2


Recommended Posts

Hi Folks,


I am new to Phaser framework. I have 6 sprites which are draggables. The codebase is as under:

var circle = game.add.sprite(64.0, 55.0, "circle");circle.anchor.setTo(0.5, 0.5);var triangle = game.add.sprite(151.3, 55.3, "triangle");triangle.anchor.setTo(0.5, 0.5);var box = game.add.sprite(63.15, 118.55, "box");box.anchor.setTo(0.5, 0.5);var penta = game.add.sprite(151.25, 122.9, "penta");penta.anchor.setTo(0.5, 0.5);var plus = game.add.sprite(62.95, 179.25, "plus");plus.anchor.setTo(0.5, 0.5);var rect = game.add.sprite(151.4, 182.9, "rect");rect.anchor.setTo(0.5, 0.5);		var arrItem = new Array(circle, triangle, box, penta, plus, rect);		for (var i = 0; i < arrItem.length; i++) {	var oItem = arrItem[i];	oItem.inputEnabled = true;				oItem.input.enableDrag(false, true);	oItem.events.onDragStart.add(player.onItemDragStart,this);	oItem.events.onDragStop.add(player.onItemDragStop,this);}

And the droppables code are as under:

for (var i = 0; i < currentDesign.shape.length; i++) {	var shape = currentDesign.shape[i];	var aShape = game.add.sprite(shape.x, shape.y, "circle");	shape.inputEnabled = true;	aShape.anchor.setTo(0.5, 0.5);	player.members.arrDesignItems.push(aShape);}

How to do collision detection? Please guide step by step.




Duke Ranjan 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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