Gio,
I have a couple of questions to ask regarding the draw functions
1. How do I draw a line for a chain of physics vertices. Like the floor in the stickman demos. In the past, I used the code below, but it doesn't seem to work anymore. It only draws the line once and then disappears. Also, I don't think this will work in a webGL environment ?
floorSprite.setDrawFunction(function(context){ self.drawLines(context,this.getSceneObject()); });
this.drawLines = function(context,obj) {
var points = obj.vertices;
var pos = obj.getPosition();
var strokeStyle = context.strokeStyle;
context.strokeStyle = 'red';
context.beginPath();
context.moveTo(points[0].x+pos.x, points[0].y+pos.y);
for (var i=1; i < points.length; i++)
{
context.lineTo(points[i].x+pos.x, points[i].y+pos.y);
}
if (obj.chainIsLoop) {
context.lineTo(points[0].x+pos.x, points[0].y+pos.y);
}
context.stroke();
context.strokeStyle = strokeStyle;
};
2. I would like to gradient fill a closed area given a list of vertices. For example, filling in the ground from the floor chain to the bottom of the game. I guess, this would be the same as (1) above, with two extra vertices for the bottom right and left corners and then calling context.fillStyle().
3. Sometimes animations only come in one direction (ex. runRight is a 4x4 animation). Right now, I use PS and flip the png manually to create the runLeft.
var runRight = new Animation('./images/runRight.png',4,4,24,true);
var runFlip = new Sprite('./images/runRight.png',wade.app.GAME_LAYER);
runFlip.setDrawFunction(wade.drawFunctions.mirror_(runFlip.draw));
var runLeft = new Animation(runFlip,4,4,24,true);
I tried doing the above, but the runLeft doesn't show anything ? Could you post a snippet of the correct way to do this ?
thanks -shri