Добрый день, вчера задавала вопрос про разделение файлов Разделить код на разные файлы
не получается объекту текстуру передать
GameScene.swift
import Foundation
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate {
var number = 0
var ballReference: SKShapeNode?
override func didMoveToView(view: SKView) {
self.scene?.size = CGSize(width: 640, height: 1136)
scene?.backgroundColor = UIColor.whiteColor()
}
func ballStop(){
let position = CGPoint(x: scene!.size.width - 50, y: scene!.size.height - 50)
let ball = Ball(circleOfRadius: 25, position: position)
self.addChild(ball)
self.ballReference = ball
}
CustomScrollView.swift
import Foundation
import SpriteKit
class Ball: SKShapeNode {
init(circleOfRadius: CGFloat, position: CGPoint){
super.init()
let diameter = circleOfRadius * 2
self.path = CGPathCreateWithEllipseInRect(CGRect(origin: CGPointZero, size: CGSize(width: diameter, height: diameter)), nil)
self.strokeColor = SKColor.brownColor()
self.fillColor = SKColor.grayColor()
self.position = position
self.physicsBody = SKPhysicsBody(circleOfRadius: 25)
self.physicsBody?.affectedByGravity = false
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}}
// а свойства такие нужны:
let ball = SKShapeNode(circleOfRadius: 25)
let tex = self.view?.textureFromNode(ball)
var ballk = SKSpriteNode(texture: tex)
textureAtlasBall = SKTextureAtlas(named: "myball")
for i in 1...textureAtlasBall.textureNames.count{
let nameBall = "ball_\(i).png"
textureArrayBall.append(SKTexture(imageNamed: nameBall))
}
ballk = SKSpriteNode(imageNamed: textureAtlasBall.textureNames[0])
ballk.size = CGSize(width: 120, height: 120)
let animationWithTextureBall = SKAction.animateWithTextures(textureArrayBall, timePerFrame: 0.2)
let repeatActionForeverBall = SKAction.repeatActionForever(animationWithTextureBall)
ballk.runAction(repeatActionForeverBall)
ballk.position = CGPoint(x: scene!.size.width - 320, y: scene!.size.height - 255)
ballk.physicsBody = SKPhysicsBody(circleOfRadius: 12)
ballk.physicsBody?.categoryBitMask = PhysicsCategory.Ball1
ballk.physicsBody?.collisionBitMask = PhysicsCategory.Border | PhysicsCategory.Ball1 | PhysicsCategory.Kvadr | PhysicsCategory.Ball2 | PhysicsCategory.Ball3 | PhysicsCategory.Ball4
ballk.physicsBody?.contactTestBitMask = PhysicsCategory.Square
self.addChild(ballk)
self.ballReference = ballk
ballk.physicsBody?.affectedByGravity = false