Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Today I learned loops are slow
#2
Why would anyone use a loop to find a sprite on a sprite sheet? Its a direct calculation.

And what does creating a bunch of random points have to do with locating a sprite?

Direct Calculation:
let SW = sprite width, SH sprite height, SPR sprites per row, SPC sprites per column
let I be the sprite index of interest
let SX, SY be the top left pixel of Sprite I
then 
SX = (I mod SPC) * SW
SY = int(I / SPR) * SH

Simple (for someone who has done it dozens of times.) Smile
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
Today I learned loops are slow - by CMR - 11-27-2025, 05:20 AM
RE: Today I learned loops are slow - by bplus - 11-27-2025, 02:09 PM
RE: Today I learned loops are slow - by CMR - 11-27-2025, 05:20 PM
RE: Today I learned loops are slow - by bplus - 11-27-2025, 06:27 PM
RE: Today I learned loops are slow - by bplus - 11-27-2025, 07:17 PM
RE: Today I learned loops are slow - by CMR - 11-27-2025, 08:35 PM
RE: Today I learned loops are slow - by bplus - 11-27-2025, 09:17 PM
RE: Today I learned loops are slow - by Pete - 11-27-2025, 10:52 PM
RE: Today I learned loops are slow - by CMR - 11-28-2025, 01:58 AM
RE: Today I learned loops are slow - by TDarcos - 12-20-2025, 02:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have learned something new: how to get a run-time syntax error TDarcos 2 970 10-02-2024, 07:04 PM
Last Post: TDarcos
  A little bit of spark fun today TerryRitchie 2 839 05-18-2024, 12:59 AM
Last Post: bobalooie
  Loops alternate recursive ways bplus 10 2,032 02-01-2023, 02:05 PM
Last Post: Dimster

Forum Jump:


Users browsing this thread: 1 Guest(s)