衝突検出のために、ボールの四角形が壁の四角形と交差していることを確認する必要があります。今は動作していますが、これを使用して、ボールの位置がタイルの GID の 1 つにあるかどうかを確認しています。
-(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;
}
}
}
}
これを変更して、ボール rect/boundingbox がプロパティ break を持つタイル rects/boundingboxex (および最初にタイル rect/boundingbox を取得する方法) と交差するかどうかを確認する方法を知る必要があります。PS タイル マップ エディターを使用しています。