美文网首页
SpriteKit--SKNode+Frame

SpriteKit--SKNode+Frame

作者: lionnner | 来源:发表于2017-11-13 17:17 被阅读31次

SKNode(及其子类)的布局是以 position 跟 anchorPoint(子类含有) 相结合

不适用于SKLableNode

#import <SpriteKit/SpriteKit.h>

@interface SKNode (Frame)

@property (nonatomic, readonly) CGFloat sk_left;

@property (nonatomic, readonly) CGFloat sk_right;

@property (nonatomic, readonly) CGFloat sk_top;

@property (nonatomic, readonly) CGFloat sk_bottom;

@property (nonatomic, readonly) CGFloat sk_width;

@property (nonatomic, readonly) CGFloat sk_height;

@property (nonatomic, readonly) CGFloat sk_posX;

@property (nonatomic, readonly) CGFloat sk_posY;

@end
#import "SKNode+Frame.h"

@implementation SKNode (Frame)

- (CGFloat)sk_left
{
    return self.frame.origin.x;
}

- (CGFloat)sk_right
{
    return self.frame.origin.x + self.frame.size.width;
}

- (CGFloat)sk_top
{
    return self.frame.origin.y + self.frame.size.height;
}

- (CGFloat)sk_bottom
{
    return self.frame.origin.y;
}

- (CGFloat)sk_width
{
    return self.frame.size.width;
}

- (CGFloat)sk_height
{
    return self.frame.size.height;
}

- (CGFloat)sk_posX
{
    return self.position.x;
}

- (CGFloat)sk_posY
{
    return self.position.y;
}
@end

相关文章

  • SpriteKit--SKNode+Frame

    SKNode(及其子类)的布局是以 position 跟 anchorPoint(子类含有) 相结合 不适用于SK...

网友评论

      本文标题:SpriteKit--SKNode+Frame

      本文链接:https://www.haomeiwen.com/subject/dpizmxtx.html