此代码适用于第一个XCode 6 Beta,但在最新的Beta版本中,它无法正常运行并出现此类错误Must call a designated initializer of the superclass SKSpriteNode:
import SpriteKit
class Creature: SKSpriteNode {
var isAlive:Bool = false {
didSet {
self.hidden = !isAlive
}
}
var livingNeighbours:Int = 0
init() {
// throws: must call a designated initializer of the superclass SKSpriteNode
super.init(imageNamed:"bubble")
self.hidden = true
}
init(texture: SKTexture!) {
// throws: must call a designated initializer of the superclass SKSpriteNode
super.init(texture: texture)
}
init(texture: SKTexture!, color: UIColor!, size: CGSize) {
super.init(texture: texture, color: …Run Code Online (Sandbox Code Playgroud) 我试图检测我的精灵节点是否被触摸,我不知道从哪里开始.
let Pineapple = SKSpriteNode(imageNamed: "Pineappleimg")
Pineapple.userInteractionEnabled = true
Pineapple.position = CGPoint(x: CGRectGetMidX(self.frame) - 200, y: CGRectGetMidY(self.frame));
self.addChild(Pineapple)
Run Code Online (Sandbox Code Playgroud) 如何将SKSpriteNode带到所有其他节点的前面?
使用UIView,我可以使用bringSubviewToFront在其他视图前面显示uiview.
我是iOS和Sprite Kit编程的新手,并想知道如何组合:
-[SKAction runAction:withKey:]
Run Code Online (Sandbox Code Playgroud)
和
-[SKAction runAction:completion:]
Run Code Online (Sandbox Code Playgroud)
一方面,我想阻止一个节点再次运行相同的动作(或动作序列),另一方面,我想对一个动作的终止作出反应,但是没有方法,据我所知,无法同时使用两者.
谢谢
我正在尝试创建类,它是SKSpriteNode的子类,我想为它添加其他属性和函数.但是在第一步中我遇到了一个错误.这是我的代码:
import SpriteKit
class Ball: SKSpriteNode {
init() {
super.init(imageNamed: "ball")
}
}
Run Code Online (Sandbox Code Playgroud)
这不是编译错误,它是运行时错误.我该如何解决?
除了这里提出的问题:用SpriteKit在矩形中画一个洞?由于两者之间没有令人满意的答案,两者之间最显着的区别是这个问题需要缺少解决方法,特别是要求扭转SKCropNodes的功能.
由于孔的随机性,孔的数量以及孔要应用的物体的变化,上述问题可以解决的hacky方式的类型无法解决这个问题中的主要问题.
因此瑞士奶酪的例子如下:
想象一堆随机大小的矩形SKSpriteNodes,充满各种色调的奶酪色.
如何通过从每片奶酪中切出随机圆圈来制作瑞士奶酪?
如果SKCropNodes是圈子,他们只留下圆形的奶酪片而不是从奶酪块中切出孔.有没有办法反转SKCropNodes的行为,所以他们切换孔?
image-masking sprite-kit skspritenode skcropnode skshapenode
(这适用于XCode 6和iOS 8 beta 4)
喜欢新的SceneKit编辑器.我成功地将.sks文件中的场景加载到自定义SKScene类中.但是,它内部的对象被实例化为默认类(SKNode,SKSpriteNode等),我不知道如何绑定它们以实例化为自定义子类.
目前,我正在通过创建自定义类并链接到sprite节点作为属性来解决这个问题,这样就可以了
我创建了一个SKSpriteNode黑色的游戏,当用户触摸屏幕时,我希望将SKSpriteNode其更改为白色.我用谷歌搜索了所有可能的东西,尝试了许多不同的策略而没有运气.有谁知道如何做到这一点?
这是我的场景的代码:
var blackBird = SKSpriteNode()
override func didMoveToView(view: SKView) {
//Black Bird
var blackBirdTexture = SKTexture(imageNamed:"blackbird")
blackBirdTexture.filteringMode = SKTextureFilteringMode.Nearest
blackBird = SKSpriteNode(texture: blackBirdTexture)
blackBird.setScale(0.5)
blackBird.position = CGPoint(x: self.frame.size.width * 0.35, y:
self.frame.size.height * 0.6)
blackBird.physicsBody =
SKPhysicsBody(circleOfRadius:blackBird.size.height/2.0)
blackBird.physicsBody!.dynamic = true
blackBird.physicsBody!.allowsRotation = false
self.addChild(blackBird)
}
override func touchesBegan(touches: Set<NSObject, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
blackBird.color = .whiteColor()
blackBird.colorBlendFactor = …Run Code Online (Sandbox Code Playgroud) 我有一个SKLabelNode,它是SKSpriteNode的子代,因为我正在尝试创建一个Button类来以更简单的方式创建按钮.我已经尝试了一些使用SKSpriteNode的锚点的东西,但我不太确切地知道发生了什么.如何将标签置于精灵(它的父节点)上?
我正在尝试围绕它的Y轴旋转SKSpriteNode节点.我知道有zRotation属性,它将顺时针或逆时针旋转节点; 但是,我想围绕它自己的Y轴旋转节点(例如舞蹈芭蕾舞女演员),我似乎无法找到任何功能.这样做的最佳推荐方法是什么?
skspritenode ×10
sprite-kit ×10
ios ×4
swift ×4
objective-c ×3
ios7 ×1
rotation ×1
skcropnode ×1
sklabelnode ×1
sknode ×1
skshapenode ×1
subclass ×1
touch ×1
touchesbegan ×1
xcode ×1