transparency - Swift | Ignore transparent parts of sprite when detecting collisions? -
i want detect collisions every part of sprite except transparent parts. found solution c can't figure out how in swift.
here's obj-c solution: sprite kit collisions: ignore transparency?
anyone have idea?
edit:
here's function code building shape. i'm not sure how set spritename.physicsbody answer supplied below user.
func addtriangles() { center = skspritenode(imagenamed:"images/center.png") center.position = cgpoint(x: cgrectgetmidx(self.frame), y: cgrectgetmidy(self.frame)) center.zposition = -1 center.physicsbody = init!(texture centertexture: sktexture!, size 1.0: cgsize) -> skphysicsbody? center.physicsbody?.dynamic = false center.physicsbody?.affectedbygravity = false center.physicsbody?.categorybitmask = physicscategory.triangle self.addchild(center) spin = clockwise center.runaction(skaction.repeatactionforever(spin)) }
you can use
init!(texture texture: sktexture!, size size: cgsize) -> skphysicsbody?
to set collision body alpha channel of texture of sprite
however, not recommended because costs lot simulate complicated shape's physics behaviour.
if have sprite complicated shape, try draw simpler shape , use texture physics body.
Comments
Post a Comment