1

I am trying to make a grid of slots for an inventory sort of thing , I have it looking how I want it, but I was wondering if there was anyway to simplify or shorten my math. Every square on the grid is 30 X 30.

for (i = 1; i <= Math.floor((QuartzBackground.width - 10) / 30) * 3; i++)
{
  // X Position
  trace(((QuartzBackground.x + ((i - 1) * 32.5)) - (Math.ceil(i / 9 - 1) * (QuartzBackground.width - 10))) - ((Math.ceil(i / 9) - 1) * 2.5)); 
  // Y Position
  trace(QuartzBackground.y + 57.5 + (Math.ceil(i / 9) * 32.5)); 
}
Jeroen Heier
  • 3,520
  • 15
  • 31
  • 32
TSSans
  • 23
  • 7

1 Answers1

2

You have a couple of things repeated at least twice there. It's not much but still.

var QB:DisplayObject = QuartzBackground;
var QBwm10:Number = QB.width - 10;

for (i = 1; i <= Math.floor(QBwm10 / 30) * 3; i++)
{
    var Mcid9:Number = Math.ceil(i / 9);

    trace(QB.x + (i - 1) * 32.5 - (Mcid9 - 1) * (QBwm10 - 2.5)); // X Position
    trace(QB.y + 57.5 + (Mcid9 * 32.5)); // Y Position
}
Organis
  • 7,243
  • 2
  • 12
  • 14