Intersect Command
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 35
- Joined: Sun Feb 02, 2014 12:20 am
Intersect Command
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".
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".
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Intersect Command
Have you tried leaving out "opaque"?
Good lcuk!
--sefro
Code: Select all
if intersect (image "brick", image "bird", "pixels") then
answer "You Lose"
end if
--sefro
Re: Intersect Command
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
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
-
- Posts: 35
- Joined: Sun Feb 02, 2014 12:20 am
Re: Intersect Command
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 bricksefrojonesGAda40 wrote:Have you tried leaving out "opaque"?
Good lcuk!Code: Select all
if intersect (image "brick", image "bird", "pixels") then answer "You Lose" end if
--sefro
-
- Posts: 35
- Joined: Sun Feb 02, 2014 12:20 am
Re: Intersect Command
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.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
Re: Intersect Command
How are you stopping the motion?....my bird image just moves through the brick
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Intersect Command
In my experience, using "pixels" will ignore the transparent parts of a PNG.
edit: I could be wrong about this.
edit: I could be wrong about this.
Last edited by sefrojones on Sun Apr 20, 2014 8:07 am, edited 1 time in total.
-
- Posts: 35
- Joined: Sun Feb 02, 2014 12:20 am
Re: Intersect Command
set the top of image "bird" to the top of image "bird" + 1Simon wrote:How are you stopping the motion?....my bird image just moves through the brick
Simon
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
Seems ok here.
Simon
But I guessed at the rest of you code.Simon
Last edited by Simon on Sun Apr 20, 2014 11:30 pm, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Intersect Command
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
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
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
-
- Posts: 35
- Joined: Sun Feb 02, 2014 12:20 am
Re: Intersect Command
Hey Simon, thanks for the help. My code is exactly like yours except I forgot to mention that my bird image accelerates down...as inSimon wrote:Seems ok here.But I guessed at the reset of you code.
Simon
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
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. 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).
Probably not ideal but it fixes the problem.
Simon
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. 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
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!