Hi, I’m making a color match game and I am using tint on my sprite and the collectible item. Currently the sprite collects the object but I want it to only collect the object if their tints match, otherwise you lose a life.
I’ve tried an if statement to no avail. Any ideas to make this work would be greatly appreciated.
Welcome Villan,
Setting a tint on a sprite doesn’t set an overall tint property on the sprite, but instead sets a tint property on each corner of the sprite. Those properties are:
So in order to see if an image has the same tint, you will need to compare either all of the corner’s tints, or just a pair of the corner’s tints, depending on how accurate you want it.
Another way you could do it is you could extend the sprite class and override the set tint method and store your own tint property to check against other extended sprites.
This is the if statement I’m using, the score goes up on the first collection, but even if the colours match after it only runs the else if part of the code. Any ideas?
Unfortunately you cannot use that type of syntax within the if statement. As sprite.tintTopLeft may evaluate as false (Especially if the tint is black.).
Sorry friend, I figured it out. in my overlap call I had to change sprites to sprite and it worked. Again, thanks so much for your help. Now onto a different question, in my game you click a button to add a red tint to the sprite and a blue button to add blue, it changes when clicked as expected, but what I would like to do is blend the colours together to make purple, but they would still keep their normal function of adding only blue if the sprite is white. So if sprite is white and blue is clicked add blue, when sprite is blue and red is clicked change to purple. I’m assuming its more if statements on my button clicks?
I got this to work, but if the sprite is white and I click the button it just makes a darker colour, and that messes up the matching function. So when it is white and I click red, it’s a darker red and when I click blue it doesn’t mix red and blue it just becomes a dark blue. So it’s functioning how it already did, but making the colour darker. Thanks for trying.
EDIT: What I’m really trying to do is when the sprite is white and you click red it changes to red, then if you click blue, instead of changing to blue it changes to purple. So is there a way to make the sprite tint change to purple instead of mixing the colour which just made it darker?
RE-EDIT got it working as intended. Had to store tint as variable and used an array for the buttons colours and a second array for the mixed colours. So red = [0] and blue =[1] these combined equal purple[1] and so on.