micouy Posted July 28, 2016 Share Posted July 28, 2016 Hi, it's my first time here and my first game. I don't know much about javascript also. My problem is that I set a variable 'rockUp' to create sprite in my function addRocks and I want to use x of this sprite in 'update' to add points. Function addRocks is called by a looped timer set in 'create', so it can't detect x of that sprite correctly. What do I have to do? code: drive.google.com/file/d/0B2GJjU5fsrlgZEV3Y2F2dTJEelk/view (sorry for my english) Link to comment Share on other sites More sharing options...
Clem Posted July 28, 2016 Share Posted July 28, 2016 You can create an array to store your rocks, you put them inside of the array from the addRocks() function and then in the update method you get the x for each rock you have. Link to comment Share on other sites More sharing options...
Skeptron Posted July 28, 2016 Share Posted July 28, 2016 One very simple solution is to put the object either in the Gamestate or in the game object. Then it will be accessible in the update() function. Link to comment Share on other sites More sharing options...
micouy Posted July 28, 2016 Author Share Posted July 28, 2016 Thanks guys but I'm such a newbie. Could you tell me how to do it? I'd be so thankfull Link to comment Share on other sites More sharing options...
Recommended Posts