samiwistler July 19th, 2015 Hi all,
I am developing a game with wade and i have a rect image of a fairy. The fairy is not rect (...), and i want the event launched when a monster touches its body or wings.
The question is, how can i add image map to a sprite?
I attached the fairy pix for you to try...
Thanks,
Samuel
Gio July 19th, 2015 Hi
If you call Sprite.getImageData() you can get the image data as an array of values (4 values per pixel: red, green, blue and alpha). However getImageData is slow. You want to do it only once when you initialize the game, after you're finished loading your images.
So for example in wade.app.init you can do this:
myImageData = mySprite.getImageData();
Then later on, when your object is clicked, so in your object's onMouseDown function, you can check if the point that was clicked is transparent (check the alpha value of the pixel that was clicked), and if so, discard it:
myObject.onMouseDown = function(eventData){ if (myImageData.data[(eventData.position.x + eventData.position.y * myImageData.width) * 4 + 3] == 0) { return false; } // if you get here, a non-transparent pixel was clicked}