I think there is a misunderstanding, @grzesiekmq. I believe you are refering to this post:
By “store off that position” that Will was mentioning, he did not mean a localStorage or a database, but simply the instance of your application. You can store your variable by attaching it to the script via this
, for example:
initialize: function() {
this.position = new pc.Vec3();
},
add: function() {
this.position.add(pc.Vec3.UP);
},
update: function() {
var newPosition = this.entity.getPosition(); // new position each frame
var existingPosition = this.position; // existing position, persisted between frames
// do something
}
The key word here “persisted between frames”, not persisted between page refreshes. So, instead of creating a new position every frame, you re-use the existing one, which can be manipulated outside of .update()
method.
Also, you generally don’t want to use localStorage for storing the positions of your bumps or whatnot. As @yaustar mentioned, nobody can access that data later, except same browser, same person. The problem will come later, when you want to change the way you store these positions or the way you calculate them, or the way you read them, etc. Some browsers then will have one version of your positions, others another, etc. It all can be managed, but why make it hard for yourself in the first place?
Instead, simply calculate all the positions when your game starts and store them in an array. This way, you will always have up to date coordinates, and you don’t need to worry about the localStorage mess. And by “store them in array”, I mean simply attach it to your script via this
, like this.positions = myArray;
. It will be available for you while your application is alive, and will be destroyed once it is closed.