UIImage碰撞效果...??? IPhone

发布于 2024-10-03 17:50:47 字数 289 浏览 1 评论 0原文

我需要一种方法来创建碰撞效果,而不需要两个图像之间发生实际碰撞。让我更详细地解释一下...如果我有一张固定图像和一张移动图像,则两张图像在不同位置的相同 x 坐标上。基本上我希望图像看起来是碰撞的。我想像这样对移动图像进行检查...

如果(移动图像的前面是清晰的)

{[向前移动];}

其他 {[stop];}

我如何在代码中实现这个???因此,在移动图像与固定图像碰撞之前它会停止,因此它们看起来已经发生碰撞。此检查也将在 1/60 NSTimer 上运行。

欢迎任何建议。谢谢。

I need a way to create a collide effect, without the actual collision between the two images. Let me explain in more detail... If I have one fixed image and one image that is moving both images are on the same x coordinate at different positions. Basically I want the images appear to be colliding.I would want to run a check on the moving image like this...

If (front of moving image is clear)

{[move forward];}

else
{[stop];}

How would I implement this in code??? So that right before the moving image collides into the fixed image it stops, so that they appear to have collided.This check would also be running on a 1/60 NSTimer.

Any advice is welcome. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海之角 2024-10-10 17:50:47

假设对象从左侧移动

#define PIXELS_PER_FRAME 1

-(CGFloat) getCurrentX:(UIImage*)image
{
    return image.frame.origin.x + image.frame.size.width;
}

-(void) moveImageToStableImage
{
    CGFloat xTarget = stableImage.frame.origin.x;
    if([self getCurrentX:movingImage] < xTarget)
    {
        movingImage.frame.origin.x += PIXELS_PER_FRAME;
        [self performSelector:@selector(moveImageToStableImage) withObject:nil afterDelay:1.0/60];
    }
}

但说实话,在这种情况下,使用动画可能会更好

Assuming the object is moving from the left

#define PIXELS_PER_FRAME 1

-(CGFloat) getCurrentX:(UIImage*)image
{
    return image.frame.origin.x + image.frame.size.width;
}

-(void) moveImageToStableImage
{
    CGFloat xTarget = stableImage.frame.origin.x;
    if([self getCurrentX:movingImage] < xTarget)
    {
        movingImage.frame.origin.x += PIXELS_PER_FRAME;
        [self performSelector:@selector(moveImageToStableImage) withObject:nil afterDelay:1.0/60];
    }
}

But truth be told in this situation you would probably just be better off using an animation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文