Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Game slow down

    Help
    6
    26
    1324
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Discostew
      Discostew F @waldron last edited by

      @waldron You're trying to draw only what is going to be visible, yes? So what you need is to keep track of the position within the level, then work with that. If you're making a horizontal scroller where it scrolls from left to right (no vertical scrolling), the left-most position would be position 0. The width of what the camera displays extends from the left of the screen to the right of the screen. Assume a display dimension of 400x256 pixels. If your tiles are 16x16 pixels, then you can fill the display with 25x16 tiles (assume 26x16 for a horizontal scroller because when you scroll, you'll be moving in pixels where tiles can crop on the sides, so technically one extra column to render).

      So, the camera displays from position 0 to 400 (in pixels). Than means you'll be drawing the tiles columns from columns 0 to column 25 (divide positions by the width of the tile size). If you move right by 16 pixels, then it displays from position 16 to 416. If you convert that to tile position (divide by 16), that could make for columns 1 and columns 26. So you'd draw from column 1 to column 26. Now, what if you move right only an extra 8 pixels? Well, that is now position 24 to position 424. Dividing by 16 to get the tile range results in column 1.5 and 26.5.

      So how does one work with that? Simple. Take the whole number position (1 and 26), and draw from the left column to the right. This will result in the right side having an empty portion because you only compensated for 25 columns. This is why you should draw one additional column beyond the display range. This sort of design can allow you to have a large area, yet only have to deal with displaying a small section. You're basically cropping out everything except the area that you need to work with.

      waldron 1 Reply Last reply Reply Quote 0
      • waldron
        waldron F @Discostew last edited by

        @Discostew martins working on it, i understand what needs to happen but to make it happen im at a loss

        1 Reply Last reply Reply Quote 0
        • Martin
          Martin Fuze Team last edited by Martin

          basically arrtived at this:

          drawX = floor(playerX / tsize)
          
          drawLevelChunk(level, drawX, scale)
          drawLevelChunk(levelb, drawX, scale)
          
          /**
           * Draw a chunk of a level (nothing to do with draw
           * windows, this function exists because the levels
           * are so big the same code is called multiple times)
           * _l - level array
           * _x - current player position in tiles
           * _s - scale
           */
          function drawLevelChunk(_l, _x, _s)
              _low = _x - 7
              _high = _x + 22
              _max = len(_l[0])
          
              for row = 0 to len(_l) loop
                  for col = clamp(_low, 0, _x) to clamp(_high, _x, _max) loop
                      if _l[row][col] >= 0 then
                          x = col * tsize    // tsize is defined outside
                          y = (row * levelOffset) * tsize
                          drawSheet(tileSheet, tiles[_l[row][cold]], x - screenX, y, _s)
                      endif
                  repeat
              repeat
          return void
          

          The -7 and +22 are the values that are currently enough to smoothly draw "just enough"

          1 Reply Last reply Reply Quote 0
          • Martin
            Martin Fuze Team last edited by

            Oh, PS: Not overly surprisingly after this the game is back up to 60fps and CPU is down to around 4% so plenty of headroom.

            The editor is still choking when it comes to displaying a 200 x 9 array so I'll taise that as a big if it is not already.

            1 Reply Last reply Reply Quote 0
            • waldron
              waldron F last edited by

              After messing with a single array and extending it, it still crashes

              1 Reply Last reply Reply Quote 0
              • Martin
                Martin Fuze Team last edited by

                Care to be a bit more specific? What crashes? The editor when you try to display the array, or the game when you run it? If it's the game when you run it, in what way does it crash? A hang? A crash to the home screen?

                waldron 1 Reply Last reply Reply Quote 0
                • waldron
                  waldron F @Martin last edited by

                  @Martin on the code editor it crashes (error the software has to to closed....) then takes me back to the home screen, sometimes it wil come up with an error and freeze so il have to home button out close software then shut down console if i want it to work again.
                  this happens while editing the array.
                  the issue seems to be code longer then 200 characters in length will cause this iv only tested it with level array code.
                  thought it was due to me having 3 separate level arrays but i tested the tutorial kennys 2d array
                  and extended that which takes me to the drawsheet function of code or crashes

                  1 Reply Last reply Reply Quote 0
                  • waldron
                    waldron F last edited by

                    think im going to abandon the whole level array and start using the map editor iv been testing it last night and i crashed that to but i extended it way longer then what i need for a single level so
                    time to build skater kid for the 6th time but now i have to get used to plotting things on screen without a column and row

                    1 Reply Last reply Reply Quote 0
                    • Martin
                      Martin Fuze Team last edited by

                      Regarding the editor, does it still crash if you split the lines up like I showed you?

                      waldron 1 Reply Last reply Reply Quote 0
                      • waldron
                        waldron F @Martin last edited by

                        @Martin yeah i managed to fit about the same as i would of originally

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post