Home > other >  How to improve to achieve two different pictures every time? Now is two of the same.
How to improve to achieve two different pictures every time? Now is two of the same.

Time:09-20

Void ThirdGuanScene: : initMap ()
{
Int x=1;
Int y=0;
For (int I=1; i For (int j=1; J & lt; YCount - 1; J++) {
MMap [I] [j]=x;
If (y==1) {
X++;
Y=0;
/* if (x==iconCount) {
x=1;
} */
}
The else {
Y=1;
}
}
}
DrawMap ();
}

Void ThirdGuanScene: : drawMap ()
{
The log ("==================================");
For (int x=0; X & lt; XCount; X++) {
For (int y=0; Y & lt; YCount; Y++) {
If (mMap [x] [y] & gt; 0 {
Char iconName [36]={0};
Sprintf (iconName "1 - % d.p ng", mMap [x] [y]);
The log (" % s "iconName);
The log (" % d ", mMap [x] [y]);
Auto position=indextoScreen (x, y);
Icon=Sprite: : createWithSpriteFrame (SpriteFrameCache: : getInstance () - & gt; GetSpriteFrameByName (iconName));
Icon - & gt; SetPosition (position);
Int tag=(yCount - 2) * (x - 1) + y;
The log (" tag=% d ", the tag);
AddChild (icon, 100, the tag);
}
}
}
}

CodePudding user response:

Every time the value of your iconName

CodePudding user response:

Iconname is fixed 36 images, according to the number size,

CodePudding user response:

reference 1st floor sinat_28338727 response:
every time the value of your iconName?


Iconname is fixed 36 images, according to the number size,

CodePudding user response:

Hello, hello, 666

CodePudding user response:

Code logic is wrong, cocos2dx usually a larger synthesis with plist loading images, efficiency will be good,

CodePudding user response:

Your sprintf (iconName "1 - % d.p ng", mMap [x] [y]); You are shown in the picture is 1, 2, 3, 30, named not 01,02,03,30 naming is, if it is two requires a placeholder
  • Related