User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'progressText.text.split')' in or related to this line: 'if (tapCount !== parseInt(progressText.text.split(' ')[1].split('/')[0])) {' Line Number: 303
Code edit (1 edits merged)
Please save this source code
User prompt
Magic Snow Ginger
Initial prompt
Toca snow glow (2014). Toddler ginger 🐱 is going snow magic. Tap on ginger 🐱 9 times to make snow and ice magic, and then toddler ginger 🐱 sing “little bo peep”
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var GingerCharacter = Container.expand(function () {
var self = Container.call(this);
// Main body
var body = self.attachAsset('ginger', {
anchorX: 0.5,
anchorY: 0.5
});
// Eyes
var leftEye = self.attachAsset('gingerFace', {
anchorX: 0.5,
anchorY: 0.5,
x: -80,
y: -50,
scaleX: 0.8,
scaleY: 0.8
});
var rightEye = self.attachAsset('gingerFace', {
anchorX: 0.5,
anchorY: 0.5,
x: 80,
y: -50,
scaleX: 0.8,
scaleY: 0.8
});
// Mouth
var mouth = self.attachAsset('gingerMouth', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
self.isSinging = false;
self.originalMouthScale = 1;
self.startSinging = function () {
self.isSinging = true;
// Animate mouth opening and closing while singing
tween(mouth, {
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeInOut
});
LK.setTimeout(function () {
if (self.isSinging) {
tween(mouth, {
scaleY: 1
}, {
duration: 200,
easing: tween.easeInOut
});
}
}, 300);
};
self.stopSinging = function () {
self.isSinging = false;
tween(mouth, {
scaleY: 1
}, {
duration: 200,
easing: tween.easeInOut
});
};
self.update = function () {
if (self.isSinging) {
// Continue mouth animation while singing
if (LK.ticks % 60 === 0) {
tween(mouth, {
scaleY: 1.3
}, {
duration: 150,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (self.isSinging) {
tween(mouth, {
scaleY: 1
}, {
duration: 150,
easing: tween.easeInOut
});
}
}
});
}
}
};
self.down = function (x, y, obj) {
tapCount++;
// Play tap sound
LK.getSound('tap').play();
// Create sparkle effect at tap location
createSparkle(x, y);
// Bounce effect on ginger
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Check if we reached 9 taps
if (tapCount >= 9) {
triggerMagicSnow();
}
};
return self;
});
var IceParticle = Container.expand(function () {
var self = Container.call(this);
var iceGraphics = self.attachAsset('iceParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 10;
self.velocityY = (Math.random() - 0.5) * 10;
self.lifetime = 0;
self.maxLifetime = 120; // 2 seconds
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityX *= 0.98; // Friction
self.velocityY *= 0.98;
self.rotation += 0.05;
self.lifetime++;
self.alpha = 1 - self.lifetime / self.maxLifetime;
if (self.lifetime >= self.maxLifetime) {
self.destroy();
for (var i = iceParticles.length - 1; i >= 0; i--) {
if (iceParticles[i] === self) {
iceParticles.splice(i, 1);
break;
}
}
}
};
return self;
});
var Snowflake = Container.expand(function () {
var self = Container.call(this);
var snowGraphics = self.attachAsset('snowflake', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 3 + 1;
self.sway = Math.random() * 2 - 1;
self.lifetime = 0;
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.lifetime * 0.05) * self.sway;
self.rotation += 0.02;
self.lifetime++;
// Remove when off screen
if (self.y > 2732 + 50) {
self.destroy();
for (var i = snowflakes.length - 1; i >= 0; i--) {
if (snowflakes[i] === self) {
snowflakes.splice(i, 1);
break;
}
}
}
};
return self;
});
var Sparkle = Container.expand(function () {
var self = Container.call(this);
var sparkleGraphics = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5
});
self.lifetime = 0;
self.maxLifetime = 60; // 1 second at 60fps
self.update = function () {
self.lifetime++;
self.rotation += 0.1;
self.alpha = 1 - self.lifetime / self.maxLifetime;
if (self.lifetime >= self.maxLifetime) {
self.destroy();
for (var i = sparkles.length - 1; i >= 0; i--) {
if (sparkles[i] === self) {
sparkles.splice(i, 1);
break;
}
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue winter sky
});
/****
* Game Code
****/
var tapCount = 0;
var ginger;
var sparkles = [];
var snowflakes = [];
var iceParticles = [];
var isMagicActive = false;
var songTimeout;
// Progress indicator
var progressText = new Text2('Taps: 0/9', {
size: 80,
fill: 0xFFFFFF
});
progressText.anchor.set(0.5, 0);
LK.gui.top.addChild(progressText);
progressText.y = 100;
// Create and position ginger character
ginger = game.addChild(new GingerCharacter());
ginger.x = 2048 / 2;
ginger.y = 2732 / 2;
function createSparkle(x, y) {
var sparkle = new Sparkle();
sparkle.x = x;
sparkle.y = y;
sparkles.push(sparkle);
game.addChild(sparkle);
// Random scale and rotation
sparkle.scaleX = Math.random() * 0.5 + 0.5;
sparkle.scaleY = sparkle.scaleX;
sparkle.rotation = Math.random() * Math.PI * 2;
}
function triggerMagicSnow() {
if (isMagicActive) return;
isMagicActive = true;
// Play magic sound
LK.getSound('magic').play();
// Create burst of ice particles
for (var i = 0; i < 20; i++) {
var ice = new IceParticle();
ice.x = ginger.x + (Math.random() - 0.5) * 200;
ice.y = ginger.y + (Math.random() - 0.5) * 200;
iceParticles.push(ice);
game.addChild(ice);
}
// Flash effect
LK.effects.flashScreen(0xFFFFFF, 500);
// Start singing
ginger.startSinging();
LK.getSound('littleBopeep').play();
// Reset after song (assuming song is about 10 seconds)
songTimeout = LK.setTimeout(function () {
ginger.stopSinging();
tapCount = 0;
isMagicActive = false;
updateProgressText();
}, 10000);
}
function updateProgressText() {
progressText.setText('Taps: ' + tapCount + '/9');
}
function createSnowflake() {
var snow = new Snowflake();
snow.x = Math.random() * 2048;
snow.y = -50;
snowflakes.push(snow);
game.addChild(snow);
}
game.update = function () {
// Create gentle snowfall during magic
if (isMagicActive && LK.ticks % 10 === 0) {
createSnowflake();
}
// Update progress text
if (tapCount !== parseInt(progressText.text.split(' ')[1].split('/')[0])) {
updateProgressText();
}
// Glow effect on ginger based on tap count
if (tapCount > 0) {
var glowIntensity = tapCount / 9;
ginger.alpha = 0.8 + glowIntensity * 0.2;
} else {
ginger.alpha = 1;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,298 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var GingerCharacter = Container.expand(function () {
+ var self = Container.call(this);
+ // Main body
+ var body = self.attachAsset('ginger', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Eyes
+ var leftEye = self.attachAsset('gingerFace', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -80,
+ y: -50,
+ scaleX: 0.8,
+ scaleY: 0.8
+ });
+ var rightEye = self.attachAsset('gingerFace', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 80,
+ y: -50,
+ scaleX: 0.8,
+ scaleY: 0.8
+ });
+ // Mouth
+ var mouth = self.attachAsset('gingerMouth', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 50
+ });
+ self.isSinging = false;
+ self.originalMouthScale = 1;
+ self.startSinging = function () {
+ self.isSinging = true;
+ // Animate mouth opening and closing while singing
+ tween(mouth, {
+ scaleY: 1.5
+ }, {
+ duration: 200,
+ easing: tween.easeInOut
+ });
+ LK.setTimeout(function () {
+ if (self.isSinging) {
+ tween(mouth, {
+ scaleY: 1
+ }, {
+ duration: 200,
+ easing: tween.easeInOut
+ });
+ }
+ }, 300);
+ };
+ self.stopSinging = function () {
+ self.isSinging = false;
+ tween(mouth, {
+ scaleY: 1
+ }, {
+ duration: 200,
+ easing: tween.easeInOut
+ });
+ };
+ self.update = function () {
+ if (self.isSinging) {
+ // Continue mouth animation while singing
+ if (LK.ticks % 60 === 0) {
+ tween(mouth, {
+ scaleY: 1.3
+ }, {
+ duration: 150,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ if (self.isSinging) {
+ tween(mouth, {
+ scaleY: 1
+ }, {
+ duration: 150,
+ easing: tween.easeInOut
+ });
+ }
+ }
+ });
+ }
+ }
+ };
+ self.down = function (x, y, obj) {
+ tapCount++;
+ // Play tap sound
+ LK.getSound('tap').play();
+ // Create sparkle effect at tap location
+ createSparkle(x, y);
+ // Bounce effect on ginger
+ tween(self, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 100,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100,
+ easing: tween.easeIn
+ });
+ }
+ });
+ // Check if we reached 9 taps
+ if (tapCount >= 9) {
+ triggerMagicSnow();
+ }
+ };
+ return self;
+});
+var IceParticle = Container.expand(function () {
+ var self = Container.call(this);
+ var iceGraphics = self.attachAsset('iceParticle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocityX = (Math.random() - 0.5) * 10;
+ self.velocityY = (Math.random() - 0.5) * 10;
+ self.lifetime = 0;
+ self.maxLifetime = 120; // 2 seconds
+ self.update = function () {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityX *= 0.98; // Friction
+ self.velocityY *= 0.98;
+ self.rotation += 0.05;
+ self.lifetime++;
+ self.alpha = 1 - self.lifetime / self.maxLifetime;
+ if (self.lifetime >= self.maxLifetime) {
+ self.destroy();
+ for (var i = iceParticles.length - 1; i >= 0; i--) {
+ if (iceParticles[i] === self) {
+ iceParticles.splice(i, 1);
+ break;
+ }
+ }
+ }
+ };
+ return self;
+});
+var Snowflake = Container.expand(function () {
+ var self = Container.call(this);
+ var snowGraphics = self.attachAsset('snowflake', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = Math.random() * 3 + 1;
+ self.sway = Math.random() * 2 - 1;
+ self.lifetime = 0;
+ self.update = function () {
+ self.y += self.speed;
+ self.x += Math.sin(self.lifetime * 0.05) * self.sway;
+ self.rotation += 0.02;
+ self.lifetime++;
+ // Remove when off screen
+ if (self.y > 2732 + 50) {
+ self.destroy();
+ for (var i = snowflakes.length - 1; i >= 0; i--) {
+ if (snowflakes[i] === self) {
+ snowflakes.splice(i, 1);
+ break;
+ }
+ }
+ }
+ };
+ return self;
+});
+var Sparkle = Container.expand(function () {
+ var self = Container.call(this);
+ var sparkleGraphics = self.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lifetime = 0;
+ self.maxLifetime = 60; // 1 second at 60fps
+ self.update = function () {
+ self.lifetime++;
+ self.rotation += 0.1;
+ self.alpha = 1 - self.lifetime / self.maxLifetime;
+ if (self.lifetime >= self.maxLifetime) {
+ self.destroy();
+ for (var i = sparkles.length - 1; i >= 0; i--) {
+ if (sparkles[i] === self) {
+ sparkles.splice(i, 1);
+ break;
+ }
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB // Light blue winter sky
+});
+
+/****
+* Game Code
+****/
+var tapCount = 0;
+var ginger;
+var sparkles = [];
+var snowflakes = [];
+var iceParticles = [];
+var isMagicActive = false;
+var songTimeout;
+// Progress indicator
+var progressText = new Text2('Taps: 0/9', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+progressText.anchor.set(0.5, 0);
+LK.gui.top.addChild(progressText);
+progressText.y = 100;
+// Create and position ginger character
+ginger = game.addChild(new GingerCharacter());
+ginger.x = 2048 / 2;
+ginger.y = 2732 / 2;
+function createSparkle(x, y) {
+ var sparkle = new Sparkle();
+ sparkle.x = x;
+ sparkle.y = y;
+ sparkles.push(sparkle);
+ game.addChild(sparkle);
+ // Random scale and rotation
+ sparkle.scaleX = Math.random() * 0.5 + 0.5;
+ sparkle.scaleY = sparkle.scaleX;
+ sparkle.rotation = Math.random() * Math.PI * 2;
+}
+function triggerMagicSnow() {
+ if (isMagicActive) return;
+ isMagicActive = true;
+ // Play magic sound
+ LK.getSound('magic').play();
+ // Create burst of ice particles
+ for (var i = 0; i < 20; i++) {
+ var ice = new IceParticle();
+ ice.x = ginger.x + (Math.random() - 0.5) * 200;
+ ice.y = ginger.y + (Math.random() - 0.5) * 200;
+ iceParticles.push(ice);
+ game.addChild(ice);
+ }
+ // Flash effect
+ LK.effects.flashScreen(0xFFFFFF, 500);
+ // Start singing
+ ginger.startSinging();
+ LK.getSound('littleBopeep').play();
+ // Reset after song (assuming song is about 10 seconds)
+ songTimeout = LK.setTimeout(function () {
+ ginger.stopSinging();
+ tapCount = 0;
+ isMagicActive = false;
+ updateProgressText();
+ }, 10000);
+}
+function updateProgressText() {
+ progressText.setText('Taps: ' + tapCount + '/9');
+}
+function createSnowflake() {
+ var snow = new Snowflake();
+ snow.x = Math.random() * 2048;
+ snow.y = -50;
+ snowflakes.push(snow);
+ game.addChild(snow);
+}
+game.update = function () {
+ // Create gentle snowfall during magic
+ if (isMagicActive && LK.ticks % 10 === 0) {
+ createSnowflake();
+ }
+ // Update progress text
+ if (tapCount !== parseInt(progressText.text.split(' ')[1].split('/')[0])) {
+ updateProgressText();
+ }
+ // Glow effect on ginger based on tap count
+ if (tapCount > 0) {
+ var glowIntensity = tapCount / 9;
+ ginger.alpha = 0.8 + glowIntensity * 0.2;
+ } else {
+ ginger.alpha = 1;
+ }
+};
\ No newline at end of file