首页 > 代码库 > CCTouch和CCTouchPhase --- Cocos2D-Swift v3.3

CCTouch和CCTouchPhase --- Cocos2D-Swift v3.3

CCTouch Class Reference

Inherits fromNSObject
Declared inCCTouch.h

Overview

Thin wrapper around platform-specific touch events (ie UITouch). CCTouch is platform independent version of the touch event objects sent by iOS, Android and OS X.

CCtouch是与平台无关的touch事件。

Note: You should never create instances of CCTouch.

你永远也不应该创建一个CCTouch实例。

Tasks

Touch Information

  •   phase property
  •   tapCount property
  •   timestamp property

Associated View and Platform Touch

  •   view property
  •   uiTouch property

Convert Touch Location to Node Coordinate System

  • – locationInNode:
  • – locationInWorld

Convert Touch Location to View Coordinate System

  • – locationInView:
  • – previousLocationInView:

Properties

phase

The CCTouchPhase this touch is currently in.

这个触摸目前的阶段

@property (nonatomic, readonly) CCTouchPhase phase

Availability

v3.2 and later

Declared In

CCTouch.h

tapCount

The number of taps for this touch event.

触摸事件的敲击次数。 

@property (nonatomic, readonly) NSUInteger tapCount

Availability

v3.2 and later

Declared In

CCTouch.h

timestamp

The timestamp of the most recent touch phase change.

最近的触摸阶段改变的时间戳。

@property (nonatomic, readonly) NSTimeInterval timestamp

Availability

v3.2 and later

Declared In

CCTouch.h

uiTouch

The associated platform-specific touch event (ie UITouch). PlatformTouch is equivalent to UITouch on iOS, CCTouchAndroid on Android and NSObject on OS X.

@property (nonatomic, strong) PlatformTouch *uiTouch

Availability

v3.2 and later

Discussion

Note: The CCTouchAndroid class is not documented, it is just a subset of CCTouch.

Declared In

CCTouch.h

view

The associated Cocos2D view.

相联系的Cocos2D的view

@property (nonatomic, strong) CCGLView *view

Availability

v3.2 and later

Declared In

CCTouch.h

Instance Methods

locationInNode:

The node to which this touch should be relative to.

这个触摸事件应该关联的node。

- (CGPoint)locationInNode:(CCNode *)node

Parameters

node

The node to which this touch should be relative to.

Return Value

The touch location relative to the given node’s position.

Availability

v3.2 and later

Declared In

CCTouch.h

locationInView:

The view to which this touch should be relative to.

- (CGPoint)locationInView:(CCGLView *)view

Parameters

view

The view to which this touch should be relative to.

Return Value

The touch location relative to the given view.

Availability

v3.2 and later

Declared In

CCTouch.h

locationInWorld

The touch location relative to the scene (aka “world”).

相对于scene的触摸位置.

- (CGPoint)locationInWorld

Return Value

The touch location relative to the scene (aka “world”).

Availability

v3.2 and later

Declared In

CCTouch.h

previousLocationInView:

The view to which this touch should be relative to.

- (CGPoint)previousLocationInView:(CCGLView *)view

Parameters

view

The view to which this touch should be relative to.

Return Value

The previous touch location relative to the given view.

返回:相对于给定的view,之前的触摸位置。

Availability

v3.2 and later

Declared In

CCTouch.h
 
 
 
 

CCTouchPhase Constants Reference

Declared inCCTouch.h

CCTouchPhase

Touch phases, equivalent to UITouch phases. Used by touch events received through CCResponder.

触摸阶段,等同于UITouch phases。

Definition

typedef NS_ENUM(NSInteger, CCTouchPhase ) {
   CCTouchPhaseBegan,
   CCTouchPhaseMoved,
   CCTouchPhaseStationary,
   CCTouchPhaseEnded,
   CCTouchPhaseCancelled,
};

Constants

CCTouchPhaseBegan

A finger just touched the screen.

手指刚刚接触屏幕

Declared In CCTouch.h.

CCTouchPhaseMoved

A finger on the screen just moved.

手指刚刚离开屏幕

Declared In CCTouch.h.

CCTouchPhaseStationary

A finger touches the screen but hasn’t moved recently.

一个手指触摸到屏幕但是还没有离开

Declared In CCTouch.h.

CCTouchPhaseEnded

A finger was lifted from the screen.

一个手指脱离了屏幕

Declared In CCTouch.h.

CCTouchPhaseCancelled

The system cancelled touch events. This can have many reasons, for instance when receiving a call and the screen goes black or a gesture recognizer cancelling touch events.

系统取消了触摸事件。这可能由多种原因造成,比如当接到电话,屏幕变黑,或者手势识别取消了触摸事件等。

Declared In CCTouch.h.

Declared In

CCTouch.h
 

CCTouch和CCTouchPhase --- Cocos2D-Swift v3.3