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 Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-18-2010, 11:50 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: Netherlands
Posts: 26
iphonechilly is on a distinguished road
Default Strange CGRectIntersectsRect problem

Hi,

I've got this strange collision problem.
I rotate my 'ant objects' with this piece of code, where 'absoluteDraaiHoek' is the direction in degrees:

Code:
#define DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) / 180.0 * M_PI)
CGAffineTransform cgCTM = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(absoluteDraaiHoek));
image.transform = cgCTM;
Then in the gameloop I check for collision like this:

Code:
if(CGRectIntersectsRect(tmpAnt.image.frame, player.image.frame)){
			tmpAnt.collisionWithPlayer = YES;
		}else{
			tmpAnt.collisionWithPlayer = NO;
		}
When collisionWithPlayer is true, the ant won't move.
But this results in the following situation:



As you can see the ant in the upperleft corner does not intersect with the players rect, but CGRectIntersectsRect returns true!
I suspect something is happening like the following screenshot:



Now my question is, when rotating an UIImageView, does the original frame rotate too? Or does its frame change like the second screenshot?
If so, how to handle that correctly?

Thanks in advance.
iphonechilly is offline   Reply With Quote
Old 02-18-2010, 12:47 PM   #2 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: Netherlands
Posts: 26
iphonechilly is on a distinguished road
Default

Just like I expected the frame of the UIImage changes when rotated:

Code:
2010-02-18 19:42:20.530 Ants[2982:207] FrameWidth: 61.072174, FrameHeight: 62.450989
2010-02-18 19:42:20.570 Ants[2982:207] FrameWidth: 44.031250, FrameHeight: 51.303574
Does anyone have a workaround for this?

Cheers

Edit:
I'm using smashers sollution to calculate the distance between the two center points (instead of origins):
http://www.iphonedevsdk.com/forum/50296-post2.html

Code:
for(Ant *tmpAnt in arryAnts) {
               [tmpAnt doMove];

               dx=tmpAnt.image.center.x - player.image.center.x;
               dy=tmpAnt.image.center.y - player.image.center.y;
               distance = sqrt( (dx*dx) + (dy*dy) );
               if(distance<=20){
                       tmpAnt.collisionWithPlayer = YES;
               }else{
                       tmpAnt.collisionWithPlayer = NO;
               }
       };
This works out fine for me now. I should play a little with the distance value though:


So I owe a big thanx to smasher!

Last edited by iphonechilly; 02-19-2010 at 04:57 AM.
iphonechilly is offline   Reply With Quote
Old 02-18-2010, 02:22 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: Netherlands
Posts: 26
iphonechilly is on a distinguished road
Default

I'm using smashers sollution to calculate the distance between the two center points (instead of origins):
http://www.iphonedevsdk.com/forum/50296-post2.html

Code:
for(Ant *tmpAnt in arryAnts) {  
		[tmpAnt doMove]; 
		
		dx=tmpAnt.image.center.x - player.image.center.x;
		dy=tmpAnt.image.center.y - player.image.center.y;
		distance = sqrt( (dx*dx) + (dy*dy) );
		if(distance<=20){
			tmpAnt.collisionWithPlayer = YES;
		}else{
			tmpAnt.collisionWithPlayer = NO;
		}
	};
This works out fine for me now. I should play a little with the distance value though:


So I owe a big thanx to smasher!
iphonechilly 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: 398
8 members and 390 guests
13dario13, iOS.Lover, JackReidy, jeroenkeij, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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