我有一个由SKShapeNode创建的shapeNodeWithRect: cornerRadius:。这个四舍五入的矩形是SKEffectNode的一个子元素,所以我可以设置shouldRasterize = YES。
我想根据用户的触摸更改此节点的宽度。也就是说,当他们的手指水平地向右移动时,直指会变大(当他们把手指向左移动时会变小)。
SKShapeNode替换为新的大小(但这是不好的)。SKEffectNode和SKShapeNode上运行一个调整大小的操作(但这不起作用,因为调整大小只适用于SKSpriteNotes[SKAction Apple -调整大小]):[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的框架).
发布于 2017-12-10 00:30:49
创建大尺寸的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
}
}在目标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;
}
@endhttps://stackoverflow.com/questions/29374852
复制相似问题