问题
i need help finding out why my collision code is not working. this is the code when game has started.
icon1.center = CGPointMake(60, -5000);
icon1.hidden = NO;
int randomizeicons = rand() % 4;
switch (randomizeicons) {
case 0:
icon1.image = [UIImage imageNamed:@"BerryBlueberryIphone.png"];
break;
case 1:
icon1.image = [UIImage imageNamed:@"BerryRasberryIphone.png"];
break;
case 2:
icon1.image = [UIImage imageNamed:@"BerryCherryIphone.png"];
break;
case 3:
icon1.image = [UIImage imageNamed:@"BerryStrawberryIphone.png"];
break;
}
and for collision i have this code for every berry type.
if (CGRectIntersectsRect(icon1.frame, pig.frame) && icon1.image == [UIImage imageNamed:@"BerryBlueberryIphone.png"]) {
supershieldbool = YES;
addtoeatenberrys = 2;
[self supershield];
newicon = arc4random()%320;
icon1.center = CGPointMake(newicon, -4000);
int randomizeicons = rand() % 4;
switch (randomizeicons) {
case 0:
icon1.image = [UIImage imageNamed:@"BerryBlueberryIphone.png"];
break;
case 1:
icon1.image = [UIImage imageNamed:@"BerryRasberryIphone.png"];
break;
case 2:
icon1.image = [UIImage imageNamed:@"BerryCherryIphone.png"];
break;
case 3:
icon1.image = [UIImage imageNamed:@"BerryStrawberryIphone.png"];
break;
}
}
this code was working a not to long ago and still works when running on an ipad but not iphone.
on ipad the code is the exact same except image are named BerryBlueberryIpad.png and cgpointmakes are different. the code is separated from iPhone and ipad by using this code
if (IS_IPAD)
{
//do stuff for iPad
NSLog(@"Device has a 7+inch Display.");
}
else
{
if(IS_IPHONE_5)
{
//do stuff for 4 inch iPhone screen
NSLog(@"Device has a 4.5inch.");
}
else
{
//do stuff for 3.5 inch iPhone screen
NSLog(@"Device has a 3.5inch Display.");
}
}
everything works as it should except for this part of detection. also detection works if ''&& icon1.image == [UIImage imageNamed:@"BerryBlueberryIphone.png"] is deleted from the if statement.
this code worked on both iphone and ipad but now only works on ipad. this started happening since i updated Xcode and my mac as well to the new os.
BTW, all other detection on the code works except this detection. this is the only detection that uses image imagenamed. again this detection works on ipad just not iphone.
来源:https://stackoverflow.com/questions/27930828/collision-not-working-on-iphone-just-ipad-xcode-6-1-1