Created
June 11, 2019 04:46
-
-
Save PedroFarina/2d4cf29b75d51aff7b0e884419089bd1 to your computer and use it in GitHub Desktop.
SpriteNode with PhysicsBody
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SpriteNodeWithPhysics : SKNode{ | |
var nodeComImagem:SKSpriteNode? //Node que guardará nossa imagem | |
init(imageNamed:String){ | |
super.init() | |
nodeComImagem = SKSpriteNode(imageNamed: imageNamed) //Inicializador que cria um node com imagem a partir de um caminho | |
let texturaDaImagem:SKTexture? = SKTexture(imageNamed: imageNamed) //Inicializador que cria uma textura a partir de um caminho | |
guard let nodeComImagem = nodeComImagem, let textura = texturaDaImagem else{ //Garantindo que conseguimos criar nossa imagem e textura | |
fatalError("Não foi possível achar a imagem") | |
} | |
self.addChild(nodeComImagem) //Adicionando a imagem ao node | |
self.physicsBody = SKPhysicsBody(texture: textura, size: textura.size()) //Criando um PhysicBody(corpo físico) a partir de uma textura | |
} | |
public required init?(coder aDecoder: NSCoder) { | |
fatalError("Neste momento não abordaremos o uso de NSCoder.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment