setDrawOffset and Sprite:draw

I'm pretty sure I should be using .setDrawOffset as a way to pan the camera around a world. (If there's another way, let me know.)

The problem I have is with sprites that have a custom Sprite:draw method. The draw offset affects them in their local coordinates too. I thought I could counteract that with pushContext and setting the offset back to 0, 0 there, but that didn't work. If I set an image for the sprite it's fine though.

Am I missing something? Is there a way to counteract the offset locally in sprites?

Do I even care? I'm assuming for simple sprites (say, just a filled rect) its faster to just draw directly, instead of drawing into an image first. Maybe that's wrong.

In this image you can seem some squares that are clipped and not aligned with their collision rects after setting an offset:

Take a look at the pullouts at


My problem turned out to be that I was using the x and y params passed to mySprite.draw (the dirty rect) wrong. I was using that point as the origin of the whole sprite drawing instead of the start of the dirty region. So, what I drew was shifted over if the dirty rect didn't start at 0,0. Oops--my fault.

I'm still not completely sure why setDrawOffset offsets the dirty rect in that way, but that's an optimization I don't need now anyway, so can ignore.

1 Like