addSceneObject not running moveTo
MaineMathMan

Hi, I have a simple shooter game in the works. There is a gun site that follows the mouse and a plane to shoot.
Plane code for addToScene that works great

var sw=wade.getScreenWidth();
var sh=wade.getScreenHeight();

this.setPosition(-sw/2+150, 0);
this.moveTo(sw/2, 50, 100);

Gun scope code on click
 

var shots = this.getOverlappingObjects();
for (var i=0; i<shots.length; i++)
    {
        if (shots[i].isEnemy)
            {
                wade.removeSceneObject(shots[i]);
                break;
            }
    }
setTimeout(function() {
            wade.addSceneObject(shots[i]);
               }, 1000);

What works: The plane flies across the screen, the gun scope moves with cursor, on click the plane is removed, the plane is added back to the screen a second later..... but doesn't move.. the moveTo doesn't work when added back to the screen

All 2 Comments
Gio

Hi

I think this may very well be a bug - I'll make a note to fix it in the next release.

What you can do to make it work: call stopMoving before removing the object, and moveTo again when adding it back to the scene.

I'd write it like this with a forEach loop (to avoid using the variable in the setTimeout - I can't see the rest of your code but it's possible that i changes before the setTimeout function is executed)

shots.forEach(function(shot)
{
	if (shot.isEnemy)
	{
		shot.stopMoving();
		wade.removeSceneObject(shot);
	}
	setTimeout(function() 
	{
		wade.addSceneObject(shot]);
		shot.moveTo(sw/2, 50, 100);
	}, 1000);
});

 

 

MaineMathMan

I think the break prevents the i from incrementing.

Post a reply
Add Attachment
Submit Reply
Login to Reply