單點觸控事件

2021-08-04 16:57:46 字數 1396 閱讀 6702

// ①建立乙個單點觸控事件***,處理觸控事件邏輯

auto listener1 = eventlistenertouchonebyone::create();

// ②設定是否向下傳遞觸控

listener1->setswallowtouches(true);

// ③通過

lambda

表示式 直接實現觸控事件的響應函式

listener1->ontouchbegan = (touch* touch, event* event); 等價於touchlistener->ontouchbegan = cc_callback_2(helloworld::ontouchbegan,this);

void helloworld::ontouchbegan(touch *touch, event *event)   

listener1->ontouchmoved = (touch* touch, event* event)else{

name = "yellowsquare.png";

log("ontouchended.. 您觸控的是

%s",name.c_str());

// ④新增場景優先事件***。

_eventdispatcher->addeventlistenerwithscenegraphpriority(listener1, sprite1);

//⑤注意:在使用

addeventlistenerwithscenegraphpriority

或者addeventlistenerwithfixedpriority

函式時,

會對當前使用的事件***新增乙個已註冊的標記,這使得它不能夠被新增多次。所以當我們再次使用listener1的時候,需要使用

clone()

函式建立乙個新的轉殖。

_eventdispatcher->addeventlistenerwithscenegraphpriority(listener1->clone(), sprite2);

_eventdispatcher->addeventlistenerwithscenegraphpriority(listener1->clone(), sprite3);

附加:target->getboundingbox().containspoint(touch->getlocation()))與

point locationinnode = target->converttonodespace(touch->getlocation());

rect rect1 = rect(870 - 60*i, 23, 138-60*i, 174);

rect1.containspoint(locationinnode)之間的區別,前者是觸控範圍為目標物件的區域大小,後者是自己自定義的區域大小。

cocos2dx 單點觸控,按鈕事件

1,單點觸控 h include using namespace std 觸控事件開始,手指按下時 void ontouchesbegan const std vector touches,cocos2d event event 觸控移動事件,也就是手指在螢幕滑動的過程 void ontouches...

TouchView觸控事件

touchview 繼承自uiview 初始化時 self multipletouchenabled yes 開啟多指觸控 取出一根手指 uitouch touch touches anyobject 獲得手指在檢視上的位置 cgpoint point touch locationinview se...

觸控事件處理

ios programming 觸控事件 處理 1 iphone ipad無鍵盤 的 在cocoa中,代表觸控物件的類是uitouch。當使用者觸控螢幕幕後,就會產生相應的事件,所有相關的uitouch物件都被包裝在事件中,被程式交由特定的物件來處理。uitouch物件直接包括觸控的詳細資訊。uit...