@@ -120,11 +120,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
120
120
_textureLoaded :false ,
121
121
_className :"Sprite" ,
122
122
123
- //Only for texture update judgment
124
- _oldDisplayColor : cc . color . WHITE , //TODO move to Canvas render
125
-
126
123
_originalTexture : null , //TODO move to Canvas render cmd
127
- _drawSize_Canvas : null ,
128
124
129
125
ctor : function ( fileName , rect , rotated ) {
130
126
var self = this ;
@@ -522,7 +518,12 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
522
518
* @function
523
519
* @param {Boolean } modify
524
520
*/
525
- setOpacityModifyRGB :null ,
521
+ setOpacityModifyRGB : function ( modify ) {
522
+ if ( this . _opacityModifyRGB !== modify ) {
523
+ this . _opacityModifyRGB = modify ;
524
+ this . _renderCmd . _updateColor ( ) ;
525
+ }
526
+ } ,
526
527
527
528
/**
528
529
* Returns whether opacity modify color or not.
@@ -532,12 +533,6 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
532
533
return this . _opacityModifyRGB ;
533
534
} ,
534
535
535
- /**
536
- * Update the display opacity.
537
- * @function
538
- */
539
- updateDisplayedOpacity : null ,
540
-
541
536
// Animation
542
537
543
538
/**
@@ -653,7 +648,36 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
653
648
* @function
654
649
* @return {Boolean }
655
650
*/
656
- init :null ,
651
+ init : function ( ) {
652
+ var _t = this ;
653
+ if ( arguments . length > 0 )
654
+ return _t . initWithFile ( arguments [ 0 ] , arguments [ 1 ] ) ;
655
+
656
+ cc . Node . prototype . init . call ( _t ) ;
657
+ _t . dirty = _t . _recursiveDirty = false ;
658
+
659
+ _t . _blendFunc . src = cc . BLEND_SRC ;
660
+ _t . _blendFunc . dst = cc . BLEND_DST ;
661
+
662
+ _t . texture = null ;
663
+ _t . _textureLoaded = true ;
664
+ _t . _flippedX = _t . _flippedY = false ;
665
+
666
+ // default transform anchor: center
667
+ _t . anchorX = 0.5 ;
668
+ _t . anchorY = 0.5 ;
669
+
670
+ // zwoptex default values
671
+ _t . _offsetPosition . x = 0 ;
672
+ _t . _offsetPosition . y = 0 ;
673
+ _t . _hasChildren = false ;
674
+
675
+ this . _renderCmd . init ( ) ;
676
+ // updated in "useSelfRender"
677
+ // Atlas: TexCoords
678
+ _t . setTextureRect ( cc . rect ( 0 , 0 , 0 , 0 ) , false , cc . size ( 0 , 0 ) ) ;
679
+ return true ;
680
+ } ,
657
681
658
682
/**
659
683
* <p>
@@ -696,8 +720,6 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
696
720
*/
697
721
initWithTexture : null ,
698
722
699
- _textureLoadedCallback : null ,
700
-
701
723
/**
702
724
* Updates the texture rect of the CCSprite in points.
703
725
* @function
@@ -724,20 +746,6 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
724
746
*/
725
747
addChild : null ,
726
748
727
- /**
728
- * Sets opacity of the sprite
729
- * @function
730
- * @param {Number } opacity
731
- */
732
- setOpacity :null ,
733
-
734
- /**
735
- * Sets color of the sprite
736
- * @function
737
- * @param {cc.Color } color3
738
- */
739
- setColor : null ,
740
-
741
749
/**
742
750
* Updates the display color
743
751
* @function
@@ -768,7 +776,9 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
768
776
* @param {cc.SpriteFrame } frame
769
777
* @return {Boolean }
770
778
*/
771
- isFrameDisplayed : null ,
779
+ isFrameDisplayed : function ( frame ) {
780
+ return this . _renderCmd . isFrameDisplayed ( frame ) ;
781
+ } ,
772
782
773
783
/**
774
784
* Returns the current displayed frame.
@@ -800,25 +810,27 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
800
810
* @function
801
811
* @param {cc.Texture2D|String } texture
802
812
*/
803
- setTexture : null ,
804
-
805
- // Texture protocol
806
- _updateBlendFunc :function ( ) {
807
- if ( this . _batchNode ) {
808
- cc . log ( cc . _LogInfos . Sprite__updateBlendFunc ) ;
813
+ setTexture : function ( texture ) {
814
+ var _t = this ;
815
+ if ( texture && ( cc . isString ( texture ) ) ) {
816
+ texture = cc . textureCache . addImage ( texture ) ;
817
+ _t . setTexture ( texture ) ;
818
+ //TODO
819
+ var size = texture . getContentSize ( ) ;
820
+ _t . setTextureRect ( cc . rect ( 0 , 0 , size . width , size . height ) ) ;
821
+ //If image isn't loaded. Listen for the load event.
822
+ if ( ! texture . _isLoaded ) {
823
+ texture . addEventListener ( "load" , function ( ) {
824
+ var size = texture . getContentSize ( ) ;
825
+ _t . setTextureRect ( cc . rect ( 0 , 0 , size . width , size . height ) ) ;
826
+ } , this ) ;
827
+ }
809
828
return ;
810
829
}
830
+ // CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteSheet
831
+ cc . assert ( ! texture || texture instanceof cc . Texture2D , cc . _LogInfos . Sprite_setTexture_2 ) ;
811
832
812
- // it's possible to have an untextured sprite
813
- if ( ! this . _texture || ! this . _texture . hasPremultipliedAlpha ( ) ) {
814
- this . _blendFunc . src = cc . SRC_ALPHA ;
815
- this . _blendFunc . dst = cc . ONE_MINUS_SRC_ALPHA ;
816
- this . opacityModifyRGB = false ;
817
- } else {
818
- this . _blendFunc . src = cc . BLEND_SRC ;
819
- this . _blendFunc . dst = cc . BLEND_DST ;
820
- this . opacityModifyRGB = true ;
821
- }
833
+ this . _renderCmd . _setTexture ( texture ) ;
822
834
} ,
823
835
824
836
_createRenderCmd : function ( ) {
@@ -873,48 +885,6 @@ cc.Sprite.INDEX_NOT_INITIALIZED = -1;
873
885
if ( cc . _renderType === cc . _RENDER_TYPE_CANVAS ) {
874
886
var _p = cc . Sprite . prototype ;
875
887
876
- _p . setOpacityModifyRGB = function ( modify ) {
877
- if ( this . _opacityModifyRGB !== modify ) {
878
- this . _opacityModifyRGB = modify ;
879
- this . setNodeDirty ( true ) ;
880
- }
881
- } ;
882
-
883
- _p . updateDisplayedOpacity = function ( parentOpacity ) {
884
- cc . Node . prototype . updateDisplayedOpacity . call ( this , parentOpacity ) ;
885
- this . _setNodeDirtyForCache ( ) ;
886
- } ;
887
-
888
- _p . init = function ( ) {
889
- var _t = this ;
890
- if ( arguments . length > 0 )
891
- return _t . initWithFile ( arguments [ 0 ] , arguments [ 1 ] ) ;
892
-
893
- cc . Node . prototype . init . call ( _t ) ;
894
- _t . dirty = _t . _recursiveDirty = false ;
895
-
896
- _t . _blendFunc . src = cc . BLEND_SRC ;
897
- _t . _blendFunc . dst = cc . BLEND_DST ;
898
-
899
- _t . texture = null ;
900
- _t . _textureLoaded = true ;
901
- _t . _flippedX = _t . _flippedY = false ;
902
-
903
- // default transform anchor: center
904
- _t . anchorX = 0.5 ;
905
- _t . anchorY = 0.5 ;
906
-
907
- // zwoptex default values
908
- _t . _offsetPosition . x = 0 ;
909
- _t . _offsetPosition . y = 0 ;
910
- _t . _hasChildren = false ;
911
-
912
- // updated in "useSelfRender"
913
- // Atlas: TexCoords
914
- _t . setTextureRect ( cc . rect ( 0 , 0 , 0 , 0 ) , false , cc . size ( 0 , 0 ) ) ;
915
- return true ;
916
- } ;
917
-
918
888
_p . initWithTexture = function ( texture , rect , rotated ) {
919
889
var _t = this ;
920
890
cc . assert ( arguments . length != 0 , cc . _LogInfos . CCSpriteBatchNode_initWithTexture ) ;
@@ -945,8 +915,7 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
945
915
_t . _flippedX = _t . _flippedY = false ;
946
916
947
917
// default transform anchor: center
948
- _t . anchorX = 0.5 ;
949
- _t . anchorY = 0.5 ;
918
+ _t . setAnchorPoint ( 0.5 , 0.5 ) ;
950
919
951
920
// zwoptex default values
952
921
_t . _offsetPosition . x = 0 ;
@@ -966,14 +935,13 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
966
935
}
967
936
if ( _t . texture )
968
937
_t . texture . removeEventListener ( "load" , _t ) ;
969
- texture . addEventListener ( "load" , _t . _textureLoadedCallback , _t ) ;
938
+ texture . addEventListener ( "load" , _t . _renderCmd . _textureLoadedCallback , _t ) ;
970
939
_t . texture = texture ;
971
940
return true ;
972
941
}
973
942
974
- if ( ! rect ) {
943
+ if ( ! rect )
975
944
rect = cc . rect ( 0 , 0 , texture . width , texture . height ) ;
976
- }
977
945
978
946
if ( texture && texture . url ) {
979
947
var _x = rect . x + rect . width , _y = rect . y + rect . height ;
@@ -994,35 +962,6 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
994
962
return true ;
995
963
} ;
996
964
997
- _p . _textureLoadedCallback = function ( sender ) {
998
- var _t = this ;
999
- if ( _t . _textureLoaded )
1000
- return ;
1001
-
1002
- _t . _textureLoaded = true ;
1003
- var locRect = _t . _rect ;
1004
- if ( ! locRect ) {
1005
- locRect = cc . rect ( 0 , 0 , sender . width , sender . height ) ;
1006
- } else if ( cc . _rectEqualToZero ( locRect ) ) {
1007
- locRect . width = sender . width ;
1008
- locRect . height = sender . height ;
1009
- }
1010
- _t . _originalTexture = sender ;
1011
-
1012
- _t . texture = sender ;
1013
- _t . setTextureRect ( locRect , _t . _rectRotated ) ;
1014
-
1015
- //set the texture's color after the it loaded
1016
- var locColor = this . _displayedColor ;
1017
- if ( locColor . r != 255 || locColor . g != 255 || locColor . b != 255 )
1018
- _t . _changeTextureColor ( ) ;
1019
-
1020
- // by default use "Self Render".
1021
- // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
1022
- _t . batchNode = _t . _batchNode ;
1023
- _t . dispatchEvent ( "load" ) ;
1024
- } ;
1025
-
1026
965
_p . setTextureRect = function ( rect , rotated , untrimmedSize ) {
1027
966
var _t = this ;
1028
967
_t . _rectRotated = rotated || false ;
@@ -1055,7 +994,6 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
1055
994
1056
995
_p . updateTransform = function ( ) {
1057
996
var _t = this ;
1058
- //cc.assert(_t._batchNode, "updateTransform is only valid when cc.Sprite is being rendered using an cc.SpriteBatchNode");
1059
997
1060
998
// re-calculate matrix only if it is dirty
1061
999
if ( _t . dirty ) {
@@ -1095,23 +1033,6 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
1095
1033
this . _hasChildren = true ;
1096
1034
} ;
1097
1035
1098
- _p . setOpacity = function ( opacity ) {
1099
- cc . Node . prototype . setOpacity . call ( this , opacity ) ;
1100
- this . _setNodeDirtyForCache ( ) ;
1101
- } ;
1102
-
1103
- _p . updateDisplayedColor = function ( parentColor ) {
1104
- var _t = this ;
1105
- cc . Node . prototype . updateDisplayedColor . call ( _t , parentColor ) ;
1106
- var oColor = _t . _oldDisplayColor ;
1107
- var nColor = _t . _displayedColor ;
1108
- if ( oColor . r === nColor . r && oColor . g === nColor . g && oColor . b === nColor . b )
1109
- return ;
1110
-
1111
- _t . _changeTextureColor ( ) ;
1112
- _t . _setNodeDirtyForCache ( ) ;
1113
- } ;
1114
-
1115
1036
_p . setSpriteFrame = function ( newFrame ) {
1116
1037
var _t = this ;
1117
1038
if ( cc . isString ( newFrame ) ) {
@@ -1160,12 +1081,6 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
1160
1081
}
1161
1082
} ;
1162
1083
1163
- _p . isFrameDisplayed = function ( frame ) { //TODO there maybe has a bug
1164
- if ( frame . getTexture ( ) != this . _texture )
1165
- return false ;
1166
- return cc . rectEqualToRect ( frame . getRect ( ) , this . _rect ) ;
1167
- } ;
1168
-
1169
1084
_p . setBatchNode = function ( spriteBatchNode ) {
1170
1085
var _t = this ;
1171
1086
_t . _batchNode = spriteBatchNode ; // weak reference
@@ -1183,35 +1098,6 @@ if (cc._renderType === cc._RENDER_TYPE_CANVAS) {
1183
1098
}
1184
1099
} ;
1185
1100
1186
- _p . setTexture = function ( texture ) {
1187
- var _t = this ;
1188
- if ( texture && ( cc . isString ( texture ) ) ) {
1189
- texture = cc . textureCache . addImage ( texture ) ;
1190
- _t . setTexture ( texture ) ;
1191
- //TODO
1192
- var size = texture . getContentSize ( ) ;
1193
- _t . setTextureRect ( cc . rect ( 0 , 0 , size . width , size . height ) ) ;
1194
- //If image isn't loaded. Listen for the load event.
1195
- if ( ! texture . _isLoaded ) {
1196
- texture . addEventListener ( "load" , function ( ) {
1197
- var size = texture . getContentSize ( ) ;
1198
- _t . setTextureRect ( cc . rect ( 0 , 0 , size . width , size . height ) ) ;
1199
- } , this ) ;
1200
- }
1201
- return ;
1202
- }
1203
-
1204
- // CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteSheet
1205
- cc . assert ( ! texture || texture instanceof cc . Texture2D , cc . _LogInfos . CCSpriteBatchNode_setTexture ) ;
1206
-
1207
- if ( _t . _texture != texture ) {
1208
- if ( texture && texture . getHtmlElementObj ( ) instanceof HTMLImageElement ) {
1209
- _t . _originalTexture = texture ;
1210
- }
1211
- _t . _texture = texture ;
1212
- }
1213
- } ;
1214
-
1215
1101
_p = null ;
1216
1102
} else {
1217
1103
cc . assert ( cc . isFunction ( cc . _tmp . WebGLSprite ) , cc . _LogInfos . MissingFile , "SpritesWebGL.js" ) ;
0 commit comments