I'm trying to create a simple game using the paper.js library to achieve crisp results on all displays by leveraging it's vector drawing framework.
The basic game logic is that the user has to move the "worm" towards the balls within a certain time or they disappear, every time a ball is "hit" or "collected" by the worm then the ball disappears and a new one is generated elsewhere on the screen, thus allowing for more points to be gained.
I've managed to get a prototyped method firing on each ball when the worm hits it, but I'm struggling to manipulate the balls size when it happens.
See the working example here http://goo.gl/uNcl5y
The distance is checked using the method below and within this method the "destruct" (or when the ball should shrink to a radius of zero) is called within it:
Ball.prototype = {
checkCollision: function(linepoint, ball) {
var dist = this.point.getDistance(linepoint);
if (dist <= this.radius) {
this.destruct(ball);
}
},
destruct: function(ball) {
console.log(ball.bounds.width); //returns undefined
}
}
This is called using Paper.js onFrame function (essentially a setInterval called every 30ms or so used for animation):
//set animations
function onFrame() {
for (var i = 0; i < balls.length; i++) {
balls[i].checkCollision(path.firstSegment.point, balls[i]);
}
}
As far as I can tell passing in the "balls[i]" array object should give me access to it's properties and therefore allow me to alter them, sure enough
destruct: function(ball) {
console.log(ball);
}
logs
{
point: { x: 89, y: 628 },
path: Path @4,
radius: 30
}
but using (scale() is an inbuilt transform function in paper.js)
ball.scale(0);
returns
"Uncaught TypeError: undefined is not a function"
I can't wrap my head around what is going on, any pointers would be greatly appreciated.