Get pixel of an image

Hey, I'm new to playdate and planning my first game before the device arrives. Exciting!

I'm trying to avoid using a physics engine for collisions. I'm making a car game and would like to check how many corners of the rectangular car is touching the road (or are outside the road). The car is rotated and I'm hoping to keep the terrain as arbitrary bitmaps.

Is there a way I can get information of individual pixels of an image? Something like getPixel(image, x, y)?

https://sdk.play.date/inside-playdate/#m-graphics.image.sample

I ended up adding a comment next to my use of this as I would also search for getpixel!

Even now it took me a few minutes to find it in the docs.

(You could add a wrapper function but it would some things down.)

1 Like

Amazing, thanks for the super quick response! Exactly what I was after.

Edit: Is there a similar way to get pixels when using the draw methods? After reading the docs it doesn't seem so, but thought I'd double check.

1 Like

I'm not sure exactly what you mean?

You can only get a pixel out of an image. If you draw to a large image then is that enough for you? Otherwise please explain.

I meant if one of the drawing functions is used, drawArc() for example, would it be possible to use sample() or a similar function to get the pixels drawn?

It doesn't say in the API whether something is returned from those functions, so I'm guessing not.

How would I go about drawing to an image?

Update: I think I found it here!

No, you can't get the pixels that were drawn as far as I know.

Drawing to an image there's lockFocus or pushContext

1 Like