Touch Handling in Cocos2D 3.x(一)

原帖地址

Cocos2d 3.0 带来经过完全修正后的触摸处理系统.本篇博文将提供所有触摸相关的信息:

  • 接收触摸
  • 取得触摸位置
  • 处理不同个触摸生命周期中的事件
  • 实现一个拖放机制

让我们开始吧 ;)

通过下载开始项目开始我们的旅程: starter project

一旦你下载运行项目,你可以运行App看到如下屏幕:

Cocos2D 3.3+ 需要注意的地方

如果你使用Cocos2D 3.3+ (它是SpriteBuilder 1.3+的一部分) 你必须分别使用CCTouch和CCTouchEvent替换所有的UITouch和UITouchEvent类.你可以在SpriteBuilder的升级手册中找到更多的信息.

时间: 2024-08-09 19:54:06

Touch Handling in Cocos2D 3.x(一)的相关文章

Touch Handling in Cocos2D 3.x(二)

接受触摸 在Cocos2d 3.0中每一个CCNode和每一个CCNode的子类都可以接收触摸.你只需要开启一个选项.让我们在定制的初始化器里完成它.替换MainScene.m中init方法的代码: - (id)init { if (self = [super init]) { // activate touches on this scene self.userInteractionEnabled = TRUE; } return self; } 现在Cocos2d 将会知道我们想要在这个场景

Touch Handling in Cocos2D 3.x(五)

实现新英雄的放置功能 首先我们需要一个变量来保持我们当前移动英雄的引用,因此我们将添加一个私有实例变量.修改MainScene.m中的代码. 用: @implementation MainScene { // this is the section to place private instance variables! CCSprite *currentHero; } 替换原来的代码: @implementation MainScene 现在我们有了一个新的私有变量.该变量将总是持有我们当前拖

Touch Handling in Cocos2D 3.x(三)

取得触摸位置 最有趣的部分是触摸的位置.接下来我们将使用触摸位置在玩家每次点击的屏幕位置上添加精灵.为了完成这项功能我们需要修改touchBegan的实现,替换旧的代码如下: - (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event { // we want to know the location of our touch in this scene CGPoint touchLocation = [touch locatio

Touch Handling in Cocos2D 3.x(四)

创建触摸生命周期 让我们改善我们的应用程序.如果玩家可以触摸屏幕并且拖放英雄到指定位置不是更好吗? 为了完成这个功能我们必须使用Cocos2d 3.0提供的所有的触摸事件: touchBegan:在用户触摸屏幕时调用 touchMoved:在用户在屏幕上移动手指时调用 touchEnded:在用户停止触摸屏幕时调用 touchCancelled:在用户依然触摸屏幕但是一些其他问题停止你的节点处理触摸事件时调用(e.g. 触摸移动到你节点的边界之外时). 我们新的英雄放置算法将会按如下方式工作:

Android - HorizontalScrollView(ViewPager) within ScrollView Touch Handling

1. public class CustomScrollView extends ScrollView { private GestureDetector mGestureDetector; View.OnTouchListener mGestureListener; public CustomScrollView(Context context, AttributeSet attrs) { super(context, attrs); mGestureDetector = new Gestur

iOS Programming Touch Events and UIResponder

iOS Programming Touch Events and UIResponder? 1 Touch Events? As a subclass of UIResponder, a UIView can override four methods to handle the four distinct touch events: 作为UIResponder的一个子类,UIView可以重写四个方法来处理touch events. (1) a finger or fingers touches

(一)创建新的react native 应用程序

最近开始学习ReactNative了,首先了解下ReactNative React Native 官网首页介绍 React Native 使你能够使用基于 JavaScript 和 React 一致的开发体验在本地平台上构建世界一流的应用程序体验.React Native 把重点放在所有开发人员关心的平台的开发效率上——开发者只需学习一种语言就能轻易为任何平台高效地编写代码.Facebook 在多个应用程序产品中使用了 React Native,并将继续为 React Native 投资. Re

和Keyle一起学StrangeIoc – Extensions

Strange: the IoC framework for Unity Extensions You may have heard that Strange is a Dependency Injection framework. I'm a little uncomfortable with that description. Sure, Strange offers DI and it's a great use, but the core of the framework - as I'

【转】Android 4.0 Launcher2源码分析——启动过程分析

Android的应用程序的入口定义在AndroidManifest.xml文件中可以找出:[html] <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.launcher">  <original-package android:name="com.android.launcher2" /> .