Code edit (4 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
create a new function updateOverlayLayer that just sets overlayLayer as the last gameChild using addChildAt
Code edit (1 edits merged)
Please save this source code
User prompt
in playButterflyAnim, prepare the target Y before the tween call and rotate the butterfly in the direction of the move
Code edit (5 edits merged)
Please save this source code
User prompt
in Butterfly class, create a list of nice colors for butterflies and make tint random from this array
Code edit (1 edits merged)
Please save this source code
User prompt
in Butterfly class, setFrame or setTexture doesn't exists, use 4 assets graphics and show/hide them alternatively
User prompt
Please fix the bug: 'TypeError: butterflyGraphics.setTexture is not a function' in or related to this line: 'butterflyGraphics.setTexture(LK.getAsset(butterflyFrames[currentFrame], {}).texture);' Line Number: 87
===================================================================
--- original.js
+++ change.js
@@ -20,8 +20,9 @@
for (var i = 0; i < butterflyFrames.length; i++) {
var graphic = self.attachAsset(butterflyFrames[i], {
anchorX: 0.5,
anchorY: 0.5,
+ alpha: 0.9,
tint: selectedColor,
scaleX: 0.4 + Math.random() * 0.2,
scaleY: 0.4 + Math.random() * 0.2,
visible: i === currentFrame // Only the first frame is visible initially
@@ -218,17 +219,54 @@
/****
* Game Code
****/
+function updateOverlayLayer() {
+ game.addChildAt(overlayLayer, game.children.length - 1);
+}
+function _typeof2(o) {
+ "@babel/helpers - typeof";
+ return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
+ return typeof o;
+ } : function (o) {
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
+ }, _typeof2(o);
+}
+function _defineProperty2(e, r, t) {
+ return (r = _toPropertyKey2(r)) in e ? Object.defineProperty(e, r, {
+ value: t,
+ enumerable: !0,
+ configurable: !0,
+ writable: !0
+ }) : e[r] = t, e;
+}
+function _toPropertyKey2(t) {
+ var i = _toPrimitive2(t, "string");
+ return "symbol" == _typeof2(i) ? i : i + "";
+}
+function _toPrimitive2(t, r) {
+ if ("object" != _typeof2(t) || !t) {
+ return t;
+ }
+ var e = t[Symbol.toPrimitive];
+ if (void 0 !== e) {
+ var i = e.call(t, r || "default");
+ if ("object" != _typeof2(i)) {
+ return i;
+ }
+ throw new TypeError("@@toPrimitive must return a primitive value.");
+ }
+ return ("string" === r ? String : Number)(t);
+}
function playButterflyAnim() {
- if (!frontLayer) {
+ if (!overlayLayer) {
return;
}
// Create a butterfly instance at the right edge of the screen
var butterfly = new Butterfly();
butterfly.x = 2048 + 50; // Start slightly off-screen to the right
butterfly.y = Math.random() * 2732; // Random vertical position
- frontLayer.addChild(butterfly);
+ overlayLayer.addChild(butterfly);
// Animate the butterfly to move from right to left
var targetY = 100 + Math.random() * 2500; // Prepare target Y before tween call
var direction = Math.atan2(targetY - butterfly.y, -50 - butterfly.x); // Calculate direction of movement
butterfly.rotation = direction + Math.PI; // Rotate butterfly in the direction of the move
@@ -236,37 +274,25 @@
x: -50,
// Move off-screen to the left
y: targetY // Use prepared target Y
}, {
- duration: 8000 + Math.random() * 3000,
+ duration: 9000 + Math.random() * 3000,
// Random duration between 8 to 11 seconds
easing: tween.linear,
onFinish: function onFinish() {
// Remove the butterfly after animation completes
- frontLayer.removeChild(butterfly);
+ overlayLayer.removeChild(butterfly);
}
});
}
-// Set an interval to play butterfly animation every 5 to 10 seconds
-LK.setInterval(playButterflyAnim, 5000 + Math.random() * 5000);
function playPlumesAnim() {
- if (!frontLayer) {
+ if (!overlayLayer) {
return;
}
// Create a plume asset at the right edge of the screen
- var plume = LK.getAsset('plumes', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 2048 + 50,
- // Start slightly off-screen to the right
- y: Math.random() * 2732,
- // Random vertical position
- scaleX: 1,
- scaleY: 1,
- alpha: 1
- });
+ var plume = LK.getAsset('plumes', {});
// Add the plume to the game
- frontLayer.addChild(plume);
+ overlayLayer.addChild(plume);
// Animate the plume to move from right to left
tween(plume, {
x: -50,
// Move off-screen to the left,
@@ -2023,8 +2049,9 @@
var backgroundImage1;
var backgroundImage2;
var middleLayer;
var frontLayer;
+var overlayLayer;
var gridBoard;
var gridBoardSoil;
var gridBoardSoilOffset = 20;
var growGrass;
@@ -2211,8 +2238,9 @@
// Init and Add backgroundLayer
backgroundLayer = new Container();
middleLayer = new Container();
frontLayer = new Container();
+ overlayLayer = new Container();
game.addChild(backgroundLayer);
// Add backgroundPlaying1 to the menu state
backgroundImage1 = LK.getAsset('backgroundPlaying1', {
anchorX: 0.5,
@@ -2250,8 +2278,9 @@
gridBoard.y = 2732 / 2;
game.addChild(gridBoard);
game.addChild(middleLayer);
game.addChild(frontLayer);
+ game.addChild(overlayLayer);
// Create growGrass asset
growGrass = LK.getAsset('growGrass', {
anchorX: 0.5,
anchorY: 0.5,
@@ -2314,9 +2343,11 @@
resetButton.visible = false;
// Add the level text to the game
game.addChild(resetButton);
// Set an interval to play plumes animation every 5 to 10 seconds
- LK.setInterval(playPlumesAnim, 1000 + Math.random() * 2000);
+ LK.setInterval(playPlumesAnim, 1000 + Math.random() * 1000);
+ // Set an interval to play butterfly animation every 5 to 10 seconds
+ LK.setInterval(playButterflyAnim, 5000 + Math.random() * 5000);
// Transition to menu state
changeGameState(GAME_STATE.MENU);
}
function initMenuState() {
straigth zenith view square light wooden pallet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
straigth zenith view square wooden pallet with big screws in each corner Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
simple yellow rating star. Modern video game style
tileSlide
Sound effect
levelWon
Sound effect
tileBlocked
Sound effect
fountain
Sound effect
waterInPipe
Sound effect
bgMusic
Music
logoBounce
Sound effect
levelStart
Sound effect
bgMusic2
Music
flowerPop
Sound effect
roundResult
Sound effect
gameWon
Sound effect
resetSound
Sound effect
birds
Sound effect
birds2
Sound effect
birds3
Sound effect