/**** * Classes ****/ // ClickCounterDisplay class var ClickCounterDisplay = Container.expand(function () { var self = Container.call(this); var clickCounterText = new Text2("Clicks: 0", { size: 50, fill: "#ffffff" }); clickCounterText.anchor.set(0.5, 0); self.addChild(clickCounterText); self.update = function () { clickCounterText.setText("Clicks: " + game.clickCount); }; }); // ClickerButton class var ClickerButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('clickerButton', { anchorX: 0.5, anchorY: 0.5 }); self.interactive = true; // Make the button interactive self.buttonMode = true; // Change cursor on hover self.on('down', function () { // Increase score and click counter when button is clicked game.score++; game.clickCount++; scoreText.setText("Score: " + game.score + "\nClicks: " + game.clickCount); }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize the clicker button asset // Initialize score and click counter game.score = 0; game.clickCount = 0; // Create the clicker button and add it to the game var clickerButton = game.addChild(new ClickerButton()); clickerButton.x = game.width / 2; clickerButton.y = game.height / 2; // Create the score text and add it to the GUI var scoreText = new Text2("Score: 0", { size: 100, fill: "#ffffff" }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); scoreText.x = game.width / 2; // Create the click counter display and add it to the GUI var clickCounterDisplay = game.addChild(new ClickCounterDisplay()); clickCounterDisplay.x = game.width / 2; clickCounterDisplay.y = scoreText.y + scoreText.height + 20; // Main game update loop LK.on('tick', function () { // Game logic goes here // In this simple clicker game, the score is updated via the button click event clickCounterDisplay.update(); });
/****
* Classes
****/
// ClickCounterDisplay class
var ClickCounterDisplay = Container.expand(function () {
var self = Container.call(this);
var clickCounterText = new Text2("Clicks: 0", {
size: 50,
fill: "#ffffff"
});
clickCounterText.anchor.set(0.5, 0);
self.addChild(clickCounterText);
self.update = function () {
clickCounterText.setText("Clicks: " + game.clickCount);
};
});
// ClickerButton class
var ClickerButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('clickerButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.interactive = true; // Make the button interactive
self.buttonMode = true; // Change cursor on hover
self.on('down', function () {
// Increase score and click counter when button is clicked
game.score++;
game.clickCount++;
scoreText.setText("Score: " + game.score + "\nClicks: " + game.clickCount);
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize the clicker button asset
// Initialize score and click counter
game.score = 0;
game.clickCount = 0;
// Create the clicker button and add it to the game
var clickerButton = game.addChild(new ClickerButton());
clickerButton.x = game.width / 2;
clickerButton.y = game.height / 2;
// Create the score text and add it to the GUI
var scoreText = new Text2("Score: 0", {
size: 100,
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.x = game.width / 2;
// Create the click counter display and add it to the GUI
var clickCounterDisplay = game.addChild(new ClickCounterDisplay());
clickCounterDisplay.x = game.width / 2;
clickCounterDisplay.y = scoreText.y + scoreText.height + 20;
// Main game update loop
LK.on('tick', function () {
// Game logic goes here
// In this simple clicker game, the score is updated via the button click event
clickCounterDisplay.update();
});