forked from robterrell/cocos2d-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayer.js
78 lines (64 loc) · 2.41 KB
/
Layer.js
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
'use strict'
var util = require('util')
, events = require('events')
, ccp = require('geometry').ccp
var Node = require('./Node').Node
, Director = require('../Director').Director
, EventDispatcher = require('../EventDispatcher').EventDispatcher
/**
* @class
* A fullscreen Node. You need at least 1 layer in your app to add other nodes to.
*
* @memberOf cocos.nodes
* @extends cocos.nodes.Node
*/
function Layer () {
Layer.superclass.constructor.call(this)
var s = Director.sharedDirector.winSize
this.isRelativeAnchorPoint = false
this.anchorPoint = ccp(0.5, 0.5)
this.contentSize = s
events.addPropertyListener(this, 'isMouseEnabled', 'change', function () {
if (this.isRunning) {
if (this.isMouseEnabled) {
EventDispatcher.sharedDispatcher.addMouseDelegate({delegate: this, priority: this.mouseDelegatePriority})
} else {
EventDispatcher.sharedDispatcher.removeMouseDelegate({delegate: this})
}
}
}.bind(this))
events.addPropertyListener(this, 'isKeyboardEnabled', 'change', function () {
if (this.isRunning) {
if (this.isKeyboardEnabled) {
EventDispatcher.sharedDispatcher.addKeyboardDelegate({delegate: this, priority: this.keyboardDelegatePriority})
} else {
EventDispatcher.sharedDispatcher.removeKeyboardDelegate({delegate: this})
}
}
}.bind(this))
}
Layer.inherit(Node, /** @lends cocos.nodes.Layer# */ {
isMouseEnabled: false
, isKeyboardEnabled: false
, mouseDelegatePriority: 0
, keyboardDelegatePriority: 0
, onEnter: function () {
if (this.isMouseEnabled) {
EventDispatcher.sharedDispatcher.addMouseDelegate({delegate: this, priority: this.mouseDelegatePriority})
}
if (this.isKeyboardEnabled) {
EventDispatcher.sharedDispatcher.addKeyboardDelegate({delegate: this, priority: this.keyboardDelegatePriority})
}
Layer.superclass.onEnter.call(this)
}
, onExit: function () {
if (this.isMouseEnabled) {
EventDispatcher.sharedDispatcher.removeMouseDelegate({delegate: this})
}
if (this.isKeyboardEnabled) {
EventDispatcher.sharedDispatcher.removeKeyboardDelegate({delegate: this})
}
Layer.superclass.onExit.call(this)
}
})
module.exports.Layer = Layer