Log In  

I have a routine where I'm checking a pixel color at a certain x/y to determine whether or not to place a new sprite there. If it's black, it's open; if it's white, it's unavailable. I'm doing this in the _update() loop but I'm often getting cases where it'll place a sprite twice in the same place rather than just once.

After going through my code again and again, it struck me that having the pixel check in the update() might not be the best place. Wondering if doing pixel checks in the draw() are more reliable because there's cases where update() could be slower/faster than draw()...?

I chose to do pixel checking to avoid having to loop through an array checking x/y coordinates every time but it sounds like that may be more reliable?

Any thoughts/insight is appreciated.

P#24765 2016-07-06 22:45 ( Edited 2016-07-08 01:19)

As a general practice in games, you don't touch the GPU except when you're actually drawing. You never know when a different thread or the GPU will actually be doing something asynchronously. So in general you're right.

With PICO-8, though, it's all done sequentially. You update, then your draw, repeat until infinity.

That said, it's possible to get more than one update per draw if your game is running slow. So in that case, you might be taking chances with using stale pixels.

Like, if you spawn a sprite and expect it to be drawn there before the next update, and the draw doesn't get called because you're running slowly and the PICO-8 OS prioritizes updates over drawing, it won't be there on the next update and you'll spawn it again.

P#24769 2016-07-06 23:19 ( Edited 2016-07-07 03:19)

Good info, thanks. I don't think my program was running slow to the point of dropping frames or anything...a lot of the issue probably still is my code and how it's working, but good to know to try and keep even the pget/pset in the draw() rather than outside.

It feels like such a hassle and waste to always loop over an array of objects to do checks but I guess that's always more reliable. Or maybe I'm just being really inefficient with my loops...

...or maybe I just need to stop worrying about efficiency until I actually hit a limit or something :) Curse of my day job that's hard to shake...

P#24818 2016-07-07 11:28 ( Edited 2016-07-07 15:28)

are you checking multiple times in _update then drawing afterwards in _draw ? then you should draw the sprite or pset the pixel straightaway.

P#24825 2016-07-07 12:27 ( Edited 2016-07-07 16:27)

Yeah, perf in PICO-8 is non-intuitive a lot of the time. Things are cheap that ought to be expensive. I think this de-complicates a lot of things for people, so I'm pretty cool with it, but it does screw up my instincts a lot.

Just put PRINTF(STAT(1),0,0,7) in your draw loop and don't worry until you go over a frame. Most of what we can do here just doesn't need optimizing.

P#24860 2016-07-07 21:19 ( Edited 2016-07-08 01:19)

[Please log in to post a comment]