My code in v2.2.1. used to look like this (no, it’s not actual working code, just an illustration):
var mySprite = cc.Sprite.crate... ... var position = mySprite.getPosition(); position.x+= 20; moveFunction(mySprite, position);
But then, when I updated to v2.2.2 I got errors, so I had to change
position.setX(position.x+20). This, however, makes the sprite move instantly, since it turns out
position is a reference to the sprite’s position, rather than a copy of it.
So now, my code looks like this:
var mySprite = cc.Sprite.crate... ... var temp = mySprite.getPosition(); var position = cc.p(temp.x, temp.y); position.x+= 20; moveFunction(mySprite, position);
Like this, everything works as it should, but I wonder: is there a better way to clone gometry objects than manually making a duplicate?