屏幕的实际尺寸比我看到的要大 [英] Screen's real size is bigger than what I see
问题描述
我正在学习Swift& amp; SpriteKit。
我创建了新的SpriteKit& Xcode 6中的Swift游戏项目和我编辑的文件 GameScene.swift
。我没有碰到其他文件。
问题:当球反弹时,它受到顶部和下部的限制,但当它向左侧或右侧时,它不受限制并且熄灭但似乎左右限制在那里,但它们不是'在屏幕边缘,因为球在一段时间后回来了。
这是我的 GameScene.swift
:
I'm learning both Swift & SpriteKit.
I created new SpriteKit & Swift game project in Xcode 6 and I edited file GameScene.swift
. I didn't touch other files.
The problem: When the ball bounces around, It's limited by top and down side but when it goes to left or right side it's not limited and goes out but it seems that the right and left limits are there but they aren't on screen edge because ball comes back after a little while.
This is my GameScene.swift
:
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
self.backgroundColor = SKColor.whiteColor()
self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
self.physicsWorld.gravity = CGVectorMake(0, 0)
let ball = SKSpriteNode(imageNamed: "ball")
ball.position = CGPointMake(self.size.width/2, self.size.height/2)
ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.frame.size.width/2)
self.addChild(ball)
var myVector = CGVectorMake(20, 20)
ball.physicsBody.applyImpulse(myVector)
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
我试图找出问题,我发现如果我在默认 GameViewController.swift
中注释第42行或 scene.scaleMode = .AspectFill
然后边缘工作正确但似乎是屏幕缩放。
I tried to find out the issue and I found that if I comment the line 42 or scene.scaleMode = .AspectFill
in default GameViewController.swift
then edges work correct but it seems the screen is scaled.
我认为我们有一个真实的方形框架,侧面尺寸等于iOS模拟器中纵向iPhone的高度。
如何更改帧大小以将屏幕边缘设置为我的边缘?
I think we have a real frame of shape square and the side size is equal to height of portrait iPhone in iOS Simulator. How I can change the frame size to set screen edges as my frame edge?
推荐答案
我删除了由默认和添加行 scene = GameScene(size:self.view.frame.size)
并且它有效!
感谢@Literphor
I removed scene created by default and added line scene = GameScene(size: self.view.frame.size)
and It worked!
Thanks to @Literphor
这篇关于屏幕的实际尺寸比我看到的要大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!