Groups | Blog | Home
all groups > flash actionscript > april 2004 >

flash actionscript : PNG transparent click issue - please help


Nicky21
4/20/2004 9:43:30 PM
Justin E-C
4/21/2004 5:15:34 AM
Nicky21
4/21/2004 7:28:03 AM
Peter Blumenthal
4/21/2004 2:26:05 PM
[quoted text, click to view]
question.

There is no actionScript that does it. It's going to have to ba manually or
not at all I'm afraid.

--
---------------------------------------
http://www.phageinteractive.com
PhageInteractive Ltd.
remove mm_ to mail
---------------------------------------
'If I come across as a grumpy and twisted old man, it's just because I'm a
grumpy, twisted, old man." - me
---------------------------------------
are a couple of hundreds of movie clips i'll have to modify,

Bart Calixto
4/21/2004 7:43:11 PM
you can use :
hitTest(_xmouse, _ymouse, true);
if you want to know if the users clicks on the transparency.
you can do something like this :

on (release) {
if (image_mc.hitTest(_xmouse, _ymouse, true)) {
trace ("clicked on image")
} else {
if (_xmouse >= image_mc._x - image_mc.width/2 and _xmouse <= image_mc._x +
image_mc.width/2 and _ymouse >= image_mc._y - image_mc.height/2 and _ymouse
<= image_mc._y + image_mc.height/2) {
trace ("clicked on the transparent pixeles")
}

or something like that! (wirted directly here so I'm not sure the AS is ok)

and check if the user clicks on
[quoted text, click to view]

Peter Blumenthal
4/22/2004 9:00:44 AM
Sorry but that's absolute rubbish. Your hitTest will evaluate to true
whether you click on the transparent area of the image or not. Try it.

--
---------------------------------------
http://www.phageinteractive.com
PhageInteractive Ltd.
remove mm_ to mail
---------------------------------------
'If I come across as a grumpy and twisted old man, it's just because I'm a
grumpy, twisted, old man." - me
---------------------------------------

Nicky21
4/22/2004 7:38:26 PM
You're right, it doesn't work. It's "true" if the coordonates are inside the
bounding rectangle regardless of the transparency.
I've come to the terms that it's simply not doable.

However, this is a BIG isue, not only checking if a click it's on the
transparency, but actually getting the color of a pixel in a bitmap (or jpeg or
whatever). I this this is a "must-have" for all the people that write games in
flash. Or should we all make our sprites as rectangular as possible ?????????
:))))))))

I wonder if macromedia is going to implement this......
Justin E-C
4/22/2004 8:48:36 PM
I do see it as a would be nice, but for game performance, the best way really
is to use a non-transparent gif or jpg and then do a break apart, cut out the
shape and use that.

Its a huge pain as far as production, but it will save some CPU cycle.
Nicky21
4/22/2004 9:18:32 PM
To my game
http://www.crea-soft.com/online-jigsaw-puzzle/
CPU time is not an issue. The hit test is only done when i click the mouse.

If there would be the need to test the hit on a cycle bases i would use first
the hitTest() to find out if it's in the rectangle then if it is, i'd use the
pixel test (which is unavalaible :(((((((( ) I've done that in another gaem and
it saved a lot of CPU time.

Huge pain in production doesn't even begin to describe what i have to do :((((
there's 50+ puzzles, 3 difficulty leavels each, on a average 25 pieces => 3750
movie clips i'll have to edit. And they keep on coming ......

Anyway, thanks everybody for all the help. I'll have to wait until macromedia
releases a new flash version or switch to macromedia director. Maybe i'll find
out that the same problem persists there, too... :)
Justin E-C
4/22/2004 9:27:38 PM
Looking at your game, which looks well done BTW, I would suggest another
solution for the future.

If you feel like coding a new engine, use the drawing API to create dynamic
masks, and make a script that draws the polygons breaking up you puzzle. that
way you can have an infinite supply of puzzles for each iamge, there would be
little production time for each new puzzle, and you would have the dynamic
drawings to hitTest again.


Nicky21
4/22/2004 9:57:42 PM
yes, that would be the best solution so far, however it's not really
practical. I use a special algorithm for cutting the edges and the sahpes, it's
in pascal and it's over 1500 lines of code. it would be painless compared to
editing 3500+ movie clips, but still too much work to convert it to
actionscript....
i just thaught of a solution. i can't really imitate the exact mask of the
image but i can generate an aproximative polygon that imitates the mask from
the pieces generator.I'll include the polygon along with the pieces. Later
using an actionscript i'll make from the polygon a mask to use with hitTest().
It ain't an exact solution but i think this is the best non time-consuming
solution so far...
Peter Blumenthal
4/22/2004 10:14:12 PM
You need to look at Director for that level of bitmap manipulation. The
hitTest method will work fine for vectors, for a given x and y coordinate
will return a hit or miss for the actual shape, but not at bitmap pixel
level at all.

--
---------------------------------------
http://www.phageinteractive.com
PhageInteractive Ltd.
remove mm_ to mail
---------------------------------------
'If I come across as a grumpy and twisted old man, it's just because I'm a
grumpy, twisted, old man." - me
---------------------------------------

AddThis Social Bookmark Button