User prompt
remove animation from game title
User prompt
touch to strart should also have effects like title
Code edit (2 edits merged)
Please save this source code
User prompt
game title should very slightly increase and decrase its size
Code edit (1 edits merged)
Please save this source code
User prompt
Game title should slightly increase and decrease the size and slightly floar
User prompt
when a pair of tiles has already been guessed do not play yes sound, play touch
User prompt
play no when a life is lost
User prompt
play no when miss a match
User prompt
play no sound when a correct match is selected
User prompt
play yes sound when a match is made
User prompt
use tile sound when a tile is turned
User prompt
play touch sound when player touches the screen while countdown
User prompt
use start sound when level changes
User prompt
When player touches ro start for the first time, play start sound
User prompt
Play start when player toches start
User prompt
Play backgroundmusic on game load
User prompt
Migrate to the latest version of LK
User prompt
Make sure numbers are alwatlys displayed after counter finishes in new level
/**** * Classes ****/ // HexTile class for the hexagon tiles var HexTile = Container.expand(function (id, colorIndex) { var self = Container.call(this); self.id = id; var hexGraphics = self.attachAsset('hexTile', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); var numberText = new Text2('', { size: 100, fill: '#333333' // Slightly lighter black }); numberText.anchor.set(0.5, 0.5); // Initially set numberText visibility to false numberText.visible = false; // Fade in effect for numberText var fadeInDuration = 60; // Duration for fade in in ticks (1 second at 60FPS) var fadeInCounter = 0; // Counter to track the number of ticks for fading LK.on('tick', function () { if (!numberText.visible && playerTouchedScreen) { fadeInCounter++; var progress = fadeInCounter / fadeInDuration; numberText.alpha = progress; if (fadeInCounter >= fadeInDuration) { numberText.visible = true; // Ensure the text is visible after fading numberText.alpha = 1; // Reset alpha after complete fade in } } }); self.addChild(numberText); self.setNumber = function (number) { self.number = number; numberText.setText(number.toString()); }; self.isSelected = false; self.toggleSelect = function () { self.isSelected = !self.isSelected; self.interactive = !self.isSelected; // Toggle interactive state hexGraphics.alpha = self.isSelected ? 0.5 : 1; if (self.isSelected) { numberText.setText(self.number.toString()); LK.getSound('tile').play(); // Play tile sound when a tile is turned } else { numberText.setText(''); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: [0x8AACB8, 0x61AC84, 0xcc919a, 0xFFA07A, 0xB39BDB, 0x73be73][Math.floor(Math.random() * 6)] // Randomly choose from soft light blue, soft light orange, soft pink, soft light red, soft light yellow, soft light green }); /**** * Game Code ****/ var scoreText = new Text2('Score 0', { size: 75, fill: '#ffffff' }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); scoreText.visible = false; var missedAttemptMessages = ["Ooops!", "Missed!", "Not Quite!", "Close One!"]; var gameTitle = new Text2('Memo-Hex', { size: 200, fill: '#ffffff', alpha: 1 }); gameTitle.anchor.set(0.5, 0); gameTitle.x = 0; // Center horizontally gameTitle.y = 100; // Move down 100 pixels LK.gui.top.addChild(gameTitle); // Play background music on game load LK.playMusic('Backgroundmusic'); // Blinking 'Touch to start' text var touchToStartText = new Text2('Touch to start', { size: 100, fill: '#ffffff', alpha: 1 }); touchToStartText.anchor.set(0.5, 0); touchToStartText.x = 0; // Center horizontally touchToStartText.y = gameTitle.y + gameTitle.height + 80; // Position below the game title LK.gui.top.addChild(touchToStartText); // Add floating and size animation to 'Touch to start' text var touchFloatDirection = 1; var touchFloatSpeed = 0.05; var touchFloatRange = 5; var touchSizeDirection = 1; var touchSizeSpeed = 0.0005; var touchSizeRange = 0.02; LK.on('tick', function () { touchToStartText.y += touchFloatSpeed * touchFloatDirection; if (touchToStartText.y >= gameTitle.y + gameTitle.height + 80 + touchFloatRange || touchToStartText.y <= gameTitle.y + gameTitle.height + 80 - touchFloatRange) { touchFloatDirection *= -1; } touchToStartText.scale.x += touchSizeSpeed * touchSizeDirection; touchToStartText.scale.y += touchSizeSpeed * touchSizeDirection; if (touchToStartText.scale.x >= 1 + touchSizeRange || touchToStartText.scale.x <= 1 - touchSizeRange) { touchSizeDirection *= -1; } }); var howToPlayText = new Text2('How to Play: \n⢠Memorize the hex numbers on countdown \n⢠Wait for goal number to appear above hex tiles \n⢠Touch two hexes that add up to the number \n⢠Repeat until all combinations possible are found', { size: 60, fill: '#ffffff', alpha: 1 }); howToPlayText.anchor.set(0.5, 0.5); howToPlayText.x = 0; howToPlayText.y = 1500; LK.gui.top.addChild(howToPlayText); // Modify game's 'down' event listener to hide howToPlayText after first touch var originalGameDownHandler = game._events && game._events['down'] ? game._events['down'][0] : function () {}; function newGameDownHandler(obj) { // Play start sound on first touch if (firstTouch) { LK.getSound('Start').play(); } else if (countdown > 0) { LK.getSound('Touch').play(); } // Start fading out the 'How to Play' text var howToPlayFadeOut = true; var howToPlayFadeDuration = 60; // Duration for fade out in ticks (1 second at 60FPS) var howToPlayFadeCounter = 0; // Counter to track the number of ticks for fading LK.on('tick', function () { if (howToPlayFadeOut) { howToPlayFadeCounter++; var progress = howToPlayFadeCounter / howToPlayFadeDuration; howToPlayText.alpha = 1 - progress; if (howToPlayFadeCounter >= howToPlayFadeDuration) { howToPlayFadeOut = false; // Stop fading howToPlayText.visible = false; // Ensure the text is invisible after fading } } }); originalGameDownHandler(obj); // Make level text visible on first touch levelText.alpha = 1; levelText.visible = true; scoreText.visible = true; LK.setTimeout(function () { countdownText.visible = true; }, 1500); touchToStartText.visible = false; // Start fading out the game title var gameTitleFadeOut = true; var gameTitleFadeDuration = 60; // Duration for fade out in ticks (1 second at 60FPS) var gameTitleFadeCounter = 0; // Counter to track the number of ticks for fading // Update the game tick function to handle game title fading LK.on('tick', function () { if (gameTitleFadeOut) { gameTitleFadeCounter++; var progress = gameTitleFadeCounter / gameTitleFadeDuration; gameTitle.alpha = 1 - progress; if (gameTitleFadeCounter >= gameTitleFadeDuration) { gameTitleFadeOut = false; // Stop fading gameTitle.visible = false; // Ensure the title is invisible after fading } } }); // Make hexTile numbers visible on first touch for (var i = 0; i < hexTiles.length; i++) { hexTiles[i].getChildAt(1).visible = true; } } game.off('down', originalGameDownHandler); game.on('down', function (x, y, obj) { obj.event = obj; newGameDownHandler(obj); }); var firstTouch = true; game.on('down', function (x, y, obj) { playerTouchedScreen = true; if (countdown > 1 && !firstTouch) { showRandomMotivationalText(); } firstTouch = false; // Make life icons visible on first touch // Update life icons visibility based on current lives for (var i = 0; i < lifeIcons.length; i++) { lifeIcons[i].alpha = i < lives ? 1 : 0; } }); var playerTouchedScreen = false; var motivationalTexts = ["Memorize!", "Wait for countdown!", "Wait for goal number!", "Stay focused!"]; var motivationalText = new Text2('', { size: 100, fill: '#ffffff', alpha: 0 // Initially invisible }); motivationalText.anchor.set(0.5, 0); motivationalText.x = 0; // Center horizontally motivationalText.y = 400; // Position at the top of the screen LK.gui.top.addChild(motivationalText); var fadeState = 'in'; // Track the fade state of the motivational text var fadeDuration = 60; // Duration for fade in and fade out in ticks (1 second at 60FPS) var fadeCounter = 0; // Counter to track the number of ticks for fading function showRandomMotivationalText() { var randomIndex = Math.floor(Math.random() * motivationalTexts.length); motivationalText.setText(motivationalTexts[randomIndex]); fadeState = 'in'; fadeCounter = 0; // Reset fade counter } // Update the game tick function to handle motivational text fading LK.on('tick', function () { if (fadeState !== 'none') { fadeCounter++; var progress = fadeCounter / fadeDuration; if (fadeState === 'in') { motivationalText.alpha = progress; if (fadeCounter >= fadeDuration) { fadeState = 'out'; // Switch to fading out fadeCounter = 0; // Reset counter for fade out } } else if (fadeState === 'out') { motivationalText.alpha = 1 - progress; if (fadeCounter >= fadeDuration) { fadeState = 'none'; // Stop fading } } } }); function resetGameForNextLevel() { // Reset hexTiles numbers for (var i = 0; i < hexTiles.length; i++) { // Number generation and assignment removed from here to be handled inside initializeHexTiles function. } // Reset goal var randomTile1 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; var randomTile2 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; while (randomTile1 === randomTile2) { randomTile2 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; } goalNumber = randomTile1.number + randomTile2.number; goalText.setText(goalNumber); // Reset combinations correctCombinations = 0; for (var i = 0; i < hexTiles.length; i++) { for (var j = i + 1; j < hexTiles.length; j++) { if (hexTiles[i].number + hexTiles[j].number === goalNumber) { correctCombinations++; } } } combinationsText.setText(correctGuess + '/' + correctCombinations); } var level = 1; var levelText = new Text2('Level ' + level, { size: 75, fill: '#ffffff', alpha: 0 // Make level text invisible initially }); levelText.anchor.set(1, 0); levelText.x = -50; // Move level text 50 pixels to the left // Hide level text on game start levelText.visible = false; LK.gui.topRight.addChild(levelText); correctGuess = 0; var correctGuess = 0; var lives = 3; var lifeIcons = []; for (var i = 0; i < lives; i++) { var lifeIcon = LK.getAsset('lifeIcon', { anchorX: 1, anchorY: 0, x: -i * 90 - 50, // Move life icons 50 pixels to the left y: 100, alpha: 0 // Make life icons invisible initially }); LK.gui.topRight.addChild(lifeIcon); lifeIcons.push(lifeIcon); } var countdown = 10; // Start from 10 and make it visible for one second before countdown starts if (hexTiles) { for (var i = 0; i < hexTiles.length; i++) { hexTiles[i].interactive = false; } } var countdownText = new Text2(countdown, { size: 200, fill: '#ffffff', alpha: 0 // Make invisible initially }); countdownText.visible = false; countdownText.anchor.set(0.5, 1); LK.gui.top.addChild(countdownText); var countdownInterval = LK.setInterval(function () { if (playerTouchedScreen) { countdown--; if (countdown <= 0) { for (var i = 0; i < hexTiles.length; i++) { hexTiles[i].interactive = true; } countdownText.alpha = 0; goalText.visible = true; goalTextFadeIn = true; // Start fading in the goal text goalTextFadeCounter = 0; // Reset fade counter combinationsText.visible = true; combinationsTextFadeIn = true; // Start fading in the combinations text combinationsTextFadeCounter = 0; // Reset fade counter LK.clearInterval(countdownInterval); for (var i = 0; i < hexTiles.length; i++) { hexTiles[i].getChildAt(1).setText(''); } } else { countdownText.setText(countdown); } } }, 1000); countdownText.y += 1600; //var scoreText = new Text2('Score: 0', { // size: 75, // fill: '#ffffff' //}); //scoreText.anchor.set(0.5, 0); //LK.gui.top.addChild(scoreText); // Create goal number and display it below the score if (hexTiles && hexTiles.length > 1) { sumOfNeighbours = hexTiles[hexTiles.length - 2].number + hexTiles[hexTiles.length - 1].number; } // sumText initialization moved to after hexTiles initialization var sumOfNeighbours = 0; var hexTiles = []; var selectedTiles = []; var guessedPairs = {}; var gridRows = []; function initializeHexTiles() { function initializeHexTiles() { // Define gridRows based on the current game level var gridRows; if (level <= 5) { gridRows = [2, 3, 2]; countdown = 11; } else if (level <= 10) { gridRows = [1, 2, 3, 4]; countdown = 16; } else if (level <= 15) { gridRows = [2, 3, 4, 3, 2]; } else { // Default to the highest defined grid for levels beyond those explicitly defined gridRows = [3, 4, 5, 4, 3]; } var tileSpacingX = 250; var tileSpacingY = 210; var startX = (2048 - Math.max.apply(Math, gridRows) * tileSpacingX) / 2 + tileSpacingX / 2; var startY = (2732 - gridRows.length * tileSpacingY) / 2 + tileSpacingY / 2; // Initialize hex tiles for (var i = 0; i < gridRows.length; i++) { for (var j = 0; j < gridRows[i]; j++) { var hexTile = new HexTile(i * gridRows.length + j); var numberRange; if (level <= 2) { numberRange = 3; } else if (level <= 5) { numberRange = 7; } else if (level > 5 && level <= 7) { numberRange = 5; } else if (level <= 12) { numberRange = 7; } else if (level <= 15) { numberRange = 7; } else { numberRange = 9; } hexTile.setNumber(Math.floor(Math.random() * numberRange) + 1); hexTile.x = startX + j * tileSpacingX + (Math.max.apply(Math, gridRows) - gridRows[i]) * tileSpacingX / 2; hexTile.y = startY + i * tileSpacingY; game.addChild(hexTile); hexTiles.push(hexTile); (function (hexTile) { hexTile.on('down', function (x, y, obj) { if (countdown > 0) { return; } if (selectedTiles.length < 2) { hexTile.toggleSelect(); if (hexTile.isSelected) { selectedTiles.push(hexTile); if (selectedTiles.length == 2) { if (selectedTiles[0].number + selectedTiles[1].number === goalNumber) { var pairId = [selectedTiles[0].id, selectedTiles[1].id].sort().join('-'); if (!guessedPairs[pairId]) { LK.getSound('yes').play(); // Play yes sound when a match is made guessedPairs[pairId] = true; correctGuess++; LK.setScore(LK.getScore() + 10 * level); combinationsText.setText(correctGuess + '/' + correctCombinations); // Show 'Yes!' or 'Right!' text on correct combination var correctCombinationMessages = ["Yes!", "Right!", "Correct!", "Nice!"]; var randomMessageIndex = Math.floor(Math.random() * correctCombinationMessages.length); var correctCombinationMessage = new Text2(correctCombinationMessages[randomMessageIndex], { size: 100, fill: '#ffffff', alpha: 1 // Initially visible }); correctCombinationMessage.anchor.set(0.5, 0); correctCombinationMessage.x = 0; // Center horizontally correctCombinationMessage.y = 1650; // Position at specified height LK.gui.top.addChild(correctCombinationMessage); // Directly start fading out the correct combination message without fade in effect var correctCombinationMessageFadeDuration = 60; // Duration for fade out in ticks (1 second at 60FPS) var correctCombinationMessageFadeCounter = correctCombinationMessageFadeDuration; // Start counter at full duration for immediate fade out LK.on('tick', function () { correctCombinationMessageFadeCounter--; scoreText.setText('Score ' + LK.getScore()); var progress = correctCombinationMessageFadeCounter / correctCombinationMessageFadeDuration; correctCombinationMessage.alpha = progress; if (correctCombinationMessageFadeCounter <= 0) { LK.gui.top.removeChild(correctCombinationMessage); // Remove the message after fading out } }); } else { LK.getSound('Touch').play(); // Play touch sound when a pair has already been guessed // Show 'Tried already!' text for a previously guessed pair var triedAlreadyMessage = new Text2("Tried already!", { size: 100, fill: '#ffffff', alpha: 0 // Initially invisible }); triedAlreadyMessage.anchor.set(0.5, 0); triedAlreadyMessage.x = 0; // Center horizontally triedAlreadyMessage.y = 1650; // Position at specified height LK.gui.top.addChild(triedAlreadyMessage); // Directly start fading out 'Tried already!' message without fade in effect var triedAlreadyMessageFadeDuration = 60; // Duration for fade out in ticks (1 second at 60FPS) var triedAlreadyMessageFadeCounter = triedAlreadyMessageFadeDuration; // Start counter at full duration for immediate fade out LK.on('tick', function () { triedAlreadyMessageFadeCounter--; var progress = triedAlreadyMessageFadeCounter / triedAlreadyMessageFadeDuration; triedAlreadyMessage.alpha = progress; if (triedAlreadyMessageFadeCounter <= 0) { LK.gui.top.removeChild(triedAlreadyMessage); // Remove the message after fading out } }); } LK.setTimeout(function () { if (selectedTiles.length > 0) { selectedTiles[0].toggleSelect(); } if (selectedTiles.length > 1) { selectedTiles[1].toggleSelect(); } selectedTiles = []; }, 300); if (correctGuess === correctCombinations) { // Disable interaction with hex tiles immediately after all combinations are found for (var i = 0; i < hexTiles.length; i++) { hexTiles[i].interactive = false; } LK.setTimeout(function () { // Temporarily bring the background to the top of the z axis game.addChildAt(game.background, game.children.length); LK.setTimeout(function () { // Move the background back to its original position after 2 seconds game.addChildAt(game.background, 0); }, 2000); level++; LK.getSound('Start').play(); lives = 3; // Reset lives back to initial value // Delete existing life icons for (var i = 0; i < lifeIcons.length; i++) { lifeIcons[i].destroy(); } lifeIcons = []; // Clear the lifeIcons array // Recreate life icons for (var i = 0; i < lives; i++) { var lifeIcon = LK.getAsset('lifeIcon', { anchorX: 1, anchorY: 0, x: -i * 90 - 50, // Move life icons 50 pixels to the left y: 100, alpha: 1 // Make life icons visible }); LK.gui.topRight.addChild(lifeIcon); lifeIcons.push(lifeIcon); } // Update score text to reflect current score dynamically LK.setScore(LK.getScore() + 10 * level); correctGuess = 0; guessedPairs = {}; combinationsText.setText(correctGuess + '/' + correctCombinations); levelText.setText('Level ' + level); countdown = 10; goalText.visible = false; combinationsText.visible = false; countdownText.alpha = 1; countdownText.setText(countdown); LK.clearInterval(countdownInterval); countdownInterval = LK.setInterval(function () { countdown--; if (countdown <= 0) { countdownText.alpha = 0; goalText.visible = true; combinationsText.visible = true; LK.clearInterval(countdownInterval); for (var i = 0; i < hexTiles.length; i++) { hexTiles[i].getChildAt(1).setText(''); } } else { countdownText.setText(countdown); } }, 1000); LK.effects.flashScreen(0x90EE90, 500); // Show success message var successMessages = ["Great Job!", "Level Cleared!", "Awesome!", "Well Done!", "Fantastic!"]; var randomSuccessMessageIndex = Math.floor(Math.random() * successMessages.length); var successMessage = new Text2(successMessages[randomSuccessMessageIndex], { size: 150, // Adjust size to match motivational text fill: '#ffffff', alpha: 1 }); successMessage.anchor.set(0.5, 0); // Adjust anchor to match motivational text successMessage.x = 0; // Center horizontally successMessage.y = 400; // Position at the same height as motivational text LK.gui.top.addChild(successMessage); // Initialize variables for success message fade out var successMessageFadeOut = true; var successMessageFadeDuration = 120; // Duration for fade out in ticks (2 seconds at 60FPS), starts 1 second after appearing var successMessageFadeCounter = 0; // Counter to track the number of ticks for fading LK.on('tick', function () { if (successMessageFadeOut) { successMessageFadeCounter++; var progress = successMessageFadeCounter / successMessageFadeDuration; successMessage.alpha = 1 - progress; if (successMessageFadeCounter >= successMessageFadeDuration) { successMessageFadeOut = false; // Stop fading LK.gui.top.removeChild(successMessage); // Ensure the message is removed after fading } } }); // Remove previous hex tiles for (var i = 0; i < hexTiles.length; i++) { hexTiles[i].destroy(); } hexTiles = []; initializeHexTiles(); // Update goal and guesses with new numbers on the new grid // Ensure a different random background color is chosen when the level changes, different from the previous one. var previousBackgroundColor = game.backgroundColor; var newColors = [0x8AACB8, 0x61AC84, 0xcc919a, 0xFFA07A, 0xB39BDB, 0x73be73].filter(function (color) { return color !== previousBackgroundColor; }); game.setBackgroundColor(newColors[Math.floor(Math.random() * newColors.length)]); var randomTile1 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; var randomTile2 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; while (randomTile1 === randomTile2) { randomTile2 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; } goalNumber = randomTile1.number + randomTile2.number; goalText.setText(goalNumber); // Reset combinations correctCombinations = 0; for (var i = 0; i < hexTiles.length; i++) { for (var j = i + 1; j < hexTiles.length; j++) { if (hexTiles[i].number + hexTiles[j].number === goalNumber) { correctCombinations++; } } } combinationsText.setText(correctGuess + '/' + correctCombinations); }, 1000); // Wait one second before executing level transition } // End of level transition delay } else { lives--; lifeIcons[lives].destroy(); if (lives <= 0) { LK.showGameOver("Your Score: " + LK.getScore()); } else { LK.getSound('no').play(); // Play no sound when a life is lost LK.effects.flashScreen(0xFFA07A, 500); // Select a random missed attempt message var missedMessageIndex = Math.floor(Math.random() * missedAttemptMessages.length); var missedMessage = new Text2(missedAttemptMessages[missedMessageIndex], { size: 100, fill: '#ffffff', alpha: 0 // Initially invisible }); missedMessage.anchor.set(0.5, 0); missedMessage.x = 0; // Center horizontally missedMessage.y = 1650; // Position at the top of the screen LK.gui.top.addChild(missedMessage); // Fade in the missed attempt message var missedMessageFadeIn = true; var missedMessageFadeDuration = 120; // Duration for fade in and out in ticks (1 second at 60FPS) var missedMessageFadeCounter = 0; // Counter to track the number of ticks for fading LK.on('tick', function () { if (missedMessageFadeIn) { missedMessageFadeCounter++; var progress = missedMessageFadeCounter / missedMessageFadeDuration; missedMessage.alpha = progress; if (missedMessageFadeCounter >= missedMessageFadeDuration / 2) { missedMessageFadeIn = false; // Start fading out after reaching half duration } } else { missedMessageFadeCounter--; var progress = missedMessageFadeCounter / missedMessageFadeDuration; missedMessage.alpha = progress; if (missedMessageFadeCounter <= 0) { LK.gui.top.removeChild(missedMessage); // Remove the message after fading out } } }); } LK.setTimeout(function () { if (selectedTiles.length > 0) { selectedTiles[0].toggleSelect(); } if (selectedTiles.length > 1) { selectedTiles[1].toggleSelect(); } selectedTiles = []; }, 300); } } } else { var index = selectedTiles.indexOf(hexTile); if (index > -1) { selectedTiles.splice(index, 1); } } } }); })(hexTile); } } } initializeHexTiles(); } initializeHexTiles(); var randomTile1 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; var randomTile2 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; while (randomTile1 === randomTile2) { randomTile2 = hexTiles[Math.floor(Math.random() * hexTiles.length)]; } var goalNumber = randomTile1.number + randomTile2.number; var goalText = new Text2(goalNumber, { size: 300, fill: '#ffffff', alpha: 0 // Make invisible initially }); // Initialize goal text fade-in variables var goalTextFadeIn = false; var goalTextFadeDuration = 60; // Duration for fade in in ticks (1 second at 60FPS) var goalTextFadeCounter = 0; // Counter to track the number of ticks for fading goalText.visible = false; // Ensure goal text is initially invisible goalText.anchor.set(0.5, 1); goalText.y += 550; LK.gui.top.addChild(goalText); // Calculate the number of unique correct combinations var correctCombinations = 0; for (var i = 0; i < hexTiles.length; i++) { for (var j = i + 1; j < hexTiles.length; j++) { if (hexTiles[i].number + hexTiles[j].number === goalNumber) { correctCombinations++; } } } // Display the number of unique correct combinations below the goal var combinationsText = new Text2(correctGuess + '/' + correctCombinations, { size: 100, fill: '#ffffff', alpha: 1 // Make visible }); // Initialize combinations text fade-in variables var combinationsTextFadeIn = false; var combinationsTextFadeDuration = 60; // Duration for fade in in ticks (1 second at 60FPS) var combinationsTextFadeCounter = 0; // Counter to track the number of ticks for fading combinationsText.visible = false; // Ensure combinations text is initially invisible combinationsText.anchor.set(0.5, 0); combinationsText.y += 1400; LK.gui.top.addChild(combinationsText); // Game tick function LK.on('tick', function () { // Handle goal text fade in effect if (goalTextFadeIn) { goalTextFadeCounter++; var progress = goalTextFadeCounter / goalTextFadeDuration; goalText.alpha = progress; if (goalTextFadeCounter >= goalTextFadeDuration) { goalTextFadeIn = false; // Stop fading } } // Handle combinations text fade in effect if (combinationsTextFadeIn) { combinationsTextFadeCounter++; var progress = combinationsTextFadeCounter / combinationsTextFadeDuration; combinationsText.alpha = progress; if (combinationsTextFadeCounter >= combinationsTextFadeDuration) { combinationsTextFadeIn = false; // Stop fading } } // Game logic that needs to be executed every frame });
===================================================================
--- original.js
+++ change.js
@@ -77,26 +77,8 @@
gameTitle.anchor.set(0.5, 0);
gameTitle.x = 0; // Center horizontally
gameTitle.y = 100; // Move down 100 pixels
LK.gui.top.addChild(gameTitle);
-// Add floating and size animation to game title
-var floatDirection = 1;
-var floatSpeed = 0.05;
-var floatRange = 5;
-var sizeDirection = 1;
-var sizeSpeed = 0.0005;
-var sizeRange = 0.02;
-LK.on('tick', function () {
- gameTitle.y += floatSpeed * floatDirection;
- if (gameTitle.y >= 100 + floatRange || gameTitle.y <= 100 - floatRange) {
- floatDirection *= -1;
- }
- gameTitle.scale.x += sizeSpeed * sizeDirection;
- gameTitle.scale.y += sizeSpeed * sizeDirection;
- if (gameTitle.scale.x >= 1 + sizeRange || gameTitle.scale.x <= 1 - sizeRange) {
- sizeDirection *= -1;
- }
-});
// Play background music on game load
LK.playMusic('Backgroundmusic');
// Blinking 'Touch to start' text
var touchToStartText = new Text2('Touch to start', {