courtneyvigo Posted December 9, 2016 Share Posted December 9, 2016 Hi everyone. I am super new to Pixi. I have a function that iterates every time it is called. The issue is that the gameloop function speeds up every time it is called. Is there a better way of animating this: //text scroll: function ScrollingText() { var pendingTexts = []; function addText(username, msg, emotes, bits) { pendingTexts.push({ username: username, message: msg, emotes: emotes, bits: bits }); } text = new PIXI.Text('', { // fontFamily: 'Oswald', // fontSize: 24, // fill: 0xff1010, // align: 'center' }); text.x = 500; text.y = 0; gameLoop(); //stage.addChild(text); } //declare global variables: var text1 = {}; var text2 = {}; var text3 = {}; var text4 = {}; var text5 = {}; var currentTextPosition = 0; var nextTextPosition = function (){ if (currentTextPosition == 1) { console.log(currentTextPosition); text1 = new PIXI.Text('User1', { fontFamily: 'Oswald', fontSize: 24, fill: 0xff1010, align: 'center' }); text1.x = 500; text1.y = 0; stage.addChild(text1); gameLoop(); } if (currentTextPosition == 2) { console.log(currentTextPosition); text2 = new PIXI.Text('User2', { fontFamily: 'Oswald', fontSize: 24, fill: 0xff1010, align: 'center' }); text2.x = 500; text2.y = 25; stage.addChild(text2); gameLoop(); } currentTextPosition += 1; } function gameLoop() { requestAnimationFrame(gameLoop); text1.x -= 1; text2.x -= 1; renderer.render(stage); } Thanks in advance Quote Link to comment Share on other sites More sharing options...
Fatalist Posted December 9, 2016 Share Posted December 9, 2016 You should call gameLoop() only once and it will continue running, no need to call it in addText or nextTextPosition . courtneyvigo 1 Quote Link to comment Share on other sites More sharing options...
courtneyvigo Posted December 9, 2016 Author Share Posted December 9, 2016 Thank you! That fixed it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.