How to swap two icons in Android game development

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.