User prompt
import tween and make an example animation ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Import the tween plugin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Delete all code
Initial prompt
Plugin Test
/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Define a simple class for a moving object var MovingObject = Container.expand(function () { var self = Container.call(this); var objectGraphics = self.attachAsset('object', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize an array to hold moving objects var movingObjects = []; // Create and add a moving object to the game function createMovingObject(x, y) { var newObject = new MovingObject(); newObject.x = x; newObject.y = y; movingObjects.push(newObject); game.addChild(newObject); } // Create a few moving objects at different positions createMovingObject(1024, 500); createMovingObject(512, 1000); createMovingObject(1536, 1500); // Update function to move objects game.update = function () { for (var i = 0; i < movingObjects.length; i++) { movingObjects[i].update(); } }; // Handle touch events to create new moving objects game.down = function (x, y, obj) { createMovingObject(x, y); };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a simple class for a moving object
var MovingObject = Container.expand(function () {
var self = Container.call(this);
var objectGraphics = self.attachAsset('object', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize an array to hold moving objects
var movingObjects = [];
// Create and add a moving object to the game
function createMovingObject(x, y) {
var newObject = new MovingObject();
newObject.x = x;
newObject.y = y;
movingObjects.push(newObject);
game.addChild(newObject);
}
// Create a few moving objects at different positions
createMovingObject(1024, 500);
createMovingObject(512, 1000);
createMovingObject(1536, 1500);
// Update function to move objects
game.update = function () {
for (var i = 0; i < movingObjects.length; i++) {
movingObjects[i].update();
}
};
// Handle touch events to create new moving objects
game.down = function (x, y, obj) {
createMovingObject(x, y);
};