Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

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

Sohail Ahmad

Recommended Posts



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.




Link to comment
Share on other sites



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


  • Recently Browsing   0 members

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