Jump to content

gameLoop function speeds up every time it is called


courtneyvigo
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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