碰撞检测导致颜色检测? [英] Collision detection leading to color detection?

查看:168
本文介绍了碰撞检测导致颜色检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在两个带球的矩形的中间与SKSpriteNode碰撞时,如何检查球和两个矩形的颜色相同?

How can I check if, when I collide with an SKSpriteNode in the middle of two rectangles with a ball, the ball and the two rectangles are the same color?

例如,如果我的两个矩形是红色,而我的球是蓝色,我希望它检测到我的矩形和球的颜色不同.如果它们是相同的颜色,那么我什么都不想发生.如果不是,我将编写使玩家迷失的代码.但是,当球与两个矩形中间和中间的skspritenode碰撞时,如何检测色差?

For example, if my two rectangles are red, and my ball is blue, I want it to detect that the colors of my rectangle and the ball are different. If they are the same color, then I don't want anything to happen. If they aren't, I'll write the code that makes the player lose. But how can I detect the color difference when the ball collides the skspritenode located in the middle and in between the two rectangles?

推荐答案

我的建议是,您将一对"墙改为三重墙.第三壁应具有不同的categoryBitMask. (PhysicsCategory.wallSpace似乎符合您当前的命名方案.)

My suggestion is that your change your "pair" of walls to become a trio of walls instead. This third wall should have a different categoryBitMask. (PhysicsCategory.wallSpace seems to fit with your current naming scheme.)

此"wallSpace"需要放置在两个现有墙之间.通过您的变色逻辑,应该为它赋予相同颜色作为其同级颜色,但是诀窍在于:将其alpha设置为0.

This "wallSpace" needs to be positioned between the two existing walls. It should be given the same color as its siblings through your color-change logic, but here comes the trick: set it's alpha to 0.

通过这种方法,您可以检查此隐形墙与您的球之间是否存在碰撞,并根据颜色信息执行操作.

This way you can check for collisions between this invisible wall and your ball and perform actions based on the color-information.

这篇关于碰撞检测导致颜色检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆