Add isDeleted (#2445)

This commit is contained in:
Franklin Tse 2019-09-25 20:47:25 +08:00 committed by Peli de Halleux
parent a10a69b96c
commit 19dffde1a8
4 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,33 @@
# Is Deleted
Find out if the sprite is deleted from the game engine or not.
```sig
game.createSprite(0,0).isDeleted()
```
## Returns
* a [boolean](/types/boolean) value that is `true` if the sprite is deleted from the game engine or `false` if not.
## Example
This game has 5 sprites initially. After 1 second, the third sprite is deleted and all remaining sprites are moved by 1.
```blocks
let sprites: game.LedSprite[] = []
for (let i = 0; i <= 4; i++) {
sprites.push(game.createSprite(0, i))
}
basic.pause(1000)
sprites[2].delete()
for (let sprite of sprites) {
if (!(sprite.isDeleted())) {
sprite.move(1)
}
}
```
## See also
[delete sprite](/reference/game/delete)

View File

@ -281,6 +281,7 @@
"game.LedSprite.goTo|param|x": "TODO",
"game.LedSprite.goTo|param|y": "TODO",
"game.LedSprite.ifOnEdgeBounce": "If touching the edge of the stage and facing towards it, then turn away.",
"game.LedSprite.isDeleted": "Reports whether the sprite has been deleted from the game engine.",
"game.LedSprite.isTouching": "Reports true if sprite has the same position as specified sprite",
"game.LedSprite.isTouchingEdge": "Reports true if sprite is touching an edge",
"game.LedSprite.isTouching|param|other": "the other sprite to check overlap or touch",

View File

@ -266,6 +266,7 @@
"game.LedSprite.delete|block": "delete %this(sprite)",
"game.LedSprite.get|block": "%sprite|%property",
"game.LedSprite.ifOnEdgeBounce|block": "%sprite|if on edge, bounce",
"game.LedSprite.isDeleted|block": "is %sprite|deleted",
"game.LedSprite.isTouchingEdge|block": "is %sprite|touching edge",
"game.LedSprite.isTouching|block": "is %sprite|touching %other",
"game.LedSprite.move|block": "%sprite|move by %leds",

View File

@ -695,7 +695,7 @@ namespace game {
* Deletes the sprite from the game engine. The sprite will no longer appear on the screen or interact with other sprites.
* @param this sprite to delete
*/
//% weight=59 help=game/delete
//% weight=59 blockGap=8 help=game/delete
//% blockId="game_delete_sprite" block="delete %this(sprite)"
public delete(): void {
this._enabled = false;
@ -703,6 +703,15 @@ namespace game {
plot();
}
/**
* Reports whether the sprite has been deleted from the game engine.
*/
//% weight=58 help=game/is-deleted
//% blockId="game_sprite_is_deleted" block="is %sprite|deleted"
public isDeleted(): boolean {
return !this._enabled;
}
/**
* Sets the blink duration interval in millisecond.
* @param sprite TODO