Sprite物理学在Swift(SpriteKit)中出现,但在视觉上没有出现

问题描述 投票:-1回答:1
我设置了精灵的物理物体,zPosition,颜色,大小等,但是不会在视觉上显示。 (它具有我的精灵最高的zPosition,是的,我确实导入了SpriteKit)

let wall = SKSpriteNode() wall.physicsBody?.velocity = CGVector(dx: 0, dy: 0) //Takes screen size / width to make each piece one/(value set by "maze" at top) of the screen let width: CGFloat = (UIScreen.main.bounds.width) / CGFloat(mazeSize) let height: CGFloat = (UIScreen.main.bounds.height - 134) / CGFloat(mazeSize) //subtract so there's extra room on top+bottom of screen wall.color = UIColor(ciColor: .black) wall.isHidden = false wall.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: width, height: height)) wall.physicsBody?.restitution = 0 wall.physicsBody?.friction = 0 wall.physicsBody?.isDynamic = false wall.zPosition = 4 //sets up x+y location based on row count and which row this is on //locations (ONLY positive) let xLoc: CGFloat = ((UIScreen.main.bounds.width) / CGFloat((mazeSize/2))) * CGFloat(i/mazeSize) let yLoc: CGFloat = ((UIScreen.main.bounds.height - 134) / CGFloat(mazeSize/2)) * CGFloat(i/mazeSize) if((i/mazeSize) > (mazeSize/2)){ //if positive on x wall.position.x = xLoc } else{ //if negative on x wall.position.x = -xLoc } if(i > ((mazeSize^2)/2)){ //if positive on y wall.position.x = yLoc } else{ //if negative on y wall.position.y = yLoc }

我正在用它在迷宫中设置墙(是的,我知道x + y位置是错误的,但它们仍然“出现”在中间,丛生),但只有这些节点的物理层会显示出来。有什么方法可以使这些黑墙出现?
ios swift sprite-kit sprite maze
1个回答
0
投票
sprite节点的几何形状与物理实体的几何形状不必关联,在这种情况下,您已经制作了一个矩形物理实体,基本上是一个空的sprite节点。尝试类似的东西

let wall = SKSpriteNode(color: .black, size: CGSize(width: 100, height: 100)

或使用SKSpriteNode(texture:)初始化程序。
© www.soinside.com 2019 - 2024. All rights reserved.