Can someone be kind and try the following code and images?
SetImageMask only works with "Brick_hole.png", the others is not working.
The images that are supposed to "mask", make holes in the destination image is completely transparent, and the remaining pixels are white. (RGB 255,255,255)
But as I said, it works only with one of the pictures ???
What have I missed?
// Code from - http://forum.thegamecreators.com/?m=forum_view&t=197260&b=41
// Project: SetImageMask_test1
// Created: 2015-05-16
// set window properties
SetWindowTitle( \"SetImageMask_test1\" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
` load in and separate the
` bullethole and bricks
SetFolder(\"/media\")
MyImg = LoadImage(\"Brick_hole.png\")
BombImg = loadImage(\"bomb_mask.png\")
BulletImg = CopyImage(MyImg, 0, 0, 64, 64)
BrickImg = CopyImage(MyImg, 64, 0, 64, 64)
bulletSprite = CreateSprite(BulletImg)
SetSpritePosition(bulletSprite, 100,100)
brickSprite = CreateSprite(BrickImg)
SetSpritePosition(brickSprite, 100, 100)
bombSprite = CreateSprite(BombImg)
SetSpritePosition(bombSprite, 250, 250)
MyImg_3 = LoadImage(\"greensquare.png\")
greenBox = CopyImage(MyImg_3, 0, 0, 16, 16)
mask = CopyImage(MyImg_3, 16, 0, 16, 16)
greenSprite = CreateSprite(greenBox)
SetSpritePosition(greenSprite, 400, 400)
maskSprite = createSprite(mask)
SetSpritePosition(maskSprite, 500, 500)
Do
Print(\"Tap to shoot\")
If GetRawMouseLeftPressed()
SetImageMask(BrickImg, bulletSprite, 4, 4, 0, 0) // This line works!
//SetImageMask(BrickImg, BulletImg, 4, 4, 0, 0) // and this works!
//SetImageMask(BrickImg, BombImg, 4, 4, 0, 0) // This does not work!
// The white pixels are visible, and the brick picture behind is visible, // it should, however, have become a black hole. Why ??
// SetImageMask(greenBox, mask, 4, 4, 0, 0) // This does not work!
SetImageMask(greenBox, mask, 2, 2, 0, 0) // This line works - green channel.
endif
Sync()
Loop
Has fixed the source code and put all the images in the same image.
Think I've got a little hang of this now!
Here comes a new test source.
// set window properties
SetWindowTitle( "SetImageMask_test1" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
// load in and separate the images
SetFolder("/media")
MyImg = LoadImage("Brick_hole.png")
bigBulletImg = CopyImage(MyImg, 0, 0, 64, 64) // Bullet hole
brickImg = CopyImage(MyImg, 64, 0, 64, 64) // Bricks
greenBox = CopyImage(MyImg, 128, 0, 32, 16) // Little Green box.
whiteCross = CopyImage(MyImg, 128, 16, 16, 16) // White cross
bombMask = CopyImage(MyImg, 128, 32, 8, 8) // white bomb mask
// To view the images separately,
// to see clearly what is happening,
// and which pictures are used.
bulletSprite = CreateSprite(bigBulletImg)
SetSpritePosition(bulletSprite, 64, 64)
brickSprite = CreateSprite(brickImg)
SetSpritePosition(brickSprite, 64, 128)
greenSprite = CreateSprite(greenBox)
SetSpritePosition(greenSprite, 64, 192)
crossSprite = CreateSprite(whiteCross)
SetSpritePosition(crossSprite, 64, 208)
bombSprite = CreateSprite(bombMask)
SetSpritePosition(bombSprite, 64, 224)
Do
Print("Tap to shoot")
If GetRawMouseLeftPressed()
SetImageMask(BrickImg, bigBulletImg, 4, 4, 0, 0) // This line works!
SetImageMask(BrickImg, bombMask, 4, 4, 0, 0) // This works!
// This one only works with "source channel 2",
// and every one of the "destination channel".
// This line only works with the green source channel!
SetImageMask(greenBox, bombMask, 2, 4, 0, 0)
// This one also only works with "source channel 2",
// and every one of the "destination channel".
// This line only works with the green source channel.
SetImageMask(greenBox, whiteCross, 2, 4, 16, 0)
endif
Sync()
Loop