Pregunta

Is it possible to have an SKSprite with a PhysicsBody calculate a different collision state depending on where it contacts another body? For instance, if a blue ball turned green if it contacted the side of the other object or would turn yellow if it touched the bottom of the other object.

¿Fue útil?

Solución

As if now i have not found anything specific which answers your question, but i can give you a way around i.e. first of all use the didBeginContact delegate to detect collision of the body and use the contact.contactPoint property to find out the point of contact.

What you can do is make check logic that the point of contact is under the body or on the left hand side of the body and then turn the color as per your need.

- (void)didBeginContact:(SKPhysicsContact *)contact {
    CGPoint pointOfContact= contact.contactPoint; 
   //this is just an example.. change the condition as per your need  
   if(pointOfContact.x>yourSpritePosition.frame.position.x&&pointOfContact.y>yourSpritePosition.frame.position.y){
   //your color change logic
   }
}

I hope this can solve your problem.

Otros consejos

You can seperate your sprite to child sprites and you can set different logic for them.

Building Complex Content Using Nodes

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top