1

ユーザーのタッチ位置にオブジェクトを作成する関数を作成しましたが、タイル マップに従って、タイルの中心に自動的に位置合わせしたいと考えています。

現在、オブジェクトを最も近いタイルに自動リダイレクトするのではなく、タッチした場所にしかオブジェクトを配置できません。

http://puu.sh/ggxOG/2785a2eeca.png (これは私のタイルが 32x32 のように見える方法です)

JSTileMap 関数

@class JSTileMap;

@interface TMXLayer : SKNode
@property (strong, nonatomic) TMXLayerInfo* layerInfo;
@property (strong, nonatomic) NSMutableSet* tileInfo;  // contains TMXTilesetInfo objects
@property (assign, nonatomic) CGSize mapTileSize;

/** Returns the width of the layer (layerGridSize.width * mapTileSize.width) */
@property (readonly,nonatomic) CGFloat layerWidth;

/** Returns the height of the layer (layerGridSize.height * mapTileSize.height) */
@property (readonly,nonatomic) CGFloat layerHeight;

/** Returns the JSTileMap that contains this layer */
@property (weak, nonatomic) JSTileMap* map;

- (CGPoint)pointForCoord:(CGPoint)coord;
- (CGPoint)coordForPoint:(CGPoint)point;

- (void)removeTileAtCoord:(CGPoint)coord;
- (SKSpriteNode*)tileAt:(CGPoint)point;
- (SKSpriteNode*)tileAtCoord:(CGPoint)coord;
- (int)tileGidAt:(CGPoint)point;
- (id)propertyWithName:(NSString*)name;
- (NSDictionary*)properties;

@end
4

1 に答える 1

2

私はこれをこの方法で解決して、最も近いタイルを取得しました。

var layer: TMXLayer = map.layerNamed("World1") // retrieve layer from tiled map
if let object = layer.tileAt(location) { // if there is a sprite(tile) at that position then set it as a var
position = object.position // update position var to the position of the sprite
}
于 2015-03-02T15:49:20.607 に答える