在 cocos2d 中如何实现 touch hash code 并在后面引用呢?
问题描述
如何实现触摸哈希码并在以后引用它?我已经阅读了哈希"代码,但我不明白如何使用它.我想知道我的两个精灵何时同时被触摸,就像在钢琴的两个琴键上按下一个和弦一样.
How do you implement a touch hash code and reference it later? I have read about a "hash" code, but I don't understand how to use it. I want to know when two of my Sprites are touched at the same time, like as if pressing a chord on two keys of a piano.
以下是我的 ccTouchesBegan 示例:
Here is an example of what I have for my ccTouchesBegan:
这是我的 ccTouchesEnded 的开始:
And here is the beginning of my ccTouchesEnded:
您能否举个例子说明如何捕捉从精灵开始到精灵结束的触摸?我一直在苦苦挣扎,无法让哈希码工作 - 只是不明白如何使用哈希码来引用稍后的触摸.我猜我正在尝试制作的东西会被称为哈希跟踪器?
Could you maybe give me an example of how you would capture touches that began on a sprite and ended on a sprite? I have been struggling and can't get the hash code to work - just not understanding how the hash code can be used to reference a touch later. I guess what I'm trying to make would be called a hash tracker?
我确信使用散列码和更少的状态变量可以使用一种不那么复杂的方法.我没有用其他状态变量效果来充实 ccTouchesEnded 方法,因为我希望找到一种更简单的方法(我知道我仍然需要制作 ccTouchesMoved 和 Canceled 方法).
I am sure there is a much less convoluted way to do it using the hash codes and less state variables. I haven't fleshed out the ccTouchesEnded method with the other state variable effects because I was hoping to find a simpler way (I know I still need to make the ccTouchesMoved and Canceled methods too).
任何建议将不胜感激!
推荐答案
这是我如何实现的 [我没有使用哈希码,因为我无法让它工作],以防其他人尝试这样做(我已将其限制为 2 键组合,但我也可以轻松地将逻辑扩展到 3 和 4 键组合).我选择使用 ccTouchBegan/Ended/Moved 而不是使用 ccTouchesBegan/Ended/Moved 单独处理每个触摸,因为我无法让它与哈希码一起使用.欢迎任何替代想法.
Here is how I implemented this [I DID NOT USE A HASH CODE because I could not get it to work] in case anyone else is trying to do this (I have limited it to 2-button combos but I could easily extend the logic to 3 & 4-button combos as well). I chose to handle each touch individually using the ccTouchBegan/Ended/Moved instead of using the ccTouchesBegan/Ended/Moved because I just couldn't get it to work with the hash code. Any alternative ideas would be welcome.
spuButton.h(CCSprite 子类)
spuButton.h (a CCSprite Subclass)
spuButton.m
spuButton.m
HelloWorldScene.m(只是我的记号:防止我的其他函数混淆示例的方法)
HelloWorldScene.m (Just my tick: method to keep my other functions from confusing the example)
这篇关于在 cocos2d 中如何实现 touch hash code 并在后面引用呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!