Sign in to follow this  

Adjust delay of depending on score?

Recommended Posts

I have a game where items fall from the top of the screen at intervals. Currently this interval is set using a timing loop (at 5 seconds):

timerPos = * 5, positiveBall);

I would like to change the timing depending on what the score is, e.g. if the score is greater than 20, change the loop to every 4 seconds instead. I tried setting a time in a variable (spawnRate), and using the update function, like so

var spawnRate = 5;

create: function() [
    timerPos = * spawnRate, positiveBall);


update: function() {
        if (score > 20) {
            spawnRate = 4;

This has had no effect though. I assume as the loop is set in the create function, it can't be changed like this? How else could I tackle this?


Share this post

Link to post
Share on other sites

You're right: the timing of the loop is set in create, so you can't do it that way.

"events.loop" hands back a TimerEvent. You can use that object to cancel the existing timer (";") and make a new one.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.