Autotile automatic splicing (ii) Learning and practice

Source: Internet
Author: User

Before we start the code, we need to do some preparatory work.

Follow me to do it below.

First I deducted a picture.

This is the water resources, so is dynamic, I have the remaining two also buckle out.

Looks the same, is not, this certainly does not see the why, you first put in the u3d.

Then can watch in the lower right corner, these I will not say more, general small white metropolis.

Next, we want to slice, you see I have 11 of the figure cut.

This cut chart, I think we should also be. Cut the squares in such a way.

Well, I'll just say it, according to this ...

The purpose of this is to divide the graph into small pieces, the foreigner with a matrix cut diagram, I tool advanced, manual fix.

Now we're going to save these sliced images in the array.

I wrote a save code before.

usingUnityengine;usingSystem.Collections;usingUnityengine.ui;usingSystem.Collections.Generic; Public Abstract classdirectionsprite:monobehaviour{ Public floatSpeed =0.05f; PrivateSprite M_image; Private floatM_delta =0; [Hideininspector] Public intM_curframe =0; [Hideininspector] Public BOOLOpen =true; //end of a loop     Public Abstract voidNextsprite (); Privatesprite[,] dict;  Public voidStartopen (BOOLOpensstringpath) {Open=opens; if(Open) {m_image= gameobject.getcomponent<spriterenderer>(). Sprite; if(M_image = =NULL) {M_image= gameobject.addcomponent<spriterenderer>(). Sprite;            } string_int_movie (path);        Show (M_curframe); }    }     Public intRow, col; voidString_int_movie (stringpath) {        Object[] Objs =Resources.loadall (path); Dict=NewSprite[row, Col]; inti =0; foreach(ObjectObjinchObjs) {Sprite SP= obj asSprite; if(sp! =NULL) {Dict[i/col, I% col] =sp; I++; }        }    }     Public voidUpdatasprite () {if(Open) {M_delta+=Time.deltatime; if(M_delta >Speed ) {M_delta=0; M_curframe++;            Show (M_curframe); }        }    }    //Set     Public voidAngle_frame (intAngles,intm_curframes) {Angle=Angles; M_curframe=M_curframes; }     Public intFramecount {Get        {            returnDict.        Length; }} [Hideininspector] Public intAngle;  Public voidShowintframe) {        if(Frame >=Col)            {Nextsprite (); Frame=0; M_curframe=frame; }        if(Angle <0) {Angle=0; }        if(Angle > Row-1) {Angle= Row-1; } m_image=dict[angle, frame]; Gameobject.getcomponent<SpriteRenderer> (). Sprite =M_image; }}

usingUnityengine;usingSystem.Collections; Public classDirectsprite:directionsprite { Public intStartmovie;  Public stringpath; voidStart () {Open=true;    Startopen (open, path); }    voidUpdate () {if(startmovie>0) {updatasprite (); }     }    //end of a loop     Public Override voidNextsprite () {Startmovie--; Open=true; } }

In this way, I'll look back and see what needs to be changed.

After that, after saving the data, we begin to write the core code in the next chapter. Goodbye to the next article

Autotile automatic splicing (ii) Learning and practice

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.