My latest 'object' creation:
function Gem()
{
this.size = 20.0;
this.body;
this.isCollected = false;
this.vertexPosBuffer;
this.vertexColBuffer;
}
Next, I define a function for it:
Gem.prototype.Update = function()
{
this.body.ApplyForce(new b2Vec2(0, 5), this.body.GetPosition());
}
Finally, I populate an array with gems:
var gems;
function AddNewGem()
{
var newGem = new Gem;
var position = new b2Vec2;
position.x = Math.random()*(canvas.width+1);
position.y = Math.random()*(canvas.height+1);
newGem.InitializeRandom(position);
gems.push(newGem);
}
To update all gems, I use the following function:
function UpdateGems()
{
for(var gem in gems)
{
gem.Update();
}
}
However, I encountered the following error:
Uncaught TypeError: Object 0 has no method 'Update'
Oddly enough, the "InitializeRandom(...)" methods, added in the same manner, do work...
What am I missing here?