objective c - Stopping objects when collision occurs in sprite kit -


i'm building game using apple's spritekit , skphysics use squares move around on screen based on user input. i'm having issue collisions in squares move out of place if collide. example, if blocks move right, blocks on same "row" need stack next each other , not overlap or move position vertically. of now, change vertical direction. here code:

self.physicsbody = [skphysicsbody bodywithrectangleofsize:self.size]; self.physicsbody.dynamic = yes; self.physicsbody.allowsrotation = no; self.physicsbody.affectedbygravity = no; 

are there other settings i'm missing?

the issue coming collisionbitmask category. in order solve that, need first create categories blocks' physics bodies follows:

struct physicscategory {     static let none : uint32 = 0     static let : uint32 = uint32.max     static let block : uint32 = 0b1     } 

then set blocks' settings following.

    block.physicsbody?.categorybitmask = physicscategory.block     block.physicsbody?.collisionbitmask = physicscategory.none 

this should prevent collision calculations being automatically carried out spritekit.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -