Jump to content

Problem with game.timer.speed


Ninjadoodle
 Share

Recommended Posts

Hi @enpu

I'm trying to speed up the game with game.timer.speed, and it seems to work on all my objects, apart from my player ship rotation.

Any idea why the rotation of the ship is not speeding up?

I'm using this to rotate the ship ...

update: function() {
    
    this.stageSetup.updateStage();
    
    if (this.spinning) {
        
        if (this.shipSpeed < this.shipLimit) {
            this.shipSpeed += 0.0005 * Math.PI;
        }
        
        if (this.dir === 1) {
            
            this.ship.sprite.rotation += this.shipSpeed * Math.PI;
            
        } else {
            
            this.ship.sprite.rotation -= this.shipSpeed * Math.PI;
        }
    }
},

Thank you!

Link to comment
Share on other sites

game.delta is time in seconds that tells how long did it take to get from last frame into the current frame.

If your game runs on 60 frames per seconds, that would mean that one frame would take around 0.17 seconds to finish.
Usually games don't run exactly 60 fps all the time, this means that the game.delta value changes a little in every frame.

Now let's say we want to move a sprite every frame and keep the speed constant. If we just increase the position value with hard number like 10, that would mean that if the last frame did take longer than 0.17 seconds to finish, it would look like the sprite is slowing down.

But if we multiply the value with game.delta every frame, we would end up with a value that is changing based on how long did the last frame take. So if the last frame did take longer, the value will be bigger and the sprite will be moved more. This way it would look like the sprite is moving same speed all the time, no matter how long the frames are taking.

Does that make sense?

 

Link to comment
Share on other sites

  • 4 weeks later...

Small clarification on what is the difference, when moving sprite using delta value vs when using just fixed number:

// This will move sprite 100 pixels in one second
sprite.position.x += 100 * game.delta;

// This will move sprite 100 pixels every frame
sprite.position.x += 100;

So multiplying value with game.delta will sync it into time.

 

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...