So " Main" is the name of Layout , 500 is the X and 400 is the Y .where it will be created
Now we want to create a sprite every 1 second so we can use
setInterval(() => create() , 1000);
So create() is the function we gonna call , ad the 1000 is the seconds 1000 = 1second
Now we gonna call the function to create the sprites
runOnStartup(async runtime =>
{
const player = runtime.objects.Sprite.getFirstInstance();
setInterval(() => create() , 1000);
function create(){
runtime.objects.Sprite.createInstance("Main", runtime.random() * 500 , runtime.random() * 400);
}
runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
});
Now we gonna destroy this sprite after 1 second
const player = runtime.objects.Sprite.getFirstInstance();
setInterval(() => destroy() , 1000);
function destroy(){
player.destroy();
}
Now lets work with some conditions
Lets stop to moving a sprite that has been dragging by drag and drop behaviour
Lets limit it to layout
const player = runtime.objects.Sprite.getFirstInstance();
if (player.x < 0)
player.x = 0;
if (player.y < 0)
player.y = 0;
if (player.x > runtime.layout.width)
player.x = runtime.layout.width;
if (player.y > runtime.layout.height)
player.y = runtime.layout.height;
Now lets change the animation frame if the frame = 0 lets change frame to 1
const player = runtime.objects.Sprite.getFirstInstance();
if (player.animationFrame === 0)
player.animationFrame = 1;
if (player.animationFrame === 0)
player.isVisible = false;