swift - 构建应用程序时,SKSpritenode 未显示在模拟器或手机中
问题描述
当我在模拟器或手机中构建应用程序时,SKspritenode 未显示。
我正在关注如何在 swift/xcode 中创建移动背景的 youtube 指南。我构建时没有显示我的图像。我尝试了以下方法:
- 用 .resizeFill 替换 .aspectfill 以获得 scaleMode
- 在 imageNamed 中添加文件扩展名:“ground.png”
- 用不同的图像替换所有图像。
- 将图像移动到不同的文件夹。
class GameScene: SKScene {
var ground = SKSpriteNode()
override func didMove(to view: SKView) {
self.anchorPoint = CGPoint(x: 0.5, y: 0.5)
}
override func update(_ currentTime: CFTimeInterval) {
}
func createGrounds() {
for i in 0...3 {
let ground = SKSpriteNode(imageNamed: "green")
ground.name = "Ground"
ground.size = CGSize(width: (self.scene?.size.width)!, height: 250 )
ground.anchorPoint = CGPoint(x: 0.5, y: 0.5)
ground.position = CGPoint(x: CGFloat(i) * ground.size.width, y: -(self.frame.size.height / 2))
self.addChild(ground)
}
func moveGround() {
self.enumerateChildNodes(withName: "Ground", using: ({
(node, error) in
node.position.x -= 2
if node.position.x < -((self.scene?.size.width)!) {
node.position.x += (self.scene?.size.width)! * 3
}
}))
}
}
}
期望它根据加载的图像创建一个移动的背景。
解决方案
推荐阅读
- django - 在 Django 中保存以前的日期并添加新日期
- monaco-editor - 在 Monaco 编辑器中启用括号着色
- stm32 - 引脚不想在 PCB STM32 板上变高
- java - Flyway - 自动增量 ID 不适用于 PostgreSQL 中的测试数据
- postgresql - Postgres使用触发器在插入时转换日期格式
- c# - EF Core 1:1 关系?
- ios - 圆形 iOS 按钮在某些设备上变形
- tailwind-css - 如何删除 TALL 中的标准文件输入?
- powershell - 通过多行 Powershell 变量运行 For 循环
- python - 部署应用程序时无法使用 EmailMessage 发送电子邮件