Closed andyg0808 closed 2 years ago
Magic, thank you! I'm committing the changes you suggested. I intend to use a spritesheet to animate this as it will be cleaner than declaring (and storing) 11 different .png files but I'm leaving that for another time. Keen to get some other functionality in first.
https://github.com/mhomami/Tank/blob/74e115e25ae04a530c524b3d3756b83eb56cb745/js/script.js#L32-L37
Instead of looping over an array and writing to it, I'd suggest using the
map()
function:map()
runs a function on each element of an array. Here, we're passing a short arrow function which just takes the element and returns the result of passing it toPIXI.Texture.from
.By using a
map()
, we can express that we want "every entry inbitsImages
to be converted into an entry intextureArray
." It also eliminates a bunch of the extra bookkeeping work (like keeping track of the index) that we'd have to do if we wrote the loop by hand.