Map of ARPG Web game (iii)

Source: Internet
Author: User

The map chunked load class Mapengine, which mainly contains the following properties:

      1. G map layer graphics, map will be drawn on top
      2. Buffpixelrange Map Load Range Rectangle
      3. ViewPort screen window
      4. Currzonearr a map block that has already been loaded
      5. Waitloadzone to load Map blocks
      6. Showzone loading completes the map block that will be displayed
      7. PRELOADERNMU number of pre-loaded blocks

Next to the map layer graphics,graphics is actually a Shape object, I put all the loaded map blocks, draw to the graphics, there are many more bitmap objects or shape objects stacked to the map layer, or create the same big bitmap as the screen window. Every time I draw to this, this is the way I started to touch the web game. After the attempt, the way after the hair, in the push map, the more powerful, directly painted on the graphics, may give toys ah the best experience, this is also cracked a variety of web game code, refer to most of the page game push graph algorithm, finally summed up, formed I now use. In addition, the number of pre-loaded blocks, PRELOADERNMU I set to 1, is the relative screen window, the actual calculation of the map block, I have to add a piece up and down, so as to provide the player experience. The specific loading algorithm is as follows:

         Public functionCalcloadzone ():void        {            varRect:rectangle =Viewport.viewrect; varTilesize:int =sceneconfig.tile_size; varScale Number= 1/tilesize; varleftx:int = Int (rect.x * scale)-Preloadernmu; varlefty:int = Int (RECT.Y * scale)-Preloadernmu; varrightx:int = Int (rect.x + rect.width) * scale +Preloadernmu; varrighty:int = Int (rect.y + rect.height) * scale +Preloadernmu; LEFTX= Max (0, LEFTX); Lefty= Max (0, Lefty); RIGHTX=min (rightx, maxmapcountx); righty=min (righty, maxmapcounty); Buffpixelrange.x= LEFTX *tilesize; Buffpixelrange.y= Lefty *tilesize; Buffpixelrange.width= (RIGHTX-LEFTX + 1) *tilesize; Buffpixelrange.height= (righty-lefty + 1) *tilesize; varCenterx:int = (LEFTX + rightx) * 0.5; varCentery:int = (lefty + righty) * 0.5; varTemp:int = 0; varKey:int = 0; varZone:zone =NULL;  while(Lefty <=righty) {Temp=LEFTX;  while(Temp <=rightx) {Key= temp + lefty *Titlex; Zone=Currzonearr[key]; Determine if this map block has been loadedif(Zone = =NULL) {Zone=NewZone (); Zone.xpos=temp; Zone.ypos=lefty; Currzonearr[key]=Zone; Zone.dis= Pow (Temp-centerx, 2) + POW (lefty-centery, 2); Calculate the distance from the center of the load range Waitloadzone[waitloadzone.length]=Zone;//Add to load queue} temp++; } lefty++; } waitloadzone.sort (Sortbydis); Sort the map blocks that you want to be on}

The above code, the important part has been commented. The sort function, separately, there are many effects of loading the map, there will be an animation effect, is the map block display, is displayed from the center, and then gradually expanded to four weeks. Therefore, the map block in the center of the loading range is loaded first, so that it will be near the center, loaded, and will show priority.

Before the player enters the map, it takes priority to download the small map, so before all the map blocks are loaded, zoom in on the small map and draw directly onto the graphics to achieve the mosaic effect. In order to improve the player's experience, only one map block is loaded in the loop of each frame, and only the map block is shown. The average page frame rate is not 30 frames a second, in theory a pin shows a map block. The code is as follows:

 

         Public functionRender (Param1:int, param2: Number) :void        {            varZone2:zone; varZone:zone; varLoadinfo:iloadinfo; varSize:int; varStepframe:int =param1; varSteptime: Number=param2; if(Waitloadzone.length > 0)//load only one map block {zone=Waitloadzone.shift (); Loadinfo=Api.loadCenter.getNewLoadInfo (); Loadinfo.url= GetPath (Getmapid (), Zone.xpos +"_"+Zone.ypos); Loadinfo.completehanlder=function(PARAM1:BITMAP):void                {                    varKey:int = Zone.xpos + Zone.ypos *Titlex; if(Loadingdic[key]! =undefined) {Loadingdic[key]=NULL; DeleteLoadingdic[key]; }                    if(!zone.iscomplete) {zone.bpd=Param1.bitmapdata;                    Showzone.push (zone);                    } loadeddic.push (Loadinfo.url); return;            } api.loadCenter.addLoadInfo (Loadinfo); }             while(showzone.length)//Show only one map block that has been loaded {Zone2=Showzone.shift (); Size=sceneconfig.tile_size;                G.beginbitmapfill (ZONE2.BPD); G.drawrect (Zone2.xpos* Size, Zone2.ypos *size, size, size);  Break; }            return; }

There may be doubts about why each frame is loaded, and only one block of map is displayed. Why not according to, after loading, or loaded, why not directly draw on the map layer. We all know the AS3.0 rendering mechanism, the runway model. If the as-per-frame process is too much, there will be a case of card frames. The purpose of this is to try to divide some operations evenly on this frame, as far as possible to smooth and smooth-dominated, is an optimization strategy. Maybe some people have high machine configuration, or fast speed, his experience will be better, it is true. But the human eye can recognize the minimum frequency of 24 frames, some movies are played at 24 frames of frequency animation, so the calculation of the allocation of some of the various frames, for the player, the experience is not much worse, the scope of increased smoothness and smoothness.

Reprint please indicate the source

  

  

Map of ARPG Web game (iii)

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.