Jump to content

Extend Problome


mirage29
 Share

Recommended Posts

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 :o ?

 

Link to comment
Share on other sites

@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?
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...