11

I am working on the instructions screen of my game and want to show to the user that they should tap a certain area of the screen.

So I want to show an animation where

1) A finger is scaling in and out of the screen, followed by -- working fine--

2) A rectangle changing opacity (to show to tap there) and then -- need help--

3) A text flashing saying, "Tap here" -- need help--

For 1), I have this (working fine):

    finger = SKSpriteNode(texture: fingerTxt)
    finger.position = CGPoint(x: 330, y: 450)
    finger.zPosition = 10
    InstHolderNode.addChild(finger)

    let fingerTapScaleDown = SKAction.scale(by: 0.6, duration: 0.7)
    let fingerTapScaleUp = SKAction.scale(by: 1.6, duration: 0.7)
    let fingerScalingSequence = SKAction.sequence([fingerTapScaleDown,fingerTapScaleUp])

    let fingerTapScaleForever = SKAction.repeatForever(fingerScalingSequence)
    finger.run(fingerTapScaleForever)

For 2), I have :

    var rect = SKShapeNode(rectOf: CGSize(width: 150.0, height: frame.height * 2))
    rect.position = CGPoint(x: 300, y: 100)
    rect.fillColor = SKColor.brown
    rect.alpha = 0.5
    InstHolderNode.addChild(rect)

Question :

How do I sync 1) and 2) such that after 1) is completed (the finger tapping animation is done), rect.alpha value to change to 0.1 and then changed back to 0.5 and then 1) happens and then rect.alpha is changed to change to 0.1 (in a loop) continuously.

Many thanks!!

Has
  • 885
  • 4
  • 13
  • 31
  • I was going to write an answer, but it is too much and should be something you code. You already know about `sequence`. At the end of your sequence you add a `runBlock` action to fire a sequence of actions on the rectangle that uses `fadeToAlpha`. Then at the end of this action, you run another block that fires the fingerScaling action. Do not use repeat forever, this will repeat forever for you – Knight0fDragon Sep 29 '16 at 17:42
  • Thanks for the prompt reply. Could you please guide me on how to change the alpha value of this rect, every 0.6 seconds, after the finger tapping action 1) takes place please? Thanks ! – Has Sep 30 '16 at 07:24
  • already told you how to do it – Knight0fDragon Sep 30 '16 at 16:36
  • Hi, I am still a beginner and tried this : http://pastebin.com/BZBFuqsA The fading of the rectangle only happens one and not continuously. How can I make it indefinite, till I want it to stop? Thanks – Has Oct 02 '16 at 17:28
  • Hi, I even tried rect.run(fingerTapScaleForever) ) and that compiled but the game didn't work. Would be grateful if you could kindly point me in the right direction please. Many thanks – Has Oct 05 '16 at 06:58
  • Hi,sorry to bother you. I am a beginner and learning from online tutorials. Would be grateful if you could point me in the right direction please. Many thanks ! – Has Oct 07 '16 at 07:02
  • Check my answer – Aryan C Oct 22 '16 at 13:01

1 Answers1

9

Try this:

    var fadeOut = SKAction.fadeAlpha(to: 0.1, duration: 0.5)
    var fadeIn = SKAction.fadeAlpha(to: 0.5, duration: 0.5)

    rect.run(SKAction.repeatForever(SKAction.sequence([fingerScalingSequence, fadeOut, fadeIn])))

Adjust the durations as per your liking

Aryan C
  • 407
  • 1
  • 3
  • 12