Intersect Command

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Intersect Command

Post by ferhan24badshah » Sun Apr 20, 2014 3:15 am

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".

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Intersect Command

Post by sefrojones » Sun Apr 20, 2014 4:48 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Intersect Command

Post by dunbarx » Sun Apr 20, 2014 5:09 am

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

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: Intersect Command

Post by ferhan24badshah » Sun Apr 20, 2014 6:47 am

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

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: Intersect Command

Post by ferhan24badshah » Sun Apr 20, 2014 6:54 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Intersect Command

Post by Simon » Sun Apr 20, 2014 7:10 am

....my bird image just moves through the brick
How are you stopping the motion?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Intersect Command

Post by sefrojones » Sun Apr 20, 2014 7:56 am

In my experience, using "pixels" will ignore the transparent parts of a PNG.

edit: I could be wrong about this.
Last edited by sefrojones on Sun Apr 20, 2014 8:07 am, edited 1 time in total.

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: Intersect Command

Post by ferhan24badshah » Sun Apr 20, 2014 8:01 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Intersect Command

Post by Simon » Sun Apr 20, 2014 8:22 am

Seems ok here.
not_bird.zip
LC 6.5
(1.57 KiB) Downloaded 255 times
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!

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: Intersect Command

Post by Newbie4 » Sun Apr 20, 2014 3:51 pm

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
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/

ferhan24badshah
Posts: 35
Joined: Sun Feb 02, 2014 12:20 am

Re: Intersect Command

Post by ferhan24badshah » Sun Apr 20, 2014 8:06 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Intersect Command

Post by Simon » Sun Apr 20, 2014 11:15 pm

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.
2014-04-20_1507.png
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply