- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我创建了一个带有黑色 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 = 1.0
}
最佳答案
您可以在SKSpriteNode
上使用color
属性,例如:
sprite.color = .whiteColor()
请记住,如果您的 SKSpriteNode
有纹理,您需要将 colorBlendFactor
设置为非零值才能看到您的颜色。来自SKSpriteNode
documentation在 colorBlendFactor
上:
The value must be a number between 0.0 and 1.0, inclusive. The default value (0.0) indicates the color property is ignored and that the texture’s values should be used unmodified. For values greater than 0.0, the texture is blended with the color before being drawn to the scene.
如果你想动画化颜色变化,你可以使用 SKAction
:
let colorize = SKAction.colorizeWithColor(.whiteColor(), colorBlendFactor: 1, duration: 5)
sprite.runAction(colorize)
来自SKAction
documentation在 colorizeWithColor:colorBlendFactor:duration:
This action can only be executed by an SKSpriteNode object. When the action executes, the sprite’s color and colorBlendFactor properties are animated to their new values.
关于ios - 如何快速更改 SKSpriteNode 的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31484411/
我正在创建一个游戏,用户可以在场景中移动一些水果。我希望用户只能移动场景中的水果,而不能移动场景中的任何其他 SKSpriteNode,因此我编写了下面的代码来实现它。然而,代码无法正常工作,因为我似
我正在尝试制作一款游戏,您可以倾斜手机并尝试将球保持在边界内。我似乎无法弄清楚如何让球不通过边界。我有倾斜来移动球,但它只是穿过我的所有边界,我似乎无法弄清楚如何让球在接触到边界时停止。这是我的代码:
我的代码遇到了一些问题。我正在尝试使用以下代码让僵尸跟随我的玩家: class GameScene: SKScene, SKPhysicsContactDelegate { func Enem
我正在尝试将一个 sprite 节点旋转到另一个。它旋转但不好。我该如何解决? 我试过: let blaster = self.childNode(withName: blaster) let cur
我如何获取一个 SKSpriteNode 及其所有子 SKSpriteNode 并将它们合并为一个没有子节点的扁平化 SKSpriteNode? 谢谢。 最佳答案 创建节点的纹理并从该纹理创建一个新的
对于我正在创建的游戏,SKSpriteNode 逐渐向下移动到用户屏幕上。屏幕底部附近还有另一个 SKSpriteNode(位置是静态的),只为原始 SKSpriteNode 留出一点空间。我需要检测
使用 swift,我试图让一个 SKSpriteNode(没有物理体)跟随另一个有物理体的 SKSpriteNode。当 Sprite 与一个物理体和另一个物理体接触时,我希望这样做。我阅读了有关设置
我有一条拿着蛋的龙。 EggNode 是 DragonNode 的子节点。 龙水平飞过屏幕。 当龙到达屏幕最右侧时,龙会重置到屏幕最左侧。 我已经实现了龙将鸡蛋扔到地面炮塔的位置。龙使用这个函数在to
/image/JQ9r6.png 在上面您可以看到我的游戏的图像。我有敌人生成并沿 y 轴向下移动。玩家应该在敌人到达墙壁之前将其击落。现在,玩家正在旋转到触摸的位置。我想要的是让子弹的旋转方向与旋转
我试图弄清楚 SKSpriteNode 已完全迭代另一个 SKSpriteNode。 这是我迄今为止想出的代码, if (node.frame.maxY == player.frame.minY) {
正如标题所说,有没有办法做这种事情: 有什么办法吗?如果是这样,我如何将 SKAction rotateToAngle 对应到面向圆的一侧? 谢谢! 最佳答案 圆在任何给定点的切线垂直于绘制到该点的半
对于令人困惑的问题标题,我深表歉意,但我不太确定如何表述我的问题。我的最终目标是在创建 SKSpriteNode 一定时间后删除它。但是,有一个小并发症。使用以下代码 func remove() {
我正在制作一个球必须遵循特定路径的游戏。如果它偏离正轨,他们就输了。问题是我不知道如何测试球是否偏离了路径。我尝试使用 node.intersectsNode(background) 但由于背景覆盖了
就问标题问,我想知道这是否完全可能。大多数 SKCropNode 示例使用纹理或形状。我想要完成的是自定义形状的面具。如果有办法,请告诉我! 最佳答案 您可以通过为节点提供一个子节点来屏蔽节点,其中子
这里的代码子类化 SKSpriteNode 并初始化它接受 SKScene import SpriteKit class Spaceship: SKSpriteNode{ var spaceship:
我的目标:让一个 SKSpriteNode 移动到另一个 SKSpriteNodes 的位置。 (为我的 sprite kit 游戏创建磁铁) 嗨,我正在尝试让多个同名的 SKSpriteNode 移
我正在使用 Xcode 开发应用程序,目前遇到有关 SKSpriteNodes 的问题。当有多个 SKSpriteNode 且该节点被触摸时,被触摸的节点不会被移除,但另一个未被触摸的节点会被移除。我
我有一个 SKScene,我要在其中添加一个 SKSpriteNode。我已经子类化 SKSpriteNode 类来创建这个节点。在子类中,我在 Sprite 上定义了某些 SKActions。我想要
我需要在我的项目中检测接触,但我有 9 个方 block 要检测接触。有没有一种方法可以在不创建 9 个不同的物理体或类似物理体阵列的情况下检测接触。此外,每当圆圈接触到一个正方形时,该正方形就会变色
我的游戏中有一个角色,它是一个带有几个子 SKSpriteNodes 的 SKSpriteNode,因此我可以为角色的各个部分(手、脚等)设置动画,它还有 1 个 SKSpriteNode(尝试用 S
我是一名优秀的程序员,十分优秀!