【发布时间】:2013-04-16 05:47:05
【问题描述】:
我正在为 iOS 制作一个驾驶游戏,其中一辆汽车 (UIView) 放置在 google maps ios api 的顶部。我无法检测与地图上显示的汽车和灰色建筑物的碰撞。
我一直在尝试通过像素颜色来做到这一点,即检查汽车前面的像素颜色是否是建筑物屋顶的颜色(灰色)。无法直接访问 iPhone 的像素颜色,因此我使用谷歌地图截图方法来获取图像并从中获取像素颜色。问题是,我只能截取刚刚离开的屏幕。我在用
mapImage = [GMSScreenshot screenshotOfMainScreen];。我也尝试过获取窗口和屏幕并调用mapImage = [GMSScreenshot screenshotOfScreen:topWindow.screen]; 两者都具有相同的效果。
有什么办法可以解决这个问题?你能想出一种更好的方法来处理这种情况下的碰撞吗?反向地理编码是否能够检测建筑物的顶部和街道? 感谢您的所有帮助!
编辑: 图片: Interface Builder:左边是主菜单,右边是游戏。左上角的 Ui 图像视图设置为当前屏幕截图,以供参考。这就是我知道它关闭的方式
Game Play,如您所见,它只显示上一个菜单。
我的 viewdidLoad 函数:除此之外与获取图像有关。
- (void)viewDidLoad
{
[super viewDidLoad];
cameraPosition = CLLocationCoordinate2DMake(42.271291, -83.729918);
moveDistance = .00055;
cA = [UIColor colorWithRed:.937255 green:.921569 blue:.886275 alpha:1];
camera = [GMSCameraPosition cameraWithLatitude:cameraPosition.latitude
longitude:cameraPosition.longitude
zoom:19
bearing:0
viewingAngle:0];
mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 480, 300) camera:camera];
mapView_.myLocationEnabled = NO;
[self.view addSubview:mapView_];
car_ = [[Car alloc] initWithFrame:CGRectMake(240, 150, 13, 29) withImage:[UIImage imageNamed:@"carA-01.png"]];
[self.view addSubview:car_];
[self.view addSubview:controllerView];
updateClock = [NSTimer scheduledTimerWithTimeInterval:(1/20)
target:self
selector:@selector(update)
userInfo:nil
repeats:YES];
crashClock = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(checkCrash)
userInfo:nil
repeats:YES];
UIWindow *topWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
mapImage = [GMSScreenshot screenshotOfScreen:topWindow.screen];
// mapImage = [GMSScreenshot screenshotOfMainScreen];
}
【问题讨论】:
-
你能显示更多代码(也许还有截图)吗?只有 2 行无济于事
标签: ios objective-c google-maps-api-3 google-maps-sdk-ios