SpriteKitでテクスチャー同士の間に隙間が空いてしまう。
お世話になります。
textureとして、不透明な四角いpng画像を使っています。
<画像2>のように、画像ファイルは色のついた部分だけなのですが、spriteにすると、
並んだ時に<画像1>のように隙間が空いてしまいます。
隙間を設定するプロパティなどあるのでしょうか?
[GameScene.swift]
import SpriteKit
import CoreMotion
class GameScene: SKScene, SKPhysicsContactDelegate {
let ballCount = 3
let accelerationSpeed : CGFloat = 5
let textureCount : UInt32 = 4
var textures = [SKTexture]()
let texture_left = SKTexture(imageNamed: "Frame_left")
let texture_right = SKTexture(imageNamed: "Frame_right")
var motionManager: CMMotionManager!
var ballXposition : Double = 0
var ballYposition : Double = 0
var accelerationX : Double = 0
var accelerationY : Double = 0
override func didMove(to view: SKView) {
for i in 0..<textureCount {
let texture = SKTexture(imageNamed: "Ball_\(i+1)")
textures.append(texture)
}
self.physicsWorld.contactDelegate = self
self.physicsWorld.gravity = CGVector.zero
self.physicsWorld.speed = 1.0
self.size = CGSize(width: 320, height: 568)
setupObjects()
motionManager = CMMotionManager()
motionManager.accelerometerUpdateInterval = 0.1
motionManager.startAccelerometerUpdates(to: OperationQueue.main){data,_ in
self.accelerationX = data!.acceleration.x
self.accelerationY = data!.acceleration.y
}
}
func setupObjects() {
//壁
let sprite_left = SKSpriteNode(texture: texture_left)
let sprite_right = SKSpriteNode(texture: texture_right)
sprite_left.position = CGPoint(x: 80, y: 284)
sprite_right.position = CGPoint(x: 240, y: 284)
sprite_left.physicsBody = SKPhysicsBody(texture: texture_left, size: sprite_left.size)
sprite_left.physicsBody?.isDynamic = false
sprite_left.physicsBody?.categoryBitMask = 1 << 0
sprite_left.physicsBody?.contactTestBitMask = 1 << 1
sprite_left.physicsBody?.restitution = 0.9
sprite_right.physicsBody = SKPhysicsBody(texture: texture_right, size: sprite_right.size)
sprite_right.physicsBody?.isDynamic = false
sprite_right.physicsBody?.categoryBitMask = 1 << 0
sprite_right.physicsBody?.contactTestBitMask = 1 << 1
sprite_right.physicsBody?.restitution = 0.9
self.addChild(sprite_left)
self.addChild(sprite_right)
//Ball
for i in 0..<ballCount {
let textureRand = Int(arc4random_uniform(textureCount))
let ball = SKSpriteNode(texture: textures[textureRand])
ball.size = CGSize(width: 30, height: 30)
ball.position = CGPoint(x: self.size.width*0.5, y: self.size.height*0.5+CGFloat(i)*0.1)
self.addChild(ball)
ball.physicsBody = SKPhysicsBody(texture: textures[textureRand], size: CGSize(width: ball.size.width*1, height: ball.size.height*1))
ball.physicsBody?.categoryBitMask = 1 << 1
ball.physicsBody?.contactTestBitMask = 1 << 0 | 1 << 1
}
}
override func update(_ currentTime: TimeInterval) {
self.physicsWorld.gravity = CGVector(dx: CGFloat(self.accelerationX)*accelerationSpeed, dy: CGFloat(self.accelerationY)*accelerationSpeed)
}
func didBegin(_ contact: SKPhysicsContact) {
print("Contact!")
}
}
[GameViewController.swift]
import UIKit
import SpriteKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let view = self.view as! SKView? {
let scene = GameScene()
scene.size = view.frame.size
print(scene.size)
view.presentScene(scene)
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
}
//...
}
「Frame_right」はグリーンの縁の部分の画像です。