Cocos2d iphone 如何从平铺贴图生成平铺矩形
对于我的碰撞检测,我需要检查球矩形与任何墙矩形的相交。现在我让它工作,但它检查球的位置是否在瓷砖的GID之一,使用这个Cocos2d iphone 如何从平铺贴图生成平铺矩形,cocos2d-iphone,tiles,bounding-box,Cocos2d Iphone,Tiles,Bounding Box,对于我的碰撞检测,我需要检查球矩形与任何墙矩形的相交。现在我让它工作,但它检查球的位置是否在瓷砖的GID之一,使用这个 -(void) checkHits:(CGPoint)position { CGPoint tileCoord = [self tileCoordForPosition:position]; int tileGid = [levelLayer tileGIDAt:tileCoord]; //NSLog(@"%g",tileRect.origin);
-(void) checkHits:(CGPoint)position {
CGPoint tileCoord = [self tileCoordForPosition:position];
int tileGid = [levelLayer tileGIDAt:tileCoord];
//NSLog(@"%g",tileRect.origin);
if (tileGid) {
NSDictionary *properties = [level propertiesForGID:tileGid];
if (properties) {
NSString *collision = [properties valueForKey:@"break"];
if (collision && [collision compare:@"True"] == NSOrderedSame) {
//for blocks
//[[SimpleAudioEngine sharedEngine] playEffect:@"hit.caf"];
[levelLayer removeTileAt:tileCoord];
velocity.y *= -1;
}
if (collision && [collision compare:@"False"] == NSOrderedSame) {
//for edges
//[[SimpleAudioEngine sharedEngine] playEffect:@"hit.caf"];
velocity.y *= -1;
}
}
}
}
我需要知道如何将此更改为检查balls rect/boundingbox是否与任何具有属性中断的tiles rect/boundingboxex相交(以及如何首先获取tiles rect/boundingbox)。
另外,我正在使用平铺地图编辑器。
不久前发现了这一点:
CCSprite *tile;
for (int i = 0; i < level.contentSize.width/level.tileSize.width; i ++)
for (int j = 0; j < level.contentSize.height/level.tileSize.height; j ++){
tile = [levelLayer tileAt:ccp(i,j)];
if (CGRectIntersectsRect(ball.boundingBox, tile.boundingBox)) {
//Do whatever...
}
}
}
CCSprite*瓷砖;
for(int i=0;i
我建议使用一个碰撞层,使地图制作更容易