UNPKG

pxt-common-packages

Version:
69 lines (56 loc) 2.16 kB
# equals Compare this image to another image to see if they are the same. ```sig image.create(0, 0).equals(null) ``` Each pixel in the image is compared with another image. If all the pixels in both images are identical, then the images are considered "equal". ## Parameters * **other**: the other image to compare this one to. ## Returns * a [boolean](/types/boolean) value that is `true` if all of the pixels in the two images are identical, or a value of `false` otherwise. ## Example #example Create sprite with using a `burger` image. Create just an image of the same burger using a variable. Compare that image with the image in the sprite to see if they are equal. ```blocks let mySprite = sprites.create(img` . . . . c c c b b b b b . . . . . . c c b 4 4 4 4 4 4 b b b . . . c c 4 4 4 4 4 5 4 4 4 4 b c . . e 4 4 4 4 4 4 4 4 4 5 4 4 e . e b 4 5 4 4 5 4 4 4 4 4 4 4 b c e b 4 4 4 4 4 4 4 4 4 4 5 4 4 e e b b 4 4 4 4 4 4 4 4 4 4 4 b e . e b 4 4 4 4 4 5 4 4 4 4 b e . 8 7 e e b 4 4 4 4 4 4 b e e 6 8 8 7 2 e e e e e e e e e e 2 7 8 e 6 6 2 2 2 2 2 2 2 2 2 2 6 c e e c 6 7 6 6 7 7 7 6 6 7 6 c c e e b e 8 8 c c 8 8 c c c 8 e b e e e b e c c e e e e e c e b e e . e e b b 4 4 4 4 4 4 4 4 e e . . . . c c c c c e e e e e . . . `, SpriteKind.Food) let burger = img` . . . . c c c b b b b b . . . . . . c c b 4 4 4 4 4 4 b b b . . . c c 4 4 4 4 4 5 4 4 4 4 b c . . e 4 4 4 4 4 4 4 4 4 5 4 4 e . e b 4 5 4 4 5 4 4 4 4 4 4 4 b c e b 4 4 4 4 4 4 4 4 4 4 5 4 4 e e b b 4 4 4 4 4 4 4 4 4 4 4 b e . e b 4 4 4 4 4 5 4 4 4 4 b e . 8 7 e e b 4 4 4 4 4 4 b e e 6 8 8 7 2 e e e e e e e e e e 2 7 8 e 6 6 2 2 2 2 2 2 2 2 2 2 6 c e e c 6 7 6 6 7 7 7 6 6 7 6 c c e e b e 8 8 c c 8 8 c c c 8 e b e e e b e c c e e e e e c e b e e . e e b b 4 4 4 4 4 4 4 4 e e . . . . c c c c c e e e e e . . . ` if (burger.equals(mySprite.image)) { mySprite.sayText("I'm a burger!", 2000, false) } ``` ## See Also #seealso [clone](/reference/images/image/clone), [get pixel](/reference/images/image/get-pixel)