gpt4 book ai didi

objective-c - Sprite.Frame.Contains 在 Objective C 中?

转载 作者:可可西里 更新时间:2023-11-01 01:42:03 24 4
gpt4 key购买 nike

所以我需要在我的游戏中做这行简单的代码。它目前处于 swift 状态,我正在尝试将其转换为 Objective-C,但我被卡住了,因为在 Objective C 中没有

sprite.frame.cointains(//CGPOINT);

我想知道我该如何继续做这件事,因为这对我的比赛至关重要。这是 swift 中的代码

    if fruitNode.frame.contains(location!) {
touchPoint = location!
touching = true
}

如果有人能帮我回复,我将不胜感激!

谢谢!

最佳答案

在 Objective C 中,您可以使用 SKNode 方法执行此操作:

if ([fruitNode containsPoint:location])
{
// do this
}

或者如果您出于某种原因需要使用 CGRect:

if (CGRectContainsPoint(fruitNode.frame, location))
{
// do this
}

一定要检查 CGRectContainsPoint 的 Apple 引用 - https://developer.apple.com/library/prerelease/ios/documentation/GraphicsImaging/Reference/CGGeometry/index.html#//apple_ref/c/func/CGRectContainsPoint

关于objective-c - Sprite.Frame.Contains 在 Objective C 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28949103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com