Code edit (19 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Fix LK.getAsset() call in preload() function because as by the Api the method getAsset does not take a callback
Code edit (1 edits merged)
Please save this source code
User prompt
Now between the lines console.log("Preloading assets..."); and console.log("Assets loaded."); load all the assets used in the game
===================================================================
--- original.js
+++ change.js
@@ -222,8 +222,9 @@
var shuffleDifficulty = 4;
var lastCheckCaller = 0;
var isPlaying = false;
var isGameEndChecking = false;
+var isTryingInitGame = false;
var checkGameEndTimeout = null;
if (nbCards % 2) {
console.error('Invalid number of cards ! Should be even.', nbCards);
LK.showGameOver();
@@ -449,10 +450,10 @@
}, true);
} else {
level++;
level = Math.min(levels.length - 1, Math.max(0, level));
- isGameEndChecking = false;
showConfettiAnimation(context, function () {
+ isGameEndChecking = false;
tryInitGame(context);
});
}
}, 300);
@@ -482,13 +483,13 @@
var card2 = cards.flat().find(function (card) {
return card.id === index && card !== card1;
});
if (canBeLinked(card1, card2)) {
- indexesChecked[index] = true;
nbPossible++;
} else {
nbImpossible++;
}
+ indexesChecked[index] = true;
}
lastNbPossible = nbPossible;
return Math.max(currentNbSolved, nbPossible) >= (nbImpossible + nbPossible) * 0.1;
}
@@ -526,8 +527,12 @@
}
isInitializing = false;
}
function tryInitGame(context) {
+ if (isTryingInitGame) {
+ console.log('Already tryInitGame...');
+ return;
+ }
var isPossible = false;
var nbTries = 0;
var currentDifficulty = shuffleDifficulty;
while (!isPossible && nbTries <= MAX_INIT_TRIES) {
@@ -539,8 +544,9 @@
}
if (nbTries > MAX_INIT_TRIES) {
console.warn('Unable to init game after ' + nbTries + ' tries');
}
+ isTryingInitGame = false;
}
function tryRemixCards(nbTries, currentDifficulty) {
nbTries = nbTries || 0;
currentDifficulty = currentDifficulty || shuffleDifficulty;
@@ -584,9 +590,9 @@
var totalTicks = 420 + (isFinal ? 300 : 0);
var tickCount = 0;
LK.on('tick', function () {
if (tickCount < totalTicks) {
- confetti.y += 5 + 10 * Math.random() + (isFinal ? 10 : 0);
+ confetti.y += 7 + 10 * Math.random() + (isFinal ? 10 : 0);
confetti.rotation += 0.05;
tickCount++;
} else {
LK.off('tick', arguments.callee);
@@ -602,8 +608,19 @@
})(confettiGraphics);
}
}
function preload(context) {
+ var titleText = new Text2('Xmas Pairs', {
+ size: 200,
+ fill: '#9bc5bc',
+ anchor: {
+ x: 0.5,
+ y: 0.5
+ }
+ });
+ titleText.x = 2048 / 8;
+ titleText.y = 2732 / 8;
+ LK.gui.addChild(titleText);
var loadingText = new Text2('Loading...', {
size: 100,
fill: '#ffffff',
anchor: {
@@ -619,11 +636,13 @@
assetsToLoad.forEach(function (asset) {
var assetInstance = LK.getAsset(asset, 'Loading ' + asset, 0.5, 0.5);
loadedAssets++;
if (loadedAssets === assetsToLoad.length) {
- console.log("Assets loaded.");
- loadingText.destroy();
- tryInitGame(context);
+ LK.setTimeout(function () {
+ loadingText.destroy();
+ titleText.destroy();
+ tryInitGame(context);
+ }, 1200);
}
});
}
var Game = Container.expand(function () {
a photo realistic top view of empty flat beige plastic square. Single Game Texture. In-Game asset. 2d. No background. High contrast. No shadows.
a christmas tree. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gift. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas ball. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a golden christmas tree star. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas hat. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas leaf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas holly leaf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas snow flake. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas snow man. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas reindeer. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas candy cane. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas green ball . plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gingerbrean man. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas pine cone. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas present green. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas boe tie. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas socks. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas penguin. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas decorated blue present. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas scarf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gloves. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas blue decorated ball. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas candle. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas snow globe. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
an christmas elongated cuboid present. plastic style. No shadow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round christmas gift.plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round christmas gift.plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cute christmas elf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cute christmas elf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cute christmas reindeer head. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cute christmas reindeer head with a red nose. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one christmas bell. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a couple of christmas bells. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gifts bag. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas candle. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute santa clauss. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Santa's sleigh. Side view. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Reimagine the cute teddy bear sitting without background. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Christmas Rocking Horse. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
One Christmas Matryoshka Doll. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A christmas Miniature Train. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A christmas Toy Soldier. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A christmas Music Box . Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute polar bear cub. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a sled plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gingerbread girl. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gingerbread house. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute christmas jack in the box. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute christmas cookie. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas log cacke. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas donut. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute christmas owl. Plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a feeric christmas landscape at night with decorated trees Background image
a feeric christmas landscape at night with snow men and snow flakes Background image
a feeric christmas landscape at night with a snow man , candy canes ,holly leafs and snow flakes, Background image
a feeric christmas landscape at night with a snow man , candy canes ,holly leafs and snow flakes, Santa's reindeers, green, red and blue presents Background image
a feeric christmas landscape at night with a snow man , candy canes ,holly leafs and snow flakes, cute penguin, Santa's reindeers, green, red and blue presents and a lot of toys, a sled, gingerbread boy and girl, snow globes, a cute polar bear cub. a gingerbread house Background image
A Magical feeric starry christmas landscape at night with a snow man , candy canes ,holly leafs and snow flakes, cute penguin, Santa's reindeers, green, red and blue presents and a lot of toys, a sled, gingerbread boy and girl, snow globes, cute polar bears cub and a gingerbread house. Realistic. Plastic style. Background image