Jump to content

Child sprites updating too late


Recommended Posts


when I move parent, child position is updated too late, how to manually force to update child position when I move parent?


in my game I have a group of sprite objects (Ships)

this.shipsGroup = game.add.group();

Each Ship before adding to this.shipsGroup have two other groups as children :

var actualShip = game.add.group();
var surrounding = game.add.group();

for (var m = 0; m < 3; m++) {
	var temp = game.add.sprite(-halfSize - 50 + l*50, tempy, 'red');
	if(m == 1 && l > 0 && l < ship.unitSize+1) {
	} else {



Note: every child object has position relative to parent (so child position (0,0) is on parent)

Everything is fine up to this point. I'm moving my ships using something like that in every possible direction (I'm moving them on 50x50grid). This check is in update method of game.

if(this.draggedShip.position.x - game.input.mousePointer.x >= 50 && some_boundary_condition) {

So, after my ship has moved to next grid, I'm calling checkOverlap function to check on top of which grid fields actually is the ship. (I have seperate group of sprites for each grid field)

checkOverlap: function() {
	for (var i = 0; i < this.draggedShip.children[0].length; i++) {
		for(var j = 0; j < this.fieldsGroup.children.length; j++) {
			if(this.draggedShip.children[0].children[i].overlap(this.fieldsGroup.children[j])) {
					this.fieldsGroup.children[j].alpha = 1;

What is wrong :
it looks like sprite.overlap uses OLD children positions (before parent move). So when I move my ship 1 field to the left, the result of this checkOverlap function are fields where the ship was in previous step.

How it should be:
children positions should be updated before my checkOverlap call. How can I force to do it? I was trying to call update on childrens but it didn't work.

Phaser 2.6.2

Link to comment
Share on other sites


  • Recently Browsing   0 members

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