I am working with Lua on Windows. I am working creating a border that isn't square. I have all the pixel coordinates saved in a table:
local borderCoords = {
{x = 100, y = 200},
{x = 101, y = 201}
-- plus a lot more coordinates
}
This table has almost 300 coordinates in it. I am then looping through each item in the table and reading the x and y coords in order to create a collider at that point:
for i=1,#borderCoords do
Boundry(borderCoords[i].x, borderCoords[i].y, 1, 1):add()
end
This is working on PC, but it does take a second to load. When I try it on my device the frame rate is EXTREMELY slow. Is there a more efficient way to do this? I haven't worked with Lua a whole lot so I know I'm missing something, just wanted to give it a try the only way I knew how.
Boundry is class I created just to put a pixel-sized sprite with a pixel sized collider rect.
Edit: I managed to increase the frame rate a bit by removing coordinates from the table after they have been used, but the frame rate is still to slow to even be playable.
I poked around in the profiler a little but I dont really know how to narrow that down. But with troubleshooting and adding/removing things, the slowness is gone once this line is removed:
I thought about using lines, but I'm almost positive that is not going to be a solution in the long run since Im going to need to layout more collisions for other objects that aren't square, or square collisions just aren't going to cut it.
I also tried an xcoord array and a ycoord array and looped through both. This showed no visual improvement. And what would be a good alternative to a sprite with a collisionRect?
Okay I decided to go with drawing lines and have lines drawn to the screen but now I think I remembered why I went the direct I did. Im not sure how the collision detection works with drawn objects. I only thought collisions were for sprites?
I had done it top down originally, but prefer the look, I didn't even think about changing the perspective. But Ill have to do some digging on that. Now that I have lines drawn Ill try to make my checks that way and then try this if that fails:
Then when you do your proper/final draw step, do it with a simple perspective transformation.
Wow thanks! Lots to unpack there! I’ll give that a shot asap! Thanks for all the help! And I love hockey games too! First thing I wanted to make when I got the console!
So I tried a lot of different things and I found that simplifying the boundaries and check lines if they are being crossed and then adjusting the velocity of the player/puck accordingly. Thanks so much, I'm learning so much about this SDK in the short months I've played around with it. (and it works great on the device!)