- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在场景中添加特定数量的方 block 。当我这样做时,广场的一部分在视野之外。是否可以在 y 轴上 move 整个场景?
最佳答案
我试过了,貌似场景本身不能 move 。另一种方法是将 SKNode 添加到代表整个世界的场景中。将所有其他元素添加到世界节点。现在如果你想 move 整个场景,你可以 move 这个节点。我正在我的博客中编写一个关于此的简短教程。这是我当前的代码:
import SpriteKit
class GameScene: SKScene {
// Declare the needed nodes
var worldNode: SKNode?
var spriteNode: SKSpriteNode?
var nodeWidth: CGFloat = 0.0
override func didMoveToView(view: SKView) {
// Setup world
worldNode = SKNode()
self.addChild(worldNode!)
// Setup sprite
spriteNode = SKSpriteNode(imageNamed: "Spaceship")
spriteNode?.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
spriteNode?.xScale = 0.1
spriteNode?.yScale = 0.1
spriteNode?.zPosition = 10
self.addChild(spriteNode!)
// Setup backgrounds
// Image of left and right node must be identical
let leftNode = SKSpriteNode(imageNamed: "left")
let middleNode = SKSpriteNode(imageNamed: "right")
let rightNode = SKSpriteNode(imageNamed: "left")
nodeWidth = leftNode.frame.size.width
leftNode.anchorPoint = CGPoint(x: 0, y: 0)
leftNode.position = CGPoint(x: 0, y: 0)
middleNode.anchorPoint = CGPoint(x: 0, y: 0)
middleNode.position = CGPoint(x: nodeWidth, y: 0)
rightNode.anchorPoint = CGPoint(x: 0, y: 0)
rightNode.position = CGPoint(x: nodeWidth * 2, y: 0)
worldNode!.addChild(leftNode)
worldNode!.addChild(rightNode)
worldNode!.addChild(middleNode)
}
var xOrgPosition: CGFloat = 0
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let xTouchPosition = touch.locationInNode(self).x
if xOrgPosition != 0.0 {
let xNewPosition = worldNode!.position.x + (xOrgPosition - xTouchPosition)
if xNewPosition <= -(2 * nodeWidth) {
// right end reached
worldNode!.position = CGPoint(x: 0, y: 0)
print("Right end reached")
} else if xNewPosition >= 0 {
// left end reached
worldNode!.position = CGPoint(x: -(2 * nodeWidth), y: 0)
print("Left end reached")
} else {
worldNode!.position = CGPoint(x: xNewPosition, y: 0)
}
}
xOrgPosition = xTouchPosition
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
// Reset value for the next swipe gesture
xOrgPosition = 0
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
关于swift - SpriteKit : Move Whole Scene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33637654/
我需要为格式为字符串的正则表达式 @% for example: 1@100%, 9@50%, 5@10%, 在@之前只能允许单个数字 数字后只有@特殊字符 @ 后的数字不得超过 3 位 只能在字符串
我正在使用 GCC 从两个 *.a(静态库)创建一个共享对象库。我引用了这些文章: How to force gcc to link an unused static library How to i
在 gcc 中使用 -Wl--whole-archive ... -Wl--no-whole-archive 标志时,您如何验证库内部的所有内容都正确链接?另外,您如何验证该库是否可以调用由 LD_L
我可以数一个物体吗?喜欢: var student1 = new Student(); student1.name("ziv"); student1.age(); student1.where("a
我想用 M 替换没有后跟 pt 的“整个”十进制数字。 例如我需要替换1、12和36.7,而不是45.63关注。 string exp = "y=tan^-1(45.63pt)+12sin(-36.7
我正在尝试通过 RegEx 进行如下验证... If Regex.IsMatch(Output, "\b" & "Serial)" & "\b") Then 'do something end if
我正在尝试在不支持 -Wl,-whole-library 标志的环境中进行编译 (emscripten)。我如何欺骗强制编译器包含导出的符号?该解决方案应尽可能多地满足以下属性: 可以应用于单个库(我
我无法弄清楚我正在阅读的书中的以下部分实际上做了什么。 //this function supposed to mimic the += operator Sales_data& Sales_data
我正在为 Excel 中的数据库开发 VBA 宏。我有一个存储诸如姓名、电子邮件等信息的工作表(遗憾的是,这些信息并没有一致地放在所有工作表的同一列中,但电子邮件地址从“B:F”跨越),这个数据库被分
是否可以在不为所有 100 条路由/防火墙规则定义的情况下为整个应用程序强制使用 https? 我们试图在网络服务器级别强制使用 https,但 symfony2 仍然尝试重定向到 http 并生成一
我定义了一个记录,其中包含许多不同类型的字段(整数、实数、字符串……加上“数组……”的动态数组)。我想将其作为一个整体保存到一个文件中,然后能够将其加载回我的程序中。我不想单独保存每个字段的值。文件类
我正在使用以下文章来验证用户的输入: http://weblogs.asp.net/monikadyrda/archive/2009/06/24/wpf-textbox-validation.aspx
我似乎找不到一种方法让 JavaScript 正则表达式匹配整个文本,而不是逐行匹配。我希望正则表达式引擎不要将 '\n' 视为文本的结尾,而是将其视为与其他字符一样的字符。 这是问题的示例: var
如果是文件结尾而不是空行,则以下代码将失败。它用于一个简单的解析器,它查找 = 符号,然后在读取空行后立即返回内容 def readFile(): keyFlag=False for
我是第一次制作静态库,我需要在 stdafx.h 中输入所有 .h 依赖项,但是有太多我不得不问是否有一些命令可以代替单独输入每个 h 文件,一次包含整个目录,如下所示: #include "lib\
我想在场景中添加特定数量的方 block 。当我这样做时,广场的一部分在视野之外。是否可以在 y 轴上 move 整个场景? 最佳答案 我试过了,貌似场景本身不能 move 。另一种方法是将 SKNo
我正在尝试使用 css 和 html 制作一个基本的下拉菜单。但是,当我将鼠标悬停在必须下拉的 li 上时,我的整个菜单都会随之下降。 这是我的代码: Home
此问题与 This question I asked yesterday. 有关现在看来,链接器标志 --whole-archive 强制将 test 对象包含在二进制文件中。然而,在链接时, g++
我目前正在编写一个基本上以这种方式构建的应用程序: 主.py + 包裹1 +--- Class1.py +--- 应用 + 套餐2 +--- Class1.py +--- 应用程序 所以我有两个问题:
我试图将 cmath 的除法函数得出的数字四舍五入为“整数”,由于程序的性质,结果通常为负数。 示例代码: strength = input("Input Strength Stat: ") str_
我是一名优秀的程序员,十分优秀!