SpriteKit 精灵无法正确缩放 [英] SpriteKit Sprites Not Scaling Properly

查看:34
本文介绍了SpriteKit 精灵无法正确缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 SpriteKit 游戏中的精灵虽然缩放得当,但在我的场景中渲染得非常小.我一直在关注一些使用类似大小的精灵的不同教程,它们在模拟器中缩放得很好.下面是一些代码片段和屏幕截图.例如,屏幕右上角的暂停按钮非常小,但资产的实际分辨率却是标准尺寸.

The sprites in my SpriteKit game, though properly scaled, are being rendered extremely small in my scenes. I've been following a few different tutorials using similarly sized sprites and theirs are scaled fine in the simulator. Below are some code snippets and screenshots. For example, the pause button on the top right of the screen is crazy small, yet the actual resolutions of the assets are standard in size.

GameScene.swift

GameScene.swift

private let pauseTex = SKTexture(imageNamed: "PauseButton")    

...

private func setupPause() {
    pauseBtn.texture = pauseTex
    pauseBtn.size = pauseTex.size()
    pauseBtn.anchorPoint = CGPoint(x: 1.0, y: 1.0)
    pauseBtn.position = CGPoint(x: size.width, y: size.height)
    pauseBtn.zPosition = Layer.Foreground.rawValue
    worldNode.addChild(pauseBtn)Btn)

    ...
}

GameVC.swift

GameVC.swift

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    ...

    if let skView = self.view as? SKView {
        if skView.scene == nil {

            let aspectRatio = view.bounds.size.height / view.bounds.size.width
            let scene = MenuScene(size: CGSize(width: 750, height: 750 * aspectRatio))

            scene.scaleMode = .aspectFill
            skView.ignoresSiblingOrder = true

            ...
        }
    }
}

推荐答案

基本上这里发生的事情是 Mike 混淆了场景大小与屏幕大小.他在想,既然精灵是 32 像素,它应该占 iPhone SE 屏幕的 10%,因为它的 1x 宽度为 320(本机为 640 [2x])但实际上,他的场景是 750 像素宽,所以它只显示为 5%.他将场景大小切换为 375x667(iPhone 6 非视网膜分辨率)以正确使用视网膜图形,现在一切都应该适合他.

Basically what has happened here is Mike got confused with scene size vs screen size. He was thinking that since the sprite was 32 pixels, it should be taking up 10% of the iPhone SE Screen since it has a 1x width of 320 (Natively it is 640 [2x]) But in reality, his scene is 750 pixels wide, so it was only showing at 5%. He switched his scene size to be 375x667 (iPhone 6 non retina resolution) to properly use the retina graphics, and now everything should be aligning up for him.

他现在会遇到的唯一问题是在 iPad 设备上裁剪.为此,他只需要在安全区域工作.

The only issue he is going to come across with now, is cropping on iPad devices. He just needs to work in safe zones for this.

这篇关于SpriteKit 精灵无法正确缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆