首页 热点专区 小学知识 中学知识 出国留学 考研考公
您的当前位置:首页正文

SpriteKit--SKNode+Frame

2024-12-06 来源:要发发知识网

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
显示全文