Page 1 of 1
Intersect Command
Posted: Sun Apr 20, 2014 3:15 am
by ferhan24badshah
The "opaque pixels" does not function for some reason? My codes looks like this
if intersect (image "brick", image "bird", "opaque pixels" then
answer "You Lose"
end if
Both of the images are PNG Files. The image "bird" is animated to fall down while spinning until it hits the ground which is image "brick".
Re: Intersect Command
Posted: Sun Apr 20, 2014 4:48 am
by sefrojones
Have you tried leaving out "opaque"?
Code: Select all
if intersect (image "brick", image "bird", "pixels") then
answer "You Lose"
end if
Good lcuk!
--sefro
Re: Intersect Command
Posted: Sun Apr 20, 2014 5:09 am
by dunbarx
What Sefro said. I am sure he has identified your problem.
To tell you a little more about what he meant, read about the "intersect" function in the dictionary. The "opaque" keyword is really just a synonym for an alpha channel of 255. Try an alpha channel of "0", which ignores the opacity of the interior pixels, and uses only the rect of the objects. As a final test, try your original handler with two totally opaque objects. They work, no?
Craig Newman
Re: Intersect Command
Posted: Sun Apr 20, 2014 6:47 am
by ferhan24badshah
sefrojonesGAda40 wrote:Have you tried leaving out "opaque"?
Code: Select all
if intersect (image "brick", image "bird", "pixels") then
answer "You Lose"
end if
Good lcuk!
--sefro
typing in "pixels" doesn't work but typing in "0" works. But I actually wanted "opaque pixels" or "255" because I don't want the intersection to pick up the transparent parts of the png file but the opaque part (the actual image)....and neither 255 or opaque pixel work....my bird image just moves through the brick
Re: Intersect Command
Posted: Sun Apr 20, 2014 6:54 am
by ferhan24badshah
dunbarx wrote:What Sefro said. I am sure he has identified your problem.
To tell you a little more about what he meant, read about the "intersect" function in the dictionary. The "opaque" keyword is really just a synonym for an alpha channel of 255. Try an alpha channel of "0", which ignores the opacity of the interior pixels, and uses only the rect of the objects. As a final test, try your original handler with two totally opaque objects. They work, no?
Craig Newman
I actually dont want it to use the rect of the objects....i want the opaque parts of the png image to be used...I tried putting "255" but that didn't work.
Re: Intersect Command
Posted: Sun Apr 20, 2014 7:10 am
by Simon
....my bird image just moves through the brick
How are you stopping the motion?
Simon
Re: Intersect Command
Posted: Sun Apr 20, 2014 7:56 am
by sefrojones
In my experience, using "pixels" will ignore the transparent parts of a PNG.
edit: I could be wrong about this.
Re: Intersect Command
Posted: Sun Apr 20, 2014 8:01 am
by ferhan24badshah
Simon wrote:....my bird image just moves through the brick
How are you stopping the motion?
Simon
set the top of image "bird" to the top of image "bird" + 1
set the angle of image "bird" to angle of image "bird" - 1
.....if intersect( image "brick" , image "bird", "255") then
..........set the hilite of button "check" to false
..........answer "You Lose" with "okay"
.....end if
if the hilite of button "check" is true then
......send "mouseUp" to me
end if
Re: Intersect Command
Posted: Sun Apr 20, 2014 8:22 am
by Simon
Seems ok here.
But I guessed at the rest of you code.
Simon
Re: Intersect Command
Posted: Sun Apr 20, 2014 3:51 pm
by Newbie4
Sometimes when you import an image, the background is actually white pixels, not transparent ones. So the "intersect" command will detect the boundaries (square outline) before you actually touch the real object.
In those cases, use the image tools (eraser) on the LiveCode Tools Palette to erase those "white" pixels
https://sites.google.com/a/pgcps.org/li ... collisions and
https://sites.google.com/a/pgcps.org/li ... graphics-1
Re: Intersect Command
Posted: Sun Apr 20, 2014 8:06 pm
by ferhan24badshah
Simon wrote:Seems ok here.
not_bird.zip
But I guessed at the reset of you code.
Simon
Hey Simon, thanks for the help. My code is exactly like yours except I forgot to mention that my bird image accelerates down...as in
set the top of image "bird" to the top of image "bird" + text of field "speed"
and within the check if button "check" is true...
add 2 to the field of "speed"
I'm guessing what happening is that because its accelerating, its skipping through pixels when it sets the image ...and that is why it doesn't stop right when the contact is made between the bird and the floor? Is there any other way to ensure the bird goes down through every pixel while picking up speeed? Thanks
Re: Intersect Command
Posted: Sun Apr 20, 2014 11:15 pm
by Simon
Hi ferhan,
You are correct in that as it accelerates setting the loc can make it jump pixels (30 in my examle) so you can skip the intersect all together.

- look at the added rect
By adding a deceleration marker you can reduce the number of pixels jumped.
Here the rect is grc "slow" (you would turn off the border).
Code: Select all
local x
on mouseUp
add 2 to x
put x
set the hilite of button "check" to true
set the top of image "bird" to the top of image "bird" +x
set the angle of image "bird" to angle of image "bird" - 3
if intersect( grc "slow" , image "bird", "255") then
put 0 into x
end if
if intersect( image "brick" , image "bird", "255") then
set the hilite of button "check" to false
put 0 into x
answer "You Lose" with "okay"
end if
wait 5 millisec
if the hilite of button "check" is true then
send "mouseUp" to me
end if
end mouseUp
Probably not ideal but it fixes the problem.
Simon