/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Drawing class to handle drawing on the canvas
var Drawing = Container.expand(function () {
var self = Container.call(this);
var graphics = new Graphics();
self.addChild(graphics);
self.isDrawing = false;
self.lastPosition = null;
self.startDrawing = function (x, y) {
self.isDrawing = true;
self.lastPosition = {
x: x,
y: y
};
};
self.stopDrawing = function () {
self.isDrawing = false;
self.lastPosition = null;
};
self.draw = function (x, y) {
if (self.isDrawing && self.lastPosition) {
graphics.lineStyle(5, 0xffffff, 1);
graphics.moveTo(self.lastPosition.x, self.lastPosition.y);
graphics.lineTo(x, y);
graphics.endFill();
self.lastPosition = {
x: x,
y: y
};
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize drawing object
var drawing = new Drawing();
game.addChild(drawing);
// Event listeners for drawing
game.down = function (x, y, obj) {
drawing.startDrawing(x, y);
};
game.move = function (x, y, obj) {
drawing.draw(x, y);
};
game.up = function (x, y, obj) {
drawing.stopDrawing();
};
// Update function to handle game logic
game.update = function () {
// Add any game logic here if needed
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Drawing class to handle drawing on the canvas
var Drawing = Container.expand(function () {
var self = Container.call(this);
var graphics = new Graphics();
self.addChild(graphics);
self.isDrawing = false;
self.lastPosition = null;
self.startDrawing = function (x, y) {
self.isDrawing = true;
self.lastPosition = {
x: x,
y: y
};
};
self.stopDrawing = function () {
self.isDrawing = false;
self.lastPosition = null;
};
self.draw = function (x, y) {
if (self.isDrawing && self.lastPosition) {
graphics.lineStyle(5, 0xffffff, 1);
graphics.moveTo(self.lastPosition.x, self.lastPosition.y);
graphics.lineTo(x, y);
graphics.endFill();
self.lastPosition = {
x: x,
y: y
};
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize drawing object
var drawing = new Drawing();
game.addChild(drawing);
// Event listeners for drawing
game.down = function (x, y, obj) {
drawing.startDrawing(x, y);
};
game.move = function (x, y, obj) {
drawing.draw(x, y);
};
game.up = function (x, y, obj) {
drawing.stopDrawing();
};
// Update function to handle game logic
game.update = function () {
// Add any game logic here if needed
};