SpriteKit,Swift - ScrollView不显示

时间:2016-01-09 17:44:18

标签: ios swift menu uiscrollview sprite-kit

好的,所以我使用这个方法实现了一个scrollview:

How to create a vertical scrolling menu in spritekit?

现在,当我启动场景时,除了黑色/灰色背景外,它不会显示任何内容

以下是我在菜单场景中使用的代码:

import Foundation
import SpriteKit
import UIKit

//let kMargin: CGFloat = 40

//var backButton = SKSpriteNode()
//var selectButton = SKSpriteNode()
var moveableNode = SKNode()
var scrollView: CustomScrollView!
private var imageSize = CGSize.zero

var sprite = SKSpriteNode()

class Menu: SKScene {

func didMoveToView() {

    addChild(moveableNode)

    scrollView = CustomScrollView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height), scene: self, moveableNode: moveableNode)
    scrollView.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height * 2)
    view!.addSubview(scrollView)

    sprite =  SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 44))
    sprite.position.y = CGRectGetMidY(self.frame) + self.frame.size.height
    moveableNode.addChild(sprite)

  }

}

这可能是非常明显但我似乎无法看到它。

2 个答案:

答案 0 :(得分:0)

尝试使用sprite,我在另一个问题上犯了一个错误,它应该是 - self.frame.size.height,而不是+。

 sprite = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 50, height: 44))
 sprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) - self.frame.size.height)
 moveableNode.addChild(sprite)

检查我的gitHub项目

https://github.com/crashoverride777/Swift-2-SpriteKit-UIScrollView-Helper

答案 1 :(得分:0)

精灵位置不对,不确定你想要它在哪里。我执行以下操作,精灵显示在视图上。

sprite.position = CGPoint(x: 200, y: 200)

// To make it a center of the view
sprite.position = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2)