mirage29 Posted July 24, 2015 Share Posted July 24, 2015 I create a class extend Sprite. game.createClass('spriteAnimations','Sprite',{ss:{ x:0, y:0},init: function() { this._super(); console.log(this.ss)},go: function() { this.ss.x = 1;},and do this var a1 = new game.spriteAnimations();a1.go();var a2 = new game.spriteAnimations();why a2.ss.x also changed ? Quote Link to comment Share on other sites More sharing options...
PixelPicoSean Posted July 25, 2015 Share Posted July 25, 2015 The "createClass" method uses "extend" to create a new class and it'll assign properties of the passed object, so "Object properties" are shared between all class instances. Quote Link to comment Share on other sites More sharing options...
oranjoose Posted July 28, 2015 Share Posted July 28, 2015 @mirage29 When I do this code: game.createClass('Panda', 'Sprite', {texture: 'panda.png',myObject: { myObjectProperty: 10 }, init: function(x, y) {this.position.set(this.myObject.myObjectProperty, y);this.addTo(game.scene.stage);}, update: function() {this.position.set(this.myObject.myObjectProperty, this.y);}, changeMyObject: function () { this.myObject.myObjectProperty = 300;}}); game.createScene('Main', {init: function() {var sprite = new game.Panda(100, 100);sprite.changeMyObject();var sprite = new game.Panda(300, 300);var sprite = new game.Panda(500, 500);}}); It's not changing myObject.myObjectProperty on any of the other instances--it only changes the instance on which I called the changeMyObject member function. Am I misunderstanding your question? 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.