Code edit (1 edits merged)
Please save this source code
User prompt
When creating the grid spacing, make sure that you compensate for the width of the elements and also make sure the grid's center position is in the center of the screen.
Code edit (1 edits merged)
Please save this source code
User prompt
If we are using the grid, our random position should be the same for all particles, also it should be every half-time, so not at random.
Code edit (3 edits merged)
Please save this source code
User prompt
Half of the time when we press the screen, the particles should end up in the neat grid. Half of the time they should be at the random position as they are right now.
Code edit (5 edits merged)
Please save this source code
User prompt
When we press the screen and do the tweens on all the particles, use one of the different tween functions at random.
Code edit (3 edits merged)
Please save this source code
User prompt
When originally spawning the particles, make them be at a random position in a circle around the center of the screen between 0 and 500 pixels from the center.
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: null is not an object (evaluating 'clickMeText.destroy')' in or related to this line: 'clickMeText.destroy();' Line Number: 56
User prompt
Add a black text to the middle of the screen that says click me then make that Tween out of the screen when you click the screen the first time
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
On square down, tween all particles to a new random location
Code edit (1 edits merged)
Please save this source code
User prompt
Add 100 particles to the game
Code edit (4 edits merged)
Please save this source code
User prompt
Add a particle class to the game as well
Code edit (1 edits merged)
Please save this source code
User prompt
Also set Tint in between.
User prompt
Use a Bouncy Tween animation.
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'tween(self, {' Line Number: 16 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Particle = Container.expand(function () { var self = Container.call(this); var particleGraphics = self.attachAsset('particle', { anchorX: 0.5, anchorY: 0.5 }); self.tint = 0xffffff * Math.random(); particleGraphics.blendMode = 1; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ for (var i = 0; i < 200; i++) { var particle = game.addChild(new Particle()); var angle = Math.random() * Math.PI * 2; var radius = Math.random() * 200; particle.x = 1024 + Math.cos(angle) * radius; particle.y = 1366 + Math.sin(angle) * radius; particle.scale.set(5, 5); } var clickMeText = new Text2('Click Me', { size: 150, fill: 0x000000 }); clickMeText.anchor.set(0.5, 0.5); clickMeText.x = 2048 / 2; clickMeText.y = 2732 / 2; game.addChild(clickMeText); // Create a grid of positions for the particles var gridPositions = []; var gridSize = 10; var gridSpacing = 2048 / gridSize; var elementWidth = 250; // width of the particle element for (var i = 0; i < gridSize; i++) { for (var j = 0; j < gridSize; j++) { gridPositions.push({ x: i * gridSpacing + elementWidth / 2 + (2048 - gridSize * elementWidth) / 2, y: j * gridSpacing + elementWidth / 2 + (2732 - gridSize * elementWidth) / 2 }); } } game.down = function () { if (clickMeText) { tween(clickMeText, { y: -200 }, { duration: 500, easing: tween.easeIn, onFinish: function onFinish() { if (clickMeText) { clickMeText.destroy(); clickMeText = null; } } }); } var tweenFunctions = [tween.linear, tween.easeIn, tween.easeOut, tween.elasticIn, tween.elasticOut, tween.bounceIn, tween.bounceOut, tween.easeInOut, tween.bounceInOut, tween.elasticInOut]; var randomTweenFunction = tweenFunctions[Math.floor(Math.random() * tweenFunctions.length)]; var useGrid = true; //Math.random() < .5; game.children.forEach(function (child, index) { if (child instanceof Particle) { var size = Math.random() * 1; var targetPosition; // Half of the time, use a grid position, half of the time use a random position if (useGrid) { targetPosition = gridPositions[index % gridPositions.length]; } else { targetPosition = { x: Math.random() * 2048, y: Math.random() * 2732 }; } tween(child, { x: targetPosition.x, y: targetPosition.y, scaleX: size, scaleY: size, tint: Math.random() * 0xffffff }, { duration: 1000, easing: randomTweenFunction }); } }); };
===================================================================
--- original.js
+++ change.js
@@ -71,9 +71,9 @@
});
}
var tweenFunctions = [tween.linear, tween.easeIn, tween.easeOut, tween.elasticIn, tween.elasticOut, tween.bounceIn, tween.bounceOut, tween.easeInOut, tween.bounceInOut, tween.elasticInOut];
var randomTweenFunction = tweenFunctions[Math.floor(Math.random() * tweenFunctions.length)];
- var useGrid = Math.random() < .5;
+ var useGrid = true; //Math.random() < .5;
game.children.forEach(function (child, index) {
if (child instanceof Particle) {
var size = Math.random() * 1;
var targetPosition;