HTML Canvas | Grab rows of data from an array using X/Y coordinates and a view-port width/height

Viewed 30

Let's say I have a array of numbers denoting a tilemap (64x64) and a player x,y coordinate. I also have a viewport (in tiles). Using those, I can create a 5x5 tilemap (viewport) with a player x,y and draw it like so:

https://codesandbox.io/s/map-loader-only-viewport-6jhric?file=/src/index.js

The problem I am running into is that when I grab the layer[] array... I have to comb through the whole arrayset.

Could I just not grab the tiles needed and send over 25 array (5x5) elements instead of the whole map (400 array elements)

0 Answers
Related