Jump to content

Dynamically updating arguments in a Timer.loop


Mitrug
 Share

Recommended Posts

Greetings,

Quick question: How do I dynamically update the arguments of this loop from the update function to reflect the actual coordinates of the pointer? (This loop is found in the create() function)

Game.mouseTimer = game.time.events.loop(
	100, 
	Client.sendMousePos,
	Client.class,
	game.input.mousePointer.x, 
	game.input.mousePointer.y
);

I have already attempted several techniques, such as including this code snippet in the update function; However, it throws an Uncaught TypeError: Cannot set property '0' of undefined error. 

Game.mouseTimer.args[0] = game.input.mousePointer.x;
Game.mouseTimer.args[1] = game.input.mousePointer.y;

 To go around the error, I tried to manually initialize the Game.mouseTimer.args array before the loop. This did indeed avoid the error; However, it only updated the arguments once.

Thanks.

 

Link to comment
Share on other sites

Simply encapsulating the Client.sendMousePos(x,y) function in another function did the trick.

Game.mouseTimer = game.time.events.loop(
	100, 
	Game.updateMousePos,
	Game.class
);

Game.updateMousePos = function(){
    Client.sendMousePos(game.input.mousePointer.x, game.input.mousePointer.y);
};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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