Skip to content

Instantly share code, notes, and snippets.

View alcidesjunior's full-sized avatar
💻
Codando...

Alcides Junior alcidesjunior

💻
Codando...
View GitHub Profile
//
// NewPlaceViewController.swift
// tell2
//
// Created by Alcides Junior on 02/10/19.
// Copyright © 2019 Alcides Junior. All rights reserved.
//
import UIKit
import MapKit
//
// AddressViewController.swift
// tell2
//
// Created by Alcides Junior on 05/10/19.
// Copyright © 2019 Alcides Junior. All rights reserved.
//
import UIKit
import MapKit
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//vamos pegar o node que foi atualmente tocado
let location = touches.first?.location(in: self)
let currentNode = nodes(at: location!)
//verificando quem é o node a partir da propriedade NAME
if currentNode.first?.name == "blueButton"{
self.changeBoardColor(color: .blue)
self.blueButton.lineWidth = 8
self.redButton.lineWidth = 1
}else if currentNode.first?.name == "redButton"{
func changeBoardColor(color: UIColor){
self.board.fillColor = color
}
override func didMove(to view: SKView) {
//adicionando os elementos na tela
addChild(blueButton)
addChild(redButton)
addChild(board)
}
//criando uma board que será o alvo das ações nos botões
private lazy var board: SKShapeNode = {
//criando uma board quadrada
let btn = SKShapeNode(rectOf: CGSize(width: 300, height: 300))
//posicionando a board no centro da tela
btn.position = CGPoint(x: (view?.frame.width)!/2, y: (view?.frame.height)!/2)
//definindo uma cor para a board
btn.fillColor = .white
//definindo a espessura da borda
btn.lineWidth = 2
//definindo o botão azul e suas propriedades
private lazy var redButton: SKShapeNode = {
//criando um botão retângulo
let btn = SKShapeNode(rectOf: CGSize(width: 70, height: 40))
//posicionando o botão
btn.position = CGPoint(x: 240, y: 60)
//definindo a cor para o botão
btn.fillColor = .red
//dando um nome ao botão
btn.name = "redButton"
private lazy var blueButton: SKShapeNode = {
//criando um botão retângulo
let btn = SKShapeNode(rectOf: CGSize(width: 70, height: 40))
//posicionando o botão
btn.position = CGPoint(x: 140, y: 60)
//definindo a cor para o botão
btn.fillColor = .blue
//dando um nome ao botão
btn.name = "blueButton"
let anim2 = SKAction.animate(with: [SKTexture(imageNamed: "5"),SKTexture(imageNamed: "6"),SKTexture(imageNamed: "7"),SKTexture(imageNamed: "8"),SKTexture(imageNamed: "9"),SKTexture(imageNamed: "10"),SKTexture(imageNamed: "11"),SKTexture(imageNamed: "12")], timePerFrame: 0.6)
self.fakeTexture.size = CGSize(width: 487, height: 236)
self.fakeTexture.run(SKAction.repeatForever(SKAction.sequence([anim2])))
//dentro do didMove setamos o delegate
physicsWorld.contactDelegate = self