How do you tell if a node is on the screen spritekit swift

前端 未结 6 2009
予麋鹿
予麋鹿 2020-12-09 12:48

I am trying to figure out how to determine if a node is visible on the screen or off the screen. Is this just a true/false property of the node? Thanks. (Using swift spritek

6条回答
  •  北海茫月
    2020-12-09 13:21

    You could use CGRectIntersectsRect supplying the frame of your SKSpriteNode and the SKScene. For example:

    if !CGRectIntersectsRect(frame, spriteNode.frame) {
        // Outside the bounds of the scene because the frames are no longer intersecting.
    }
    

提交回复
热议问题