@@ -13,6 +13,90 @@ var InputManager = new Class({
1313 SceneInputManager . call ( this , scene , game ) ;
1414 } ,
1515
16+ processUpEvents : function ( pointer , currentlyOver )
17+ {
18+ // If the pointer is released we need to reset all 'isDown' IOs, regardless if pointer is still over them or not
19+ // Also concat in the currentlyOver, so we can dispatch an UP event for an IO that has the pointer over it.
20+ // For example if you click down outside a sprite, hold down, move over the sprite, then release, the sprite will
21+ // still fire an UP event, even though it never previously received a DOWN event.
22+ var previouslyDown = this . children . down [ pointer . id ] . concat ( currentlyOver ) ;
23+
24+ if ( previouslyDown . length === 0 )
25+ {
26+ // Dispatch UP event, even though nothing was down previously
27+ this . events . dispatch ( new InputEvent . UP ( pointer ) ) ;
28+ }
29+ else
30+ {
31+ // Go through all objects the pointer was previously down on and set to up
32+ for ( var i = 0 ; i < previouslyDown . length ; i ++ )
33+ {
34+ var interactiveObject = previouslyDown [ i ] ;
35+
36+ if ( ! this . topOnly || ( this . topOnly && i === 0 ) )
37+ {
38+ this . events . dispatch ( new InputEvent . UP ( pointer , interactiveObject . gameObject , previouslyDown ) ) ;
39+ }
40+
41+ this . childOnUp ( i , pointer , interactiveObject ) ;
42+ }
43+ }
44+
45+ // Reset the down array
46+ this . children . down [ pointer . id ] . length = 0 ;
47+ } ,
48+
49+ processDownEvents : function ( pointer , currentlyOver )
50+ {
51+ if ( currentlyOver . length === 0 )
52+ {
53+ // Dispatch DOWN event, even though nothing was below the pointer
54+ this . events . dispatch ( new InputEvent . DOWN ( pointer ) ) ;
55+ }
56+ else
57+ {
58+ // Go through all objects the pointer was over and set them to down
59+ for ( var i = 0 ; i < currentlyOver . length ; i ++ )
60+ {
61+ var interactiveObject = currentlyOver [ i ] ;
62+
63+ this . events . dispatch ( new InputEvent . DOWN ( pointer , interactiveObject . gameObject , currentlyOver ) ) ;
64+
65+ this . childOnDown ( pointer , interactiveObject ) ;
66+
67+ if ( this . topOnly )
68+ {
69+ break ;
70+ }
71+ }
72+ }
73+ } ,
74+
75+ childOnUp : function ( index , pointer , interactiveObject )
76+ {
77+ interactiveObject . isDown = false ;
78+
79+ // If we are not processing topOnly items, or we are and this IS the topmost item, then hit it
80+ if ( ! this . topOnly || ( this . topOnly && index === 0 ) )
81+ {
82+ interactiveObject . onUp ( interactiveObject . gameObject , pointer ) ;
83+ }
84+ } ,
85+
86+ childOnDown : function ( pointer , interactiveObject )
87+ {
88+ interactiveObject . isDown = true ;
89+
90+ interactiveObject . onDown ( interactiveObject . gameObject , pointer , interactiveObject . localX , interactiveObject . localY ) ;
91+
92+ this . children . down [ pointer . id ] . push ( interactiveObject ) ;
93+
94+ // if (input.draggable && !input.isDragged)
95+ // {
96+ // this.gameObjectOnDragStart(pointer, gameObject);
97+ // }
98+ } ,
99+
16100 /*
17101 processOverOutEvents: function (pointer, currentlyOver)
18102 {
0 commit comments