Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-22-2011, 02:17 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 6
CyberTron is on a distinguished road
Default CGPoint help !!

Hi!

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

thanks
Michael
CyberTron is offline   Reply With Quote
Old 11-23-2011, 11:35 AM   #2 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

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)
rocotilos is offline   Reply With Quote
Old 11-23-2011, 01:50 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 6
CyberTron is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
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?
CyberTron is offline   Reply With Quote
Old 11-23-2011, 04:34 PM   #4 (permalink)
Registered Member
 
2WeeksToGo's Avatar
 
Join Date: Nov 2011
Posts: 227
2WeeksToGo is on a distinguished road
Default

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.

Code:
if (elephant.center.y + 20 =< table.center.y - 5) {
            Elephant.center = CGPointMake(table.center.x, table.center.y - 50);
        }
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.
2WeeksToGo is offline   Reply With Quote
Old 11-23-2011, 11:52 PM   #5 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Quote:
Originally Posted by CyberTron View Post
Thanks that is perfect, didn't really understand how it workes, but where is the frame.origin.x point located?
frame.origin.x is located at TOP LEFT.
rocotilos is offline   Reply With Quote
Old 11-26-2011, 03:14 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 6
CyberTron is on a distinguished road
Smile

Quote:
Originally Posted by rocotilos View Post
frame.origin.x is located at TOP LEFT.
I just wanted to say thanks to both of you!! I now understand how it works and how to make my "game" work! !

/Michael
CyberTron is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
16 members and 380 guests
7twenty7, chiataytuday, Clouds, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, jeroenkeij, leostc, mbadegree, Murphy, QuantumDoja, sacha1996, Sami Gh
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:34 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0