Jump to content

Is this a rendering issue or...


Recommended Posts

My issue here is I'm trying to create  a countdown timer using fonts and styling of my choice but I don't know how to update the text variable. I want to call the addChild method once and have the value of that string updated in a function. The only way I can see the updated countdown is with the addChild method but at the moment that leaves duplicate copies of the object on the screen. The render does not clear the canvas even though I read in the documentation it's set to do that by default. I tried two methods to get the desired results:

var countdown = new PIXI.Text( days+" days "+hours+" hours " +minutes+" minutes "+seconds+" seconds ",timerStyle);
//tried a second method and that was use to create a sprite from the text
    textSprite = new PIXI.Sprite(countdown.texture);

I did some extensive google searching and I learned that you need to use the function .updateText(); in order for the text variable to actually update. I thought this would work but it does nothing to change the string value on the screen. I have also tried to declare and add the countdown  variable to the stage, outside the function but the text does not update. 

Any suggestions would be greatly appreciated. 

Link to comment
Share on other sites

Hello! UpdateText is used only for texture manipulations that you dont have. In your case update will be that thing:

countdown.text = days+" days "+hours+" hours " +minutes+" minutes "+seconds+" seconds ";

I advice you to read something about JS itself, like http://shop.oreilly.com/product/9780596805531.do

Link to comment
Share on other sites

That still doesn't help multiple text objects are created every time the timer is incremented. What other way can I go about adding one text object on the stage and having it dynamically update during render time? The reason I'm seeing multiple copies is probably because I keep adding the object to the stage.

function countDown(){
...//getting the time code
        //font styling
    var timerStyle = new PIXI.TextStyle({
    fontFamily: 'Times New Roman',
    fontStyle: 'normal',
    fontWeight: 'light',
    fill: ['#ffffff'], // gradient
    countdown =  days+" days "+hours+" hours " +minutes+" minutes "+seconds+" seconds ";
    duh = new PIXI.Text(countdown,timerStyle)

    timerStyle.x = 100;
    timerStyle.y = 300;
    timerContainer.x =timerStyle.x;
    timerContainer.y =timerStyle.y;
    timerContainer.scale.x = timerContainer.scale.y =3.7;

}, 1000);       



Link to comment
Share on other sites

Books shows only ES5, basic version of JS, you can read something about ES6 later. Here's the book: https://www.dropbox.com/s/dvcdcqpxcpuobk8/[O`Reilly] - JavaScript. The Definitive Guide%2C 6th ed. - [Flanagan].pdf?dl=0 . Dropbox keeps deleteing my links because of copyrights, grab the book and i remove it :)

Link to comment
Share on other sites

I think the assumption in the original question was that you passed the string to the PIXI.Text constructer by a reference. You can think of strings in JS as being "passed by copy" (unless it's passed as an object with a string property). When you set PIXI.Text.text, a set method is called which updates it with the new string.

In addition to that you were also joining multiple variables into a string literal when you created the PIXI.Text instance. So the assumption there was that those variables could be updated with the string literal you defined somehow knowing about that and re-creating itself.

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.

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.


  • Recently Browsing   0 members

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