[BEHAVIOR] Isometric

Post your completed addons to share with the community

Post » Thu Apr 28, 2016 5:21 pm

Have another question now, since I moved the scroll to center isoView within the layout. How do I translate mouse within isoView to the map grid?
You can use the equation posted above:
mapx = 0.5*x+y+iz-400
mapy = -0.5*x+y+iz-80

just use mouse.x(layer) an mouse.y(layer) for x and y.

For pathfinding you can either try to shrink the grid size, use a grid based pathfinding plugin or do your own pathfinding with events.

Searching for astar or dijkstra will give some event based examples.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Fri Apr 29, 2016 9:55 am

EDIT: I realize the code in Start Layout is setting the size of the tile. Now it looks good. But I would still like to know how the iso sizes are calculated for varying heights :)

@R0J0hound
Really appreciate your help. Will try this out. :)

I ran into another thing. Its with the tile size. Is there a standard formula to calculate the iso Size x,y and z if the height is not same as width (in my case width is 64px and height is 52px)? I followed your mini tutorial but it didnt seem to have any effect on the output.
Attached the tile dimension and out for your reference.
Image
Create your own Isometric Runner Game using C2:

Image

Check out my game "Last of the Survivors":
Play Store
App Store
B
58
S
13
G
2
Posts: 420
Reputation: 5,395

Post » Fri Apr 29, 2016 6:54 pm

In your output it looks like the sprites are resized. The actual sprite size should stay the same.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Thu May 26, 2016 2:08 pm

@R0J0hound
I figured the sprite itself were not in the right isometric angle. I rendered my own tiles and now they look fine!

I was wondering if there is someway I can restrict camera movement only within the Isometric map boundaries when my character is moving? Right now I am using scroll to player.x and y at every tick

I am really struggling with the math :(
Create your own Isometric Runner Game using C2:

Image

Check out my game "Last of the Survivors":
Play Store
App Store
B
58
S
13
G
2
Posts: 420
Reputation: 5,395

Post » Thu May 26, 2016 5:56 pm

@samrock
You just need to loop over all the isometric objects a find the x and y extreme positions. The scroll clamping assumes the iso objects cover more than the screen, so it uses half the screen size (320,240 in this case) to make scrolling stop at the edge.

global number boundleft= 99999
global number boundright= -99999
global number boundtop= 99999
global number boundbottom= -99999

start of layout
for each sprite
--- set boundleft to min(boundleft , sprite.bboxleft)
--- set boundright to max(boundright , sprite.bboxright)
--- set boundtop to min(boundtop , sprite.bboxtop)
--- set boundbottom to max(boundbottom , sprite.bboxbottom)

every tick
--- scroll to (clamp(scrollx, boundleft+320, boundright-320), clamp(scrolly, boundtop+240, boundbottom-240))
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Fri Jul 01, 2016 9:09 pm

Hello there!

Your isometric behavior is awesome but when the game have big layouts with lots of objects the game gets really slow.

I've tested with a layout that had about 1000 objects with your iso and the preview was running at ~5 fps
(With the behavior disabled it was running at 60fps)

Then I've made some changes on the runtime.js of the behavior to ignore all objects outside of the canvas completely and creates an array of references to the remaining objects index numbers before looping over and over again.
Now running at 60fps with the same amount of objects without messing the sorting.

Code: Select all
   behinstProto.tick = function ()
   {
      //alert(window.rojoList.length);
      var refList=[];
      var isoList = this.type.isoList;
      if(this === isoList[0])
      {   
         for (a=0; a < isoList.length;a++)
         {
            var isoA = isoList[a];
            if(this.IsInstOnScreen(isoA.inst))
            {
               refList.push(a);
            }
            else
            {
               isoList[a].behind.length=0;
            }
         }
      }

      if (this === isoList[0] && (this.type.state.enabled || this.type.state.sortOnce))  // only run once
      {
         this.type.state.sortOnce = false;
         var isoA, isoB, a, b, c=0;
         
         // updade positions from isometric positions
         for (a=0; a<refList.length; a++)
         {
            isoA = isoList[refList[a]];
            //isoA.updatePosFromIso();
            isoA.inst.update_bbox();
            isoA.visited=false;
         }

         // build dependency graph
         for (a=0; a<refList.length; a++)
         {
            isoA = isoList[refList[a]];
            
            // culling
            if (!isoA.visited && !isoA.inst.visible && !this.IsInstOnScreen(isoA.inst))
            {
               isoA.visited=true;
               continue;
            }
            
             for (b=0; b<refList.length; b++)
            {
               isoB = isoList[refList[b]];
               
               // culling
               /*if (!isoB.visited && !isoB.inst.visible && !this.IsInstOnScreen(isoB.inst))
               {
                  isoB.visited=true;
                  continue;
               }*/
                  
               if ( isoA != isoB
                  && isoA.inst.bbox.intersects_rect(isoB.inst.bbox)  //bounding box check
                  && isoA.ix-isoA.sx/2 < isoB.ix+isoB.sx/2 -0.001
                  && isoA.iy-isoA.sy/2 < isoB.iy+isoB.sy/2 -0.001
                  && isoA.iz-isoA.sz/2 < isoB.iz+isoB.sz/2 -0.001)
                  {
                     isoA.behind.push(isoB);
                     c++;
                  }
            }

         }
         
         // topo sort
         for (a=0; a<refList.length; a++)
            isoList[refList[a]].visitNode();
      }
   };


\o/
B
7
S
2
Posts: 31
Reputation: 947

Post » Sat Jul 02, 2016 12:55 am

Since the system now offers a reasonable z sorter I guess It really doesn't need it in the plug.
Image ImageImage
B
169
S
50
G
173
Posts: 8,319
Reputation: 110,282

Post » Tue Sep 27, 2016 5:58 am

Hey how can I install this, I get an error saying that GetPluginSettings is global, but not a function. How to fix?
B
15
S
6
G
3
Posts: 11
Reputation: 2,707

Post » Tue Sep 27, 2016 6:24 am

Did you put it under plugs, or behaviors?
Image ImageImage
B
169
S
50
G
173
Posts: 8,319
Reputation: 110,282

Post » Tue Sep 27, 2016 2:30 pm

loved it !!!

Will bookmark it for future use :D :D
Image
B
36
S
13
G
1
Posts: 99
Reputation: 3,051

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 4 guests