我刚刚做了一个函数,创建一个对象在用户的触摸位置,但我希望它是自动对齐的瓷砖中心,根据我的瓷砖地图。
现在,我只能将对象放置在我的触摸位置,而不是自动地将其重定向到最近的瓷砖。
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发布于 2015-03-02 15:49:20
我用这种方法解决了这个问题,得到了最近的瓷砖。
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
}https://stackoverflow.com/questions/28784830
复制相似问题