ippa / jaws

Jaws - HTML5 canvas javascript 2D Game Framework
https://jawsjs.ippa.se
GNU Lesser General Public License v3.0
364 stars 75 forks source link

jaws.Parallax.add_layer use jaws.Parallax.prototype.default_options.layers #84

Closed yetanotherportfolio closed 11 years ago

yetanotherportfolio commented 11 years ago

Hello, I'm new with jaws.js and I love it. I just found something here, not sure if it's me or a real bug.

// in the menu GameState
var para1 = new jaws.Parallax({});
para1.addLayer({image: "image1.png", damping: 1});
para1.addLayer({image: "image2.png", damping: 2});
console.log(para1.layers.length); // 2

// in another GameState
var para2 = new jaws.Parallax({});
para2.addLayer({image: "image3.png", damping: 3});
console.log(para2.layers.length); // 3, should be 1 right?

It make the parallax from the menu gamestate visible in the gamescene gamestate. A good workaround is to not use that function but the constructor instead:

var para1 = new jaws.Parallax({
   layers: [
      new jaws.ParallaxLayer({image: "image1.png", damping: 1}),
      new jaws.ParallaxLayer({image: "image2.png", damping: 2})
  ]
});
ippa commented 11 years ago

looks like a bug ye, could you add this as a failing test-case?

ippa commented 11 years ago

Fixed in https://github.com/ippa/jaws/commit/a97f5de686b92f55ae552aa2e0f5919495f1cf85 .. good find!

yetanotherportfolio commented 11 years ago

Wow, good job! That was quick! Keep up the good work.