destroy

Destroy the sprite.

mySprite500destroy
JavaScript
(method) Sprite.destroy(effect: effects.ParticleEffect, duration: number): void;
Python
(method) Sprite.destroy(effect: effects.ParticleEffect, duration: number): None

The sprite destroys itself immediately. The sprite is removed from the game and will no longer overlap or collide with any other sprites.

Sprites will also destroy when their lifespan count reaches 0 or they have auto destroy set as a sprite flag when they move off screen.

You can also select an optional particle effect to display at the sprite when it’s destroyed.

Parameters

  • effect: an optional built-in effect to display when the sprite is destroyed.

Example

Gulp the player

Make a Player and an Enemy sprite. The player moves into the open area of the enemy sprite. When an overlap of the two is detected, destroy the Player.

PlayerEnemyspriteotherSpriteotherSprite"Gulp!"1000spritedestroysayformsonof kindoverlapsof kind1616create image widthheightyellowBlockyellowBlock001616yellowBlockPlayerspriteof kindplayer03232create image widthheightcatchBox003232catchBox06025catchBoxEnemyspriteof kindenemyscreen width16-player20setvx (velocity x)tosetrighttosetenemytodraw line infrom xyto xydraw rectangle inat xywidthheightsetcatchBoxtosetlefttosetplayertodraw rectangle inat xywidthheightfillwithsetyellowBlocktoon start

Show a destroy effect

Create a square sprite. Destroy the sprite after 3 seconds and show a fountain effect.

3232create image widthheightsquaresquare003232squarespriteof kind3000sqSpritedestroywithfountainpausemssetsqSpritetodraw rectangle inat xywidthheightfillwithsetsquaretoon start

See also

on destroyed, lifespan, set flag