Swift image / silhouette path in Swift

I am working on a game in Xcode / Swift for iPad / iPhone.

What I need to do is get the outline path of the image / silhouette so that I can animate along the outline of the image / silhouette. This will create the effect of laser cutting, the one that you see in the films when they pierce the door / window with a laser.

Just draw it as the Beizer path will not work, since I need to do this for a bunch of images / silhouettes. If possible, I would prefer to just add images to my project and make a presentation in the code, so I can easily expand with a lot of shapes and sizes.

In SpriteKit, I tried using SKPhysicsBody, and then used Alpha to create an outline. This gives me this outline, but not as a way, so I cannot revive this line. In fact, when I turn on ".showsPhysics", I get the line I need, but still not the line that I can use for animation.

Is there a way to use / modify the ".showsPhysics" method or cancel the PhysicalBody method on the path?

I am coding in Swift and any advice would be appreciated.

This is an example of what I need, I need a blue line as a path for the animation.

enter image description here

+4
source share
1 answer

SpriteKit . bodyWithTexture:size:, . .

, bodyWithTexture:size:,

let texture = SKTexture(imageNamed: "rex")
let rex = SKSpriteNode(imageNamed: "rex")
rex.physicsBody = SKPhysicsBody(texture: texture, size: texture.size())
rex.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));
rex.physicsBody?.dynamic = false    // This line is just for demo
self.addChild(rex)

enter image description here

:

enter image description here

0

Source: https://habr.com/ru/post/1607080/


All Articles