swift - 如何在没有 SKTexture 的情况下更改 didBeginContact 中的 SKSpriteNode 大小和颜色?

标签 swift sprite-kit swift2 skspritenode

我一直在使用 SKTexture 按以下方式在 didBeginContact 中更改 SKSpriteNode 的颜色和大小。

if firstBody.categoryBitMask == spriteCategory && secondBody.categoryBitMask == enemyCategory    {
     var newSprite = firstBody.node
     let newImage = SKTexture(imageNamed: "newSprite.png")
     (newSprite as? SKSpriteNode)?.size = newImage.size() //magic
     oldToNewSpriteAction = SKAction.setTexture(newImage)
     newSprite!.runAction(oldToNewSpriteAction)
 }

现在我正在创建一个没有 SKTextures 的示例代码,按以下方式设置我的 SKSpriteNodes:

oldSprite = SKSpriteNode(color: SKColor.blueColor(), size: oldSpriteSize)
newSprite = SKSpriteNode(color: SKColor.BrownColor(), size: newSpriteSize)

如何在没有 SKTextures 的情况下更改 didBeginContact 中的 Sprite 颜色和大小?

最佳答案

这应该可行

newSprite.color = UIColor.redColor()
newSprite.size = CGSize(width: 250, height: 250)

关于swift - 如何在没有 SKTexture 的情况下更改 didBeginContact 中的 SKSpriteNode 大小和颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34728116/

相关文章:

ios - 静态 TableViewCell 中的 UICollectionView

xcode - 如何在触摸对象时运行 Score Label?

swift - 实现符合 Hashable 协议(protocol)的通用结构。错误 : Refernce to generic type 'strA' requires arguments in <. ..> 错误

ios - Swift AFNetworking POST 错误

ios - 具有透明背景的 Swift 模态视图 Controller

swift - fatal error : Unexpectedly found nil while

ios - 使用代码创建约束 - 出现错误 "Unable to simultaneously satisfy constraints"

ios - 我如何有效地为 100 多个 View Controller 使用多个 Storyboard?

ios - SKSpriteNode 来自图像触摸检测

ios - 从另一个文件中的 SKScene 中删除 UIView