Set up a breakpoint where you declare the rectangle and I'm sure you'll find that the x position is off. You'll have to adjust your equation based on what you get when you set up the breakpoint.