/**** * Classes ****/ //<Assets used in the game will automatically appear here> // MagicBook class to handle drawing and animation var MagicBook = Container.expand(function () { var self = Container.call(this); var drawing = null; var isDrawing = false; // Event handler for starting the drawing self.down = function (x, y, obj) { isDrawing = true; drawing = new Graphics(); drawing.lineStyle(5, 0xffffff, 1); drawing.moveTo(x, y); self.addChild(drawing); }; // Event handler for drawing self.move = function (x, y, obj) { if (isDrawing) { drawing.lineTo(x, y); } }; // Event handler for ending the drawing self.up = function (x, y, obj) { isDrawing = false; animateDrawing(drawing); }; // Function to animate the drawing function animateDrawing(drawing) { var animation = new Graphics(); animation.lineStyle(5, 0xff0000, 1); animation.moveTo(drawing.graphicsData[0].shape.points[0], drawing.graphicsData[0].shape.points[1]); var points = drawing.graphicsData[0].shape.points; var index = 2; var animate = function () { if (index < points.length) { animation.lineTo(points[index], points[index + 1]); index += 2; requestAnimationFrame(animate); } }; self.addChild(animation); animate(); } }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize the magic book var magicBook = new MagicBook(); magicBook.x = 2048 / 2; magicBook.y = 2732 / 2; game.addChild(magicBook); // Set up event listeners for drawing game.down = function (x, y, obj) { magicBook.down(x, y, obj); }; game.move = function (x, y, obj) { magicBook.move(x, y, obj); }; game.up = function (x, y, obj) { magicBook.up(x, y, obj); }; // Update function to handle game logic game.update = function () { // Any game logic updates can be added here };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// MagicBook class to handle drawing and animation
var MagicBook = Container.expand(function () {
var self = Container.call(this);
var drawing = null;
var isDrawing = false;
// Event handler for starting the drawing
self.down = function (x, y, obj) {
isDrawing = true;
drawing = new Graphics();
drawing.lineStyle(5, 0xffffff, 1);
drawing.moveTo(x, y);
self.addChild(drawing);
};
// Event handler for drawing
self.move = function (x, y, obj) {
if (isDrawing) {
drawing.lineTo(x, y);
}
};
// Event handler for ending the drawing
self.up = function (x, y, obj) {
isDrawing = false;
animateDrawing(drawing);
};
// Function to animate the drawing
function animateDrawing(drawing) {
var animation = new Graphics();
animation.lineStyle(5, 0xff0000, 1);
animation.moveTo(drawing.graphicsData[0].shape.points[0], drawing.graphicsData[0].shape.points[1]);
var points = drawing.graphicsData[0].shape.points;
var index = 2;
var animate = function () {
if (index < points.length) {
animation.lineTo(points[index], points[index + 1]);
index += 2;
requestAnimationFrame(animate);
}
};
self.addChild(animation);
animate();
}
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize the magic book
var magicBook = new MagicBook();
magicBook.x = 2048 / 2;
magicBook.y = 2732 / 2;
game.addChild(magicBook);
// Set up event listeners for drawing
game.down = function (x, y, obj) {
magicBook.down(x, y, obj);
};
game.move = function (x, y, obj) {
magicBook.move(x, y, obj);
};
game.up = function (x, y, obj) {
magicBook.up(x, y, obj);
};
// Update function to handle game logic
game.update = function () {
// Any game logic updates can be added here
};