Kongregate Developers

Drawing custom shapes

You may use the drawCanvasObject function to use any of the methods in the AS2 Drawing API in order to create a custom graphic shape. This function takes a name, and a list of drawing operations, which must come from this list:

 beginFill()
 beginGradientFill()
 clear()
 curveTo()
 endFill()
 lineTo()
 lineStyle()
 moveTo()
 drawRect()
 drawRoundRect()
 drawCircle()
 drawEllipse()
drawCanvasObject(name:String,operations:Array):void
  • name:String - The name of the object
  • operations:Array - The drawing operations to perform, from the list above

Example: Drawing a box using the drawCanvasObject function

 var commands:Array = [
            ["beginFill",0x333333,100],
            ["moveTo",25,25],
            ["lineTo",75,25],
            ["lineTo",75,75],
            ["lineTo",25,75],
            ["lineTo",25,25],
            ["endFill"] ];
 kongregate.chat.drawCanvasObject("box",commands);

Note that unlike other display operations, drawing onto an object which already exists will not replace it, but instead will draw onto the existing object.

Comments