简体   繁体   中英

Swift & Sprite-Kit: How to rotate sprites to the direction set by collision?

I'm new to game physics. I would like to create a sprite in Sprite-kit where the sprite would rotate as it collides with screen boundaries or other objects in the game. Basically like so.

在此处输入图片说明

I just have no idea how this is done in Sprite-Kit or with any other framework for that matter... Do I have to calculate rotations in code or does the framework offer assistance? If this is going to be done in my code, could someone help me get started? Thanks a bunch already!

Use the following SKAction:

let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:5)
sprite.runAction(action)

This will rotate the sprite 180º

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM