首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从与JSTileMap的联系中获取最近的瓷砖?

如何从与JSTileMap的联系中获取最近的瓷砖?
EN

Stack Overflow用户
提问于 2015-02-28 17:41:49
回答 1查看 457关注 0票数 1

我刚刚做了一个函数,创建一个对象在用户的触摸位置,但我希望它是自动对齐的瓷砖中心,根据我的瓷砖地图。

现在,我只能将对象放置在我的触摸位置,而不是自动地将其重定向到最近的瓷砖。

http://puu.sh/ggxOG/2785a2eeca.png (这是我的瓷砖看起来像32x32)

JSTileMap函数

代码语言:javascript
复制
@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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-02 15:49:20

我用这种方法解决了这个问题,得到了最近的瓷砖。

代码语言:javascript
复制
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
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28784830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档