Cocos2d x3 2 多點觸控

2021-09-23 19:37:58 字數 3627 閱讀 6392

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

#include "cocos2d.h"

using_ns_cc;

classgamescene :publiccocos2d::layer

;

簡介: cocos2d-x 3.0版本以後的事件分發的機制較之之前的版本進行了修改,把事件處理的邏輯分離出來,並通過不同的事件***來監聽不同的事件。當乙個節點收到了事件,就會指派乙個事件分發器_eventdispatcher專門來分發這些事件。對於觸控來說,大概的過程就是我們先建立乙個對應觸控事件的***,然後覆蓋觸控事件的函式,並把它們繫結到***,然後可以設定一下這個***的屬性,最後把***新增到分發器之中,系統就會自動進行觸控事件的處理。 ? 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

//可參考mutitouchtest.cpp

#include "gamescene.h"

using_ns_cc;

cocos2d::scene* gamescene::createscene()

//初始化當前的圖層

boolgamescene::init()

voidgamescene::menucallback(ref* psender)

//觸控開始時呼叫

voidgamescene::ontouchesbegan(conststd::vector& touches, event *unused_event)

}

//觸控移動時呼叫

voidgamescene::ontouchesmoved(conststd::vector& touches, event *unused_event)

//觸控結束時呼叫

voidgamescene::ontouchesended(conststd::vector& touches, event *unused_event)

//取消觸控時呼叫

voidgamescene::ontouchescancelled(conststd::vector&touches, event *unused_event)

備註:關鍵掌握對容器touches中成員的遍歷。c++11新特性中,for 語句將允許簡單的範圍迭代:第一部分定義被用來做範圍迭代的變數,就像被宣告在一般for迴圈的變數一樣,其作用域僅只於迴圈的範圍。而在":"之後的第二區塊,代表將被迭代的範圍。這樣一來,就有了能夠允許c-style陣列被轉換成範圍概念的概念圖。這可以是std::vector,或是其他符合範圍概念的物件。

cocos2d x3 2 多點縮放單點滑動

重設bgsprite錨點和位置 bgsprite setanchorpoint vec2 anchorx,anchory bgsprite setposition vec2 absmidx,absmidy 根據兩觸控點前後的距離計算縮放倍率 auto scale bgsprite getscale ...

cocos2d x 3 2建立專案方法

1.首先開啟終端,cd到cocos2d x 3.2目錄下,執行命令.setup.py 根據提示設定相應的ndk路徑ndk root,sdk路徑 android sdk root,ant路徑 ant root,cocos2d路徑cocos console root cocos2d x 3.2 tool...

Cocos2dx 3 x多點觸控問題

首先,這並不是什麼教程。只是今天折騰了一天的乙個比較傻的問題。3.x的eventlistener想必各位已經都會了。toucheventallatonce是多點觸控,但幾乎沒什麼人用過。用法不難,但是很多人和我一樣卡在了無論怎麼搞touches的數量都只有一,換句話說,就是死活單點觸控。搜了很多論壇...