1
我有一個SKSpriteNode
與SKTexture
看到下面。我將我的節點的centerRect
設置爲我會告訴它向上伸展以便箭頭不會變形。該圖像是190x190 px
,我設置我的centerRect
這樣:拉伸SKSpriteNodes
CGRectMake(90/190, 90/190, 5/190, 5/190);
從我從docs明白了,這是說,每個角落90x90 px
,和3×3網格的中心矩形是5x5 px
。這意味着只有中心的5x5像素被拉伸。
但我的結果是這樣的:
我有一個叫Obstacle
類是SKSpriteNode
一個子類,當它被初始化,它上面連同圖像名稱這通過在CGRect
方法:
-(void)setTextureNamed:(NSString*)imageName centerRect:(CGRect)rect
{
// set texture for sprite
UIImage* image = [UIImage imageNamed: imageName];
SKTexture* texture = [SKTexture textureWithImage: image];
[self setTexture: texture];
// make stretchable
self.centerRect = rect;
[self setSize: texture.size];
}
而且在我SKScene
,當添加Obstacle
,該代碼被稱爲:
int bottomHeight, topHeight, topY, bottomY, max;
bottomY = 0;//_floor.size.height/2;
max = self.view.frame.size.height - _floor.size.height/2 - 2*OBSTACLE_PADDING - 2*OBSTACLE_MIN_HEIGHT;
bottomHeight = arc4random() % max + OBSTACLE_MIN_HEIGHT;
topY = bottomHeight + OBSTACLE_PADDING + _floor.size.height;
topHeight = self.view.frame.size.height - topY;
bottomY += bottomHeight/2;
topY += topHeight/2;
Obstacle *bottom = [[Obstacle alloc] initWithHeight: bottomHeight flipped: NO];
bottom.zPosition = 0;
[bottom setPosition: CGPointMake(400, bottomY)];
NSArray* objs = @[bottom, top];
for (Obstacle* o in objs)
{
o.zPosition = 2;
[self addChild: o];
[o runAction: [SKAction
moveToX: -100 duration: SPAWN_SPEED*2]
completion:^{
[o removeFromParent];
}];
}
我認爲這是因爲您將SKView呈現給viewDidLoad中的UIViewController視圖的方式。但是誰知道?我們沒有什麼信息。 –
發佈更多的代碼,而不是描述你正在嘗試做的 –
@AndreyGordeev對不起,我提出了幾個代碼塊,負責創建有問題的對象 – Chris