2

I am trying to achieve an effect of a moving flashlight (controlled by the player) which cuts a hole in a dark overlay.

I found a lot of methods to cut a static hole in a node for example to cut the hole using the blend mode and assigning the texture to a new sprite, but that seems to be very ineffective if it needs to be done every frame.

Using an image which already has the hole in it is also not an option, because i need support to add at runtime multiple flashlights.

Using directly the blend mode also cuts the hole in all nodes below.

Is there a way to apply the blend mode only to the dark overlay or an other approach to solve this problem?

Edit: The shape of the hole (flashlight) to cut out is a sprite of any form and with alpha-values (for smooth edges etc).

rmaddy
  • 314,917
  • 42
  • 532
  • 579
greensn
  • 21
  • 3
  • What about SKLightNode? – Simone Pistecchia Sep 12 '16 at 10:41
  • 1
    Just use SKCropNode, that is why it exists – Knight0fDragon Sep 12 '16 at 11:54
  • http://stackoverflow.com/questions/34576112/draw-a-hole-in-a-rectangle-with-spritekit – Knight0fDragon Sep 12 '16 at 11:57
  • I would not recommend creating a shape node every time, create it once for each flashlight needed, and just move it to desired location – Knight0fDragon Sep 12 '16 at 11:58
  • @SimonePistecchia as far as I know, with SKLightNode you can't use specific shapes of the light source... – greensn Sep 12 '16 at 17:19
  • @Knight0fDragon: I have not found a way with the SKCropNode to use alpha-values for masking – greensn Sep 12 '16 at 17:21
  • use an SKCropNode inside of an SKCropNode to get alpha value masking – Knight0fDragon Sep 12 '16 at 17:22
  • @Knight0fDragon how do to use two `SKCropNode`s to create an alpha mask? – 0x141E Sep 13 '16 at 07:01
  • @0141e no idea, potential bug on apples part maybe – Knight0fDragon Sep 13 '16 at 10:42
  • @Knight0fDragon: How do you use the SKCropNode to make a hole in a node? I only achieved the inverse (masking the node to a circle) with SKCropNode – greensn Sep 13 '16 at 17:55
  • I sent you a link to that already – Knight0fDragon Sep 13 '16 at 17:55
  • @Knight0fDragon: Yes, but this method also cuts a hole in all nodes below it, but it should only make a hole in its direct parent... – greensn Sep 13 '16 at 20:03
  • huh? your overlay should not have any children, it is an overlay – Knight0fDragon Sep 13 '16 at 20:04
  • @Knight0fDragon: In the example from the link you sent, there is a circle with blendmode .Subtract used to cut the hole in the rectangle and the circle is added to the rectangle as a child. But this circle does not only cut a hole in the rectangle but also in all nodes below the rectangle – greensn Sep 13 '16 at 20:17
  • no it doesn't I do not know what you are doing, but what you say does not make any sense, you have an SKCropNode that has a black rectangle the size of your screen, and you use a black circle to create the hole. You then take this node, and add it to your scene with a zposition of 1000. You do not add any children to this overlay. All other nodes go to the scene. There is no reason for the nodes under it to get cut – Knight0fDragon Sep 13 '16 at 20:43
  • @Knight0fDragon: Ah, i thought you were talking about just adding a child with blendmode .Subtract as it was mentioned in the other post ;) But to make the hole you add the black overlay to the cropnode and then add the circle as a mask right? This results for me in a circle and not in a black rectangle without a circle... – greensn Sep 13 '16 at 21:33
  • "cut the hole using the blend mode and assigning the texture to a new sprite". That sounds like something I think I need to do - how do you do it? – Steve Ives Sep 16 '16 at 06:19

0 Answers0