如何在碰撞时显示文字?
需要快速帮助。我正在创建我的第一个游戏 Cocos 2D 和 Box 2D,并且需要有关如何在碰撞期间显示文本的帮助。标准非常简单。我需要使用石头和弹弓击中从上面掉落的物体。每个对象都有自己的要点和特征。对于其中一个我需要实现的,如果石头摧毁了超过 3 个物体,“组合”一词应该出现在屏幕上并逐渐淡出。将热切等待您的回复和建议。
问候,
卡蒂克
Need a Quick Help. I'm creating my first game Cocos 2D and Box 2D and would require help on how to display text during collision. Criteria is very simple. Using a stone and a slingshot i need to hit the objects falling from above. Each object has its own points and features. For one of them i need to implement, if the stone destroys more than 3 objects, the word "combo" should come up on screen and gradually fade out. Will be eagerly waiting for your reply and suggestions.
Regards,
Karthik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如,在 cgintersectect 中检测更新中的碰撞,您必须编写如下文本。
示例代码:-
for example in cgintersectrect is detect your collision in update there you have to write text like these.
Example code:-
看起来相当简单:
要显示“组合”,您需要使用图形或标签 - 这在 cocos2d 示例中有所介绍,因此我不会在这里解释如何显示它。
从这里开始,在“tick”回调中,只需检查“count”的值,如果它大于或等于“3”(您的“神奇”数字),则在您的“组合”节点上运行以下操作序列。
这组操作将在四分之一秒内淡出节点,等待半秒,然后在八分之一秒内淡出。您可以根据需要调整代码的时间。当计数器 > 时,您可以执行一些其他操作。 3 是将“组合”文本重新定位到最后一个被销毁的项目的位置,或者随机化它的位置,这样它并不总是在同一个位置,等等...
示例代码中的“节点”对象是保留下来的 CCSprite 或 CCLabel添加到场景中,但只是切换其可见性(因为该项目很可能“经常”出现在场景中,因此最好将其保留在场景中并更改其可见性,而不是每次创建一个新项目并销毁它 -如果它是不常见的物品,只需创建一个新物品,然后销毁它......
Seems fairly straightforward and simple:
To display the "combo", you would want to use a graphic or a label - this is covered in the cocos2d examples, so I won't explain how to display it here.
From here, in your "tick" callback, just check the value of "count", if it is greater than or equal to "3" (your "magic" number) then run the following action sequence on your "combo" node.
This set of actions will Fade the node in over a quarter second, wait for half a second, then fade it out over an eighth of a second. You can adjust timing as necessary, for your code. Some additional things you can do, when the counter is > 3 is reposition the "combo" text to the position of the last item destroyed, or randomize it's position so it's not always in the same place, etc ...
The "node" object in the example code is a CCSprite or CCLabel that remains added to your scene, but simply has it's visibility toggled (as this item will appear in the scene more than likely "often" it's better to leave it in the scene and change it's visibility rather than create a new one and destroy it each time - if it's an infrequent item, just create a new one, and destroy it ...