@@ -29,11 +29,13 @@ class BasePictorialNode extends Node {
29
29
// Translate everything by our offset
30
30
this . translation = baseNumber . offset ;
31
31
32
+ // @private {EnumerationProperty.<PlayObjectType>}
33
+ this . playObjectTypeProperty = playObjectTypeProperty ;
34
+
32
35
// saves the case from when value is 0
33
36
value = Math . max ( baseNumber . numberValue , value ) ;
34
37
35
38
let backgroundNode ;
36
-
37
39
const objectWidth = CountingCommonConstants . PLAY_OBJECT_SIZE . width ;
38
40
const objectHeight = CountingCommonConstants . PLAY_OBJECT_SIZE . width ;
39
41
const stackOffset = 10 ;
@@ -60,6 +62,7 @@ class BasePictorialNode extends Node {
60
62
}
61
63
62
64
// add and position the object images
65
+ const objectImages = [ ] ;
63
66
for ( let i = 0 ; i < value ; i ++ ) {
64
67
const offset = ( sideMargin + i * stackOffset ) ;
65
68
const objectImage = new Image ( CountingCommonConstants . PLAY_OBJECT_TYPE_TO_IMAGE [ playObjectTypeProperty . value ] , {
@@ -69,10 +72,16 @@ class BasePictorialNode extends Node {
69
72
y : offset
70
73
} ) ;
71
74
this . addChild ( objectImage ) ;
72
- playObjectTypeProperty . link ( playObjectType => {
75
+ objectImages . push ( objectImage ) ;
76
+ }
77
+
78
+ // @private
79
+ this . playObjectTypeListener = playObjectType => {
80
+ objectImages . forEach ( objectImage => {
73
81
objectImage . image = CountingCommonConstants . PLAY_OBJECT_TYPE_TO_IMAGE [ playObjectType ] ;
74
82
} ) ;
75
- }
83
+ } ;
84
+ this . playObjectTypeProperty . link ( this . playObjectTypeListener ) ;
76
85
77
86
// TODO: these should be elminated with future designs, see https://github.com/phetsims/number-play/issues/19
78
87
// add the grippy lines if this number is on the top layer
@@ -92,6 +101,14 @@ class BasePictorialNode extends Node {
92
101
this . addChild ( grippyLines ) ;
93
102
}
94
103
}
104
+
105
+ /**
106
+ * @public
107
+ */
108
+ dispose ( ) {
109
+ this . playObjectTypeProperty . unlink ( this . playObjectTypeListener ) ;
110
+ super . dispose ( ) ;
111
+ }
95
112
}
96
113
97
114
countingCommon . register ( 'BasePictorialNode' , BasePictorialNode ) ;
0 commit comments