I have started to develop my own iphone game/program. in this program I move an image below another image, I would need to say this to the program:
"if image1 is underneth the other image " then to something
then perhaps I wanna try this: if image1 is on right side of the other image" then do this.. and so on.
I have tried using: if((elephant.center.x < table.center.x)) and it kind of works, but it is not close enough to be accepted, so I need something more accurate, and I would like to say that these are the coordinates if (image1 < CGPOINT (x,y) && (x,y) || (x,y) and so on...
Hope I have made myself clear enough, otherwise ask me and I will try and tell what I need/want
For the image1 under the other image thing:
Maybe u can have some boolean that u set when you move the image under or top of the other (ie, keep track of it by yourself), then check it as necessary.
For the image1 is on right side,
Probably this is better
Code:
if ((elephant.frame.origin.x+elephant.frame.size.width) < table.frame.origin.x)
For the image1 under the other image thing:
Maybe u can have some boolean that u set when you move the image under or top of the other (ie, keep track of it by yourself), then check it as necessary.
For the image1 is on right side,
Probably this is better
Code:
if ((elephant.frame.origin.x+elephant.frame.size.width) < table.frame.origin.x)
Thanks that is perfect, didn't really understand how it workes, but where is the frame.origin.x point located?
Simply figure out how big your images are and do the math:
FOR EXAMPLE. Elephant width and height is a box 40 pixels across, and table 10 pixels across. We use a box just for this example.
This above works for my game which is one pixel accurate in high speed collisions between two objects with CGPoints. The above example will make it so that IF the elephants feet, so bottom of the frame thats why we add 20 from the center to the bottom of the image where his feet are, if his feet are.. touching or JUST below the top of the table, the elephant will be placed 50 pixels ABOVE THE table. Try it and good luck.