How to Create a Pulse Effect on an Skspritenode

How To Create a Pulse Effect On an SKSpriteNode?

A real easy way of doing this would be to have your button image, and an outline image right below you button. then just run the pulse func on the button outline image and voila! It works with any shape and you can just adjust the actions as you see fit. These are added via the scene editor but it makes no difference how they are added as long as the outline images have a lower zPosition than the button.

Sample Image

button1
button1_outline
button2
Sample Image
Sample Image
Sample Image

class LevelMenu: SKScene {

private var button1 = SKSpriteNode()
private var button1Outline = SKSpriteNode()
private var button2 = SKSpriteNode()
private var button2Outline = SKSpriteNode()
private var button3 = SKSpriteNode()
private var button3Outline = SKSpriteNode()

override func didMove(to view: SKView) {

if let button1 = self.childNode(withName: "button1") as? SKSpriteNode {
self.button1 = button1
}

if let button2 = self.childNode(withName: "button2") as? SKSpriteNode {
self.button2 = button2
}

if let button3 = self.childNode(withName: "button3") as? SKSpriteNode {
self.button3 = button3
}

if let button1Outline = self.childNode(withName: "button1Outline") as? SKSpriteNode {
self.button1Outline = button1Outline
}

if let button2Outline = self.childNode(withName: "button2Outline") as? SKSpriteNode {
self.button2Outline = button2Outline
}

if let button3Outline = self.childNode(withName: "button3Outline") as? SKSpriteNode {
self.button3Outline = button3Outline
}
}

func pulseAction(node: SKSpriteNode) {

let copyNode = node.copy() as! SKSpriteNode
copyNode.position = node.position
addChild(copyNode)

let scale = SKAction.scale(by: 1.75, duration: 0.4)
scale.timingMode = .easeInEaseOut
let wait = SKAction.wait(forDuration: 0.25)
let fadeOut = SKAction.fadeOut(withDuration: 0.15)
let fadeSeq = SKAction.sequence([wait, fadeOut])
let pulseGroup = SKAction.group([scale, fadeSeq])

copyNode.run(pulseGroup, completion: { copyNode.removeFromParent() })
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

pulseAction(node: button1Outline)
pulseAction(node: button2Outline)
pulseAction(node: button3Outline)
}
}

How to pulse a sprite using SpriteKit in SWIFT

In xCode Version 8.3.3 with Swift,

    let pulseUp = SKAction.scale(to: 3.0, duration: 1.0)
let pulseDown = SKAction.scale(to: 0.5, duration: 1.0)
let pulse = SKAction.sequence([pulseUp, pulseDown])
let repeatPulse = SKAction.repeatForever(pulse)
self.playButton.run(repeatPulse)

Increasing the size of a spriteNode using spriteKit in update function (Swift)

Whoever told you to not use SKActions is wrong. This is exactly when you want to use an SKAction, and if you have multiple circles pulsing, you use the same action on all circles.

You really want to keep your update function as small as possible. Trust in apple’s optimizations because they have better access to the API than you do.

Issue with SKEmitterNode?

Clearly the particle system is being detected by the hit test instead of the buttons. You could use nodes(at:) to get the list of all the nodes in that point (instead of just the first one). Then you need to iterate or filter that array and find out which of these nodes are buttons.

for touch: AnyObject in touches 
{
let location = (touch as! UITouch).location(in: self)
let nodes = self.nodes(at:location)

let filtered1 = nodes.filter{ $0.name == "playBox" || $0.name == "playButton" }
let filtered2 = nodes.filter{ $0.name == "shopBox" || $0.name == "shopButton" }

if let node = filtered1.first {
buttonSound()
pulse(playBox, scene: "GameScene")
}

if let node = filtered2.first {
buttonSound()
pulse(shopBox, scene: "shop")
}

How to detect if, one sprite node is the same colour as another sprite node then add to score if they are the same if not restart game

Given a Ball and a Wall class

class Ball: SKSpriteNode { }
class Wall: SKSpriteNode { }

In your didBegin(contact:) just compare the color property.

class GameScene: SKScene, SKPhysicsContactDelegate {

func didBegin(_ contact: SKPhysicsContact) {

let nodeA = contact.bodyA.node
let nodeB = contact.bodyB.node

guard let nodes: (ball:Ball, wall:Wall) = (nodeA, nodeB) as? (Ball, Wall) ?? (nodeB, nodeA) as? (Ball, Wall) else { return }

if nodes.ball.color == nodes.wall.color {
// same color
// TODO...
}

}
}

Add reference problem in silverlight: You can't add a reference to dll as it was not built against the silverlight runtime

Apparently Silverlight project will only work with Silverlight asseblies.
CLRs for .NET and Silverlight are different, therefore assemblies are not compatible. These frameworks provide different set of classes, assemblies have different versions, et cetera.

You need to change your Class Library to Silverlight Class Library.

This can either be done by changing project file manually or by creating Silverlight Class Library project and copying the sources in it. If you need the same library for a non-Silverlight project and don't want to maintain two versions, consider using Add as Link feature of Add Existing Item... dialog to only reference the original sources without copying them. But you'll need to make sure you only use functionality available on both platforms for both library versions to build.



Related Topics



Leave a reply



Submit