Puis-je simuler l'objet SKPhysicsContact
pour alimenter la méthode -(void)didEndContact:(SKPhysicsContact *)contact
? Ou y a-t-il d'autres techniques qui peuvent être exploitées ici?Existe-t-il un moyen d'écrire un test d'une fonction `SKPhysicsContactDelegate`?
class PhysicsTestCase: XCTestCase {
var physics: GamePhysics!
...
func testCaseOfCollisionsHandling() {
let contact = SKPhysicsContact()
contact.bodyA = SKPhysicsBody(circleOfRadius: 10) // Error, 'bodyA' is get-only property
physics.didEnd(contact) // Physics conforms to `SKPhysicsContactDelegate`
}
...
}
...
// The class that is being tested
class GamePhysics: NSObject, SKPhysicsContactDelegate {
// MARK: - SKPhysicsContactDelegate
func didBegin(_ contact: SKPhysicsContact) {
guard let nodeA = contact.bodyA.node, let nodeB = contact.bodyB.node else {
fatalError("No nodes in colliding bodies")
}
switch (nodeB, nodeA) {
case let (ball as LogicalBall, tile as LogicalTile):
// Performing some logic
...
}
}
func didEnd(_ contact: SKPhysicsContact) {
...
}
...
}
Vous pouvez créer un petit projet et encore vos objets sur initialise dessus de l'autre. 'didEndContact' devrait être appelé dans cette situation. –
Qu'essayez-vous exactement de faire? Pourquoi essayez-vous de définir le corps de la physique? Ce n'est pas quelque chose que tu ferais jamais. –
Je veux écrire un ensemble de tests qui vérifie que mon 'SKPhysicsContactDelegate' fonctionne comme prévu. – Zapko