last day (14 days later) » 

3:06 PM
0
Q: didbegincontact not called spritekit

GmaSamy code is like so class GameScene: SKScene, SKPhysicsContactDelegate { var player: SKSpriteNode! var player2: SKSpriteNode! var initialplayerposition : CGPoint! override func didMove(to view: SKView) { self.physicsWorld.gravity = CGVector(dx:0, dy:0) self.physicsWorld.conta...

 
Nik
You haven't setup your physicsBodies bitmasks
 
@Nik i have struct CollisionBitMask { static let Player:UInt = 0*00 static let Obstacle:UInt = 0*01 } but it doesnt work either
 
Nik
Instead of 0*01 and 0*00, try 0b10 and 0b1 (I don't use zero because that's for something that isn't part of collisions/contacts. Also, at least one of the physicsBodies has to be dynamic for the collision/contact to work. Another issue is that you need both nodes to have physicsBodies and both should have the bitmasks to be setup
 
the Obstacle (the second element) is already Dynamic but using 0b1 doesnt solve the problem
 
Nik
I didn't mention yet that in your didBeginContact, you're assuming that bodyA is always going to be player if you want the game to end. You can't assume that unless you sort them in order of categoryBitmasks (because you know which node should have a certain bitmask)
 
3:06 PM
im already sorting them too but nothing happens, its a little bit confusing here, yes ill edit my post
 
Nik
You have to set isDynamic for the obstacle after you've created its physicsBody. You also haven't setup the obstacles contactTestBitMask to the category of the player
 
none of them works , isDynamic is already set now after creating the physicsBody , and the contactTestBitMask too , its already set to the player , ive tried to set it to the obstacle too but doesnt work
 
Nik
You're using two different names. The player name is PLAYER, but you're checking if it's name is Player in didBeginContact. Those two names should be identical
 
ive already correct it setting the bodyA.node.name to "PLAYER" , but doesnt work :/
 
Nik
Where have you actually used the obstacle function?
 
3:06 PM
im using it in the update function
@nik here is the repo if u want to test it github.com/gallaouim/divideit
 
Nik
Set the player categoryBitmask to 0b01 instead of 0b00
 
no changes , can u please test it locally if u dont mind ?
 
Nik
I'm actually on my phone right now and can't test it, but in that code, you're not actually calling the obstacle function anywhere. I checked the update and it's not there
 
im not calling it directly thats why
 
Nik
I forgot to check, but is it part of updateWithTimeSinceLastUodate? I can't check cuz the github is down
 
3:06 PM
ah oki , im really confused , let me know if u find something :)
 
Nik
Are you sure that didBeginContact is not being called at all? Put a fatalError() in it and see if the game crashes at contact
 
:D , ive already test it too with a FatalError , its not being called at all
under GameElements.swift addRow call addObstacle, and under gamescene, add addRandomRow call add addrow
 
Nik
Try setting the player isDynamic to true
 
doesnt work (test it now) , based on the documentation , only one of the spritenode is enough
 
Nik
I know, but if it changed anything I'd know where the problem could be
Try changing UInt to UInt32. It shouldn't do anything, but maybe it will...
@GmaSa Have you tried that yet?
 
3:28 PM
@Nik as u said , nothing happens :/
 

last day (14 days later) »