This file contains hidden or 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
extension GameScene: SKPhysicsContactDelegate{ | |
func didBegin(_ contact: SKPhysicsContact) { | |
if (contact.bodyA.node?.name == "ball" && contact.bodyB.node?.name == "snareND") || (contact.bodyA.node?.name == "snareND" && contact.bodyB.node?.name == "ball"){ | |
//quando a bola entra em contato com o bloco um som é tocado. | |
run(snareSound) | |
} | |
} | |
} |
This file contains hidden or 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
//criando corpo 2 que é em formato de retângulo | |
let element = SKShapeNode(rectOf: CGSize(width: 100, height: 40)) | |
element.position = CGPoint(x: 100 ,y: 100) | |
element.fillColor = .green | |
element.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 100, height: 40)) | |
//diz que esse objeto não é movido pela simulação, ele fica parado. | |
element.physicsBody?.isDynamic = false | |
//setando as configurações de colisão | |
element.physicsBody?.categoryBitMask = 1 | |
element.physicsBody?.collisionBitMask = 2 |
This file contains hidden or 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
//criando o corpo 1 que é em formato de circulo. | |
let element = SKShapeNode(circleOfRadius: 10) | |
element.position = CGPoint(x: 100 ,y: 140) | |
element.fillColor = .yellow | |
element.physicsBody = SKPhysicsBody(circleOfRadius: 10) | |
//setando configurações de colisão | |
element.physicsBody?.restitution = 1 | |
element.physicsBody?.categoryBitMask = 2 | |
element.physicsBody?.collisionBitMask = 1 |
This file contains hidden or 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
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { | |
for touch in touches{ | |
if objTouched != nil{ | |
//reaproveitando a variavel utilizada em touchesBegan | |
if touch as UITouch == objTouched!{ | |
let location = touch.location(in: self) | |
var touchedNode = nodes(at: location) | |
touchedNode.first?.position = location | |
} | |
} |
This file contains hidden or 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
//vamos declarar | |
var objTouched: UITouch? | |
... | |
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { | |
for touch in touches{ | |
let touchlocation = touch.location(in: self) | |
//armazenamos o objeto que foi tocado |
This file contains hidden or 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
//carregando os sons | |
var snareSound = SKAction.playSoundFileNamed("snare.mp3", waitForCompletion: false) | |
var kikSound = SKAction.playSoundFileNamed("kik.mp3", waitForCompletion: false) | |
var hihatSound = SKAction.playSoundFileNamed("hihat.mp3", waitForCompletion: false) | |
... | |
//executando o som | |
run(hihatSound) | |
run(kikSound) |
This file contains hidden or 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
//trecho de código que faz um elemento piscar 5 vezes | |
var fadeOut = SKAction.fadeAlpha(to: 0.2, duration: 0.2) | |
var fadeIn = SKAction.fadeAlpha(to: 1, duration: 0.2) | |
element.run(SKAction.repeat(SKAction.sequence([fadeOut, fadeIn]), count: 5)) |
This file contains hidden or 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
element.fillColor = .yellow |
This file contains hidden or 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
element.position = CGPoint(x: 100 ,y: 100) |
This file contains hidden or 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
//criando um retângulo | |
let element = SKShapeNode(rectOf: CGSize(width: 100, height: 40)) |