Android game interface sometimes because of the layout of the beautiful, you need to swap the two icon position. These two icons are not simple to change the ID number can be, the following is the way to exchange two icons.
Related programs in the original code:
Not modified before:
float pic_x=200;
float pic_y=130;
The first part of the program that needs to be modified, this part draws the icon in the corresponding interface position using the definition pic_x,pic_y.
First icon Position drawing
if (BACKMUSICFLAG01)
{
Canvas.drawbitmap (Backmusicoff, pic_x, pic_y, paint);
}
else if (!BACKMUSICFLAG01)
{
Canvas.drawbitmap (backmusicon,pic_x, pic_y, paint);
}
The second icon draws a second icon using the value of the Pic_y plus the border to draw a certain gap.
if (YINXIAOFLAG01)
{
float x1=pic_x;
float y1=pic_y+music_height+25;
Canvas.drawbitmap (Yinxiaooff, x1, y1, paint);
}
else if (!YINXIAOFLAG01)
{
float x1=pic_x;
float y1=pic_y+music_height+25;
Canvas.drawbitmap (Yinxiaoon, x1, y1, paint);
}
The second part of the Code to be modified:
This part of the code by listening to whether the flag, if the icon to transform the icons, the code after the label, the original background music turned into a background music off; sound effects music turned on
if (x>pic_x&&x<pic_x+music_weight&&y>pic_y&&y<pic_y+music_height)
{
BACKMUSICFLAG02=!BACKMUSICFLAG02;
Activity.setbackgroundmusicon (BACKMUSICFLAG02);
BACKMUSICFLAG01=!BACKMUSICFLAG01;
}
if (x>pic_x&&x<pic_x+music_weight&&y>pic_y+music_height+25&&y<pic_y+music_ Height+25+music_height)
{
YINXIAOFLAG02=!YINXIAOFLAG02;
Activity.setsoundon (YINXIAOFLAG02);
YINXIAOFLAG01=!YINXIAOFLAG01;
}
The changed code:
The first part of the code after the modification:
if (yinxiaoFlag01)
{
canvas.drawbitmap (yinxiaooff,pic_x, pic_y , paint);
}
else if (!yinxiaoflag01)
{
canvas.drawbitmap (Yinxiaoon, pic_x, pic_y, paint);
}
if (BACKMUSICFLAG01)
{
float x1=pic_x;
float y1=pic_y+music_height+25;
Canvas.drawbitmap (Backmusicoff, x1, y1, paint);
}
else if (!BACKMUSICFLAG01)
{
float x1=pic_x;
float y1=pic_y+music_height+25;
Canvas.drawbitmap (Backmusicon, x1, y1, paint);
}
The second part of the code after the modification:
if (x>pic_x&&x<pic_x+music_weight&&y>pic_y&&y<pic_y+music_height)
{
YINXIAOFLAG02=!YINXIAOFLAG02;
Activity.setsoundon (YINXIAOFLAG02);
YINXIAOFLAG01=!YINXIAOFLAG01;
}
if (x>pic_x&&x<pic_x+music_weight&&y>pic_y+music_height+25&&y<pic_y+music_ Height+25+music_height)
{
BACKMUSICFLAG02=!BACKMUSICFLAG02;
Activity.setbackgroundmusicon (BACKMUSICFLAG02);
BACKMUSICFLAG01=!BACKMUSICFLAG01;
}
Post-modification effects show:
Pre-modification effects:
Summarize:
The modification of this icon, required to modify the two parts, or only modify the first part of the code, when you click on the icon, it will not change the jump changes. must also be modified along with the second part of the action that will be changed.
How to swap two icons in Android game development