Jump to content

Tween infinity repeat


Recommended Posts

So I have this code I want to repeat

        stars = game.add.group();    stars.enableBody = true;            //  And now we convert all of the Tiled objects with an ID of 34 into sprites within the coins group    map.createFromObjects('Object Layer 1', 6, 'star', 0, true, false, stars);        game.add.tween(stars.position).to( {y: 100}, 2200, Phaser.Easing.Back.InOut, true, 2000, 20, true);    

I want to repeat the tween an infinite amount of times. Currently is set to repeat 20 times. From reading the book I got from phaser.io about tween management, I should be able to set this value to -1 and it should repeat constantly till i tell it to stop in another line.


However the first tween is called and executed and then it stops. The tween seems to stop once it hits -1. It does not go to the Yoyo attribute of the tween and return to the original position. The tween is stopped completely.


Any advice would be great.


Thanks in advance I do not really know how to code and i am doing all this from examples and attempting to use reason.



Link to comment
Share on other sites

Looking at the phaser docs, you can try use the loop function on the end.


game.add.tween(stars.position).to( {y: 100}, 2200, Phaser.Easing.Back.InOut, true, 2000, 20, true).loop(true);
EDIT: Behind the scenes, this does the same thing as setting your 20 to -1, it seems, so this shouldn't make a difference...

As for why changing your 20 to -1 making it not loop, no idea...

The docs say you should be able to do that, so perhaps it is a bug...

EDIT 2: Tested this out myself, and it was working as intended... I copied your line that starts the tween, put my own image in there, and set it to -1...

It is still happily bouncing around...

This tells me that there is something else going on somewhere...

Link to comment
Share on other sites

Ok so i got it. With you testing it and working, it got me thinking that the error must it been somewhere else.


So thank you very much the issue was that in the 


js/ folder on my server since i was still working off the tutorials folders, I was missing:






So thank you very much for the suggestion, now they are bouncing all over constantly.


Next Step: Adding enemies.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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