SpriteKit解坑系列(三):投影Label

身为游戏引擎,投影文本框都没有,垃圾!

//
//  MSShadowLabel.h
//  MagicSword
//
//  Created by Netease on 15/12/2.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import <SpriteKit/SpriteKit.h>

@interface MSShadowLabel : SKLabelNode

- (void)setShadowColor:(UIColor *)color;
- (void)setShadowOffset:(CGSize)offset;
- (void)setShadowOpacity:(CGFloat)opacity;
- (void)setShadowHidden:(BOOL)isHidden;

@end

//
//  MSShadowLabel.m
//  MagicSword
//
//  Created by Netease on 15/12/2.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import "MSShadowLabel.h"

@implementation MSShadowLabel {
    SKLabelNode *_dropLabel;
    SKLabelNode *_dropShadow;
}

- (id)initWithFontNamed:(NSString *)fontName {
    self = [super initWithFontNamed:fontName];
    if (self) {
        _dropLabel = [[SKLabelNode alloc] initWithFontNamed:fontName];
        [_dropLabel setPosition:CGPointMake(0, 0)];
        [_dropLabel setFontSize:self.fontSize];
        [_dropLabel setFontColor:[UIColor whiteColor]];
        [_dropLabel setZPosition:2];
        [self addChild:_dropLabel];
        
        _dropShadow = [[SKLabelNode alloc] initWithFontNamed:fontName];
        [_dropShadow setPosition:CGPointMake(1, -1)];
        [_dropShadow setFontSize:self.fontSize];
        [_dropShadow setFontColor:[UIColor blackColor]];
        [_dropShadow setZPosition:1];
        [self addChild:_dropShadow];
    }
    return self;
}

- (void)setShadowColor:(UIColor *)color {
    [_dropShadow setFontColor:color];
}
- (void)setShadowOffset:(CGSize)offset {
    [_dropShadow setPosition:CGPointMake(offset.width, -offset.height)];
}
- (void)setShadowOpacity:(CGFloat)opacity {
    [_dropShadow setAlpha:opacity];
}
- (void)setShadowHidden:(BOOL)isHidden {
    [_dropShadow setHidden:isHidden];
}

- (void)setText:(NSString *)text {
    [_dropLabel setText:text];
    [_dropShadow setText:text];
}

- (void)setFontSize:(CGFloat)fontSize {
    [_dropLabel setFontSize:fontSize];
    [_dropShadow setFontSize:fontSize];
}

- (void)setFontColor:(UIColor *)fontColor {
    [_dropLabel setFontColor:fontColor];
}

- (void)setPosition:(CGPoint)position {
    [super setPosition:position];
}

- (void)setHorizontalAlignmentMode:(SKLabelHorizontalAlignmentMode)horizontalAlignmentMode {
    [_dropLabel setHorizontalAlignmentMode:horizontalAlignmentMode];
    [_dropShadow setHorizontalAlignmentMode:horizontalAlignmentMode];
}

- (void)setVerticalAlignmentMode:(SKLabelVerticalAlignmentMode)verticalAlignmentMode {
    [_dropLabel setVerticalAlignmentMode:verticalAlignmentMode];
    [_dropShadow setVerticalAlignmentMode:verticalAlignmentMode];
}

- (void)setName:(NSString *)name {
    [super setName:name];
    [_dropLabel setName:name];
    [_dropShadow setName:name];
}
@end


你可能感兴趣的:(SpriteKit解坑系列(三):投影Label)