我SKShapeNode
创建了shapeNodeWithRect: cornerRadius:
。这个舍入的rect是SKEffectNode的子项,因此我可以设置shouldRasterize = YES
。
我想根据用户的触摸更改此节点的宽度。即当他们将手指水平向右移动时,矩形会变大(当它们向左移动时会变小)。
SKShapeNode
来做到这一点(但这很糟糕)。 SKEffectNode
和SKShapeNode
执行调整大小操作(但这不起作用,因为调整大小仅适用于SKSpriteNotes
{{3} }): [self runAction:[SKAction resizeToWidth:newSize.width height:newSize.height duration:0]];
[self.shapeNode runAction:[SKAction resizeToWidth:newSize.width height:newSize.height duration:0]];
SKShapeNode
会变得像素化。我该怎么做?
在UIKit中这么容易(只需设置UIView的框架)......
答案 0 :(得分:0)
创建大尺寸的SKShapeNode
个对象,然后立即缩小它们。如果你这样做,你不应该遇到模糊或像素化的节点。
在Swift 4.0中:
class GameScene: SKScene {
var roundedRect: SKShapeNode!
didMove(to view: SKView) {
roundedRect = SKShapeNode(rect: Constants.RoundedRect.largeInitialRect, cornerRadius: Constants.Rect.largeInitialCornerRadius)
// configure roundedRect
addChild(roundedRect)
scaleRoundedRect
}
func scaleRoundedRect(to size: CGSize) {
roundedRect.xScale = roundedRect.xScale / frame.width * size.width
roundedRect.yScale = roundedRect.yScale / frame.height * size.height
}
}
在Objective-C中:
@implementation GameScene
- (void) didMoveToView:(SKView *)view {
CGRect largeRect = CGRectMake(0, 0, 0, 0); // replace with your own values
CGFloat largeCornerRadius = (CGFloat) 0; // replace with your value
_roundedRect = [SKShapeNode shapeNodeWithRect:largeRect cornerRadius:largeCornerRadius];
CGSize initialSize = CGSizeMake(0, 0); // replace with your value
[self scaleRoundedRectToSize:initialSize];
}
- (void) scaleRoundedRectToSize:(CGSize)size {
_roundedRect.xScale = _roundedRect.xScale / _roundedRect.frame.size.width * size.width;
_roundedRect.yScale = _roundedRect.yScale / _roundedRect.frame.size.height * size.height;
}
@end