I have a custom object called pipe
function pipe()
{
this.x = 800;
this.width = 50;
this.y = 450;
}
When I try storing pipes in an array its not storing the object, but the function.
function loop()
{
var flappy = new player();
for(var i = 0; i < 3; ++i)
{
var p = new pipe();
p.x = (1 + i) * 266;
pipes.push(pipe);
}
interval = window.setInterval(function() { updateLogic(flappy) } , 20);
}
If I try accessing a property of a pipe in pipes it says undefined.
var pipe = pipes[0];
console.log(pipe.x);
You put pipes.push(pipe)
instead of pipes.push(p)
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments