Sohail Ahmad Posted April 2, 2014 Share Posted April 2, 2014 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, Quote Link to comment Share on other sites More sharing options...
enpu Posted April 2, 2014 Share Posted April 2, 2014 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; Sohail Ahmad 1 Quote Link to comment Share on other sites More sharing options...
Sohail Ahmad Posted April 2, 2014 Author Share Posted April 2, 2014 You are great Quote Link to comment Share on other sites More sharing options...
Sohail Ahmad Posted April 2, 2014 Author Share Posted April 2, 2014 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) Quote Link to comment Share on other sites More sharing options...
enpu Posted April 2, 2014 Share Posted April 2, 2014 Try: this.topBody.velocity.x = -400; Quote Link to comment Share on other sites More sharing options...
Sohail Ahmad Posted April 2, 2014 Author Share Posted April 2, 2014 i need to change this value at outside this .js filelike my method is function UpdateLevel(){ this.topBody.velocity.x = -400;} how to manage this here, because its only accessible within the body of that method. Quote Link to comment Share on other sites More sharing options...
enpu Posted April 2, 2014 Share Posted April 2, 2014 You need to have access to the instance of Gap class, example:var gap = new Gap();gap.topBody.velocity.x = -300; Sohail Ahmad 1 Quote Link to comment Share on other sites More sharing options...
Sohail Ahmad Posted April 2, 2014 Author Share Posted April 2, 2014 once again thanks for the hint.i have update this method. spawnGap: function () { var gap = new Gap(); gap.topBody.velocity.x = GlobalConfig.gapSpeed; this.addObject(gap); }and updating GlobalConfig.gapSpeed value in UpdateLevel() method.working perfect for me you are awesome.Long live man.Thanks alot. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.