簡體   English   中英

使用陀螺儀數據旋轉SpriteKit精靈的z旋轉

[英]Rotating a SpriteKit sprite’s z rotation with gyroscope data

我已經實現了用於核心運動的設置,但無法弄清楚如何保持我的精靈的旋轉,使其跟隨iPhone的旋轉(在z軸上)。

更新代碼:

[self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue]
                                            withHandler:^(CMDeviceMotion *motion, NSError *error)
{
    mySprite.zRotation = ?;
}];

有任何想法嗎?

CMAttitude是您要尋找的課程。 當您進行更新時,塊觸發將通過CMDeviceMotion實例上的態度屬性來訪問設備態度。 從態度上講,您可以直接向設備詢問有關其旋轉的各種有趣信息,但是對於您的用例,您可能只需要詢問偏航即可。

當然,假設您不需要以任何方式轉換這些值,則可以將它們直接泵入精靈的zRotation中,並且應該會收到預期的結果。

[self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue]
                                        withHandler:^(CMDeviceMotion *motion, NSError *error) {
                                            mySprite.zRotation = motion.attitude.yaw;
                                        }];

在此處輸入圖片說明 圖片來自http://uqtimes.blogspot.com/2012/05/3-coremotion.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM