Jump to content

How to change the speed of current running frames at run time.


Sohail Ahmad
 Share

Recommended Posts

HI,

 

is there any way to control the game frame speeds at runtime ?

i need to change the speed of "Parallax" frame of the game, that was added when game object initialized.

 

Code Sample

 

this.addParallax(360, 'media/Ground.png', -400); 

 

 

in the above code, i need to change lets say -400 to -300 at runtime.

 

Any help?

 

Thanks in advance.

 

Regards,

 

Link to comment
Share on other sites

Hi,

 

Change your addParallax function to return TilingSprite:

addParallax: function(y, path, speed) {    var parallax = new game.TilingSprite(path);    parallax.position.y = y;    parallax.speed.x = speed;    this.addObject(parallax);    this.stage.addChild(parallax);    return parallax;},

Then you can change the speed with:

var sprite = this.addParallax(360, 'media/Ground.png', -400);sprite.speed.x = -300;
Link to comment
Share on other sites

one more thing i got to know.
 

Gap = game.Class.extend({
    groundTop: 800,
    width: 132,
    minY: 150,
    maxY: 550,
    height: 300,
    speed: -300,
 init: function() {
        var y = Math.round(game.Math.random(this.minY, this.maxY));
        soleGap = this;
        var topHeight = y - this.height / 2;
        this.topBody = new game.Body({
            position: {x: game.system.width + this.width / 2, y: topHeight / 2},
            velocity: {x: this.speed},
            collisionGroup: 0
        });
 
 
how to change the speed of this -300 to -400 at runtime (while playing)
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...