|Topic was automatically imported from the old Question2Answer platform.
So I made a big amount of code that relies on an array. That array gives the positions of certain objects using the 2d array (array[y]). The only problem is that the top left corner of the environment is at -1024,-600. And that is a problem because arrays cannot have negative indexes. So I was wondering if I could move the global origin to -1024,-600 or if there is another work around for my problem, thanks.
Using screen positions as array indices seems really strange. I’d guess there’s a better way to organize your data, but it’s hard to say without some more info and maybe some relevant code.
That said, you could always add 1024 to each X coord and 600 to each Y coord as you store them and then subtract the offsets back out on use…
But, again, the data storage here seems odd to me…
jgodfrey | 2020-06-24 17:08
yeah the offset thing was what I was thinking but hoping I wouldn’t have to, because changing the global origin would be less work.
As for the reason I am storing the data in a array:
I am doing a tile-like thing where each tile is a 32*32 sprite. The array stores the x y and tile value of said tile (aka array[comment1-y] = tile value). In order to set a value I divide the mouse position by 32 and round it. Which gives me the corresponding tile data in the array. This method worked fine until I expanded the world and made the top left corner not 0,0 but -1024,-600. Which apparently gave the array a stroke when it tried to compute negative numbers. Instead of godot giving a error when you try to put a negative value for a index in a array, godot just takes the highest index from the array and subtracts it by the negative value. Now this would be fine but with the way I was making my game I did not notice the bug. So I built everything in my game around this bug until recently when I found out that this was happening. Now my choices are: Reset the tile engine and start again but with the top left being 0,0, Remember to add offsets to everything that involves the array, or to change where the global origin is. The last one would be the easiest so that is why I went searching for how to do that. I probably should of said all this at the beginning but it didn’t seem to matter at first.
stevepetoskey | 2020-06-24 17:32