Touch Handling in Cocos2D 3.x(六)
in cocos2d touch Handling
2023-09-14 08:56:50 时间
这是另一个非常有用的特性.很多用户需要捡起已经存在的英雄然后满屏幕移动它们.让我们按以下步骤实现该功能:
如果用户触摸屏幕空白位置,一个新的英雄将被创建 如果用户触摸一个已经存在的英雄,不会有新英雄被创建,相反Ta可以移动已存在的那个英雄
为了实现这些,我们需要创建一个CCSprite的子类.前进去创建一个名为CCDragSprite的类,该类继承自CCSprite:
在CCDragSprite.h中添加以下一行导入Cocos2d的头文件:
#import "cocos2d.h"
现在我们可以在CCDragSprite.m中关注实现部分了!我想你保证它将惊人的简单.我们需要做如下步骤:
// we want to know the location of our touch in this scene CGPoint touchLocation = [touch locationInNode:self.parent]; self.position = touchLocation; }
现在你应该大致了解上面的代码了.当我们的CCDragSprite进入屏幕时,我们打开它的交互选项.我们需要增加一个touchBegan方法的空白实现,这是为了让Cocos2d知道我们想要认领该触摸(否则下一层的responder将会接收到这次触摸).
相关文章
- Touch Handling in Cocos2D 3.x(三)
- Touch Handling in Cocos2D 3.x(一)
- 2016年北京hadoop in china见闻
- [Kotlin] Multi ways to write constuctor in Kotlin
- [Angular] FadeIn and FadeOut animation in Angular
- [Angular] Lazy Load Images in Angular
- [Test] Easy automated testing in NodeJS with TestCafe
- [Angular] Show a loading indicator in Angular using *ngIf/else, the as keyword and the async pipe
- [GIF] Parenting in GIF Loop Coder
- [ES6] 12. Shorthand Properties in ES6
- Opportunity creation case in Firebug
- atitit.dw不能显示正确的百分比高度in dw的解决
- Matlab:成功解决In an assignment A(I)=B,the number of elements in B and I must be the same
- 已解决FutureWarning: The default value of regex will change from True to False in a future version. In
- Sqlachemy的警告SAWarning: The IN-predicate on "sns_object.BIZ_ID" was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.
- Python Missing parentheses in call to 'print'
- Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack.
- 解决办法:The name 'Response' does not exist in the current context
- :app:mergeDexDebug Cannot fit requested classes in a single dex file (# methods: 71369 > 65536) com.
- JS对象操作(in、instanceof、delete)运算符