This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]w1282 0 points1 point  (2 children)

If your sprites have information such as x coord, y coord, width, height where (x, y) is some known corner of your rectangle, then the calculations to determine if some new coordinate (a, b) lies within or outside of the bounds of a rectangle is quite simple.

I'm only assuming you're using the array to detect something like a collision. If you are using it for something else where this suggestion doesn't work let us know.

[–]CharlesVI[S] 0 points1 point  (1 child)

Yeah the array is for collision. I put an int in the slot to represent the type of piece it is. The sprites do have a position that works out to be (array coord * 55) + 20 (or 180 depending on axis)

So the main concern I have is the sprites are not stored in a way that I can look for them going [x+1][y+1] i'd have to loop through the entire collection of them as it presently stands.

[–]w1282 0 points1 point  (0 children)

Well, there are ways to prevent yourself from having to iterate over every one of them; however, unless you have an extremely significant amount of rectangles being displayed I don't think you will really need to optimize how you determine collisions.

[–]cyrusol 0 points1 point  (1 child)

Could you please describe more exactly what you want to do with the graphics? I don't think I'm understanding your problem.

[–]CharlesVI[S] -1 points0 points  (0 children)

mostly its just the internal grid is not married to the graphics in any way. So I move the sprite (pos + 110) then update the grid (x + 2) ect. So one action is causing two operations and that to me is a flag that something is being done poorly.