Full background images in Pulp with automated placement (no more manually click and placing tiles)

Hey Pulp folks! I recently had a bit of a breakthrough and I wanted to share it here in case it helps anyone. I looked around for a while for the best way to get a full-screen, seamless background image into a Pulp room, without much luck. I've got it working now, and getting images like this to render on the device with ease:

We'll start with what I was doing, and why it was so slow. Here was how I was getting full images into Pulp:

  • Start by making my image-table-8-8.png file in an image editor
  • Import the image into Pulp (this creates 375 different tiles)
  • Make a room new, place 375 tiles by hand
  • Repeat

To be honest, I got it down pretty good, and could place an entire room in a single quick sitting. But I wanted more and more rooms, so I know I needed to automate. I wrote some code that can place all the tiles for you, and here's how that process works:

  • Start with our trusty image-table-8-8.png file
  • Import it into Pulp, and take note of the tile ID for the first tile
  • Make a new room, add the following Pulpscript to the room
on enter do
	
	start = 2261 // define starting tile ID
	
	while count<375 do // number of tiles to complete a room
		
		tell xtile,ytile to
			swap start // swap the tile, starting with the tile defined above
		end
		
		xtile++ // move our X coord +1
		start++ // increment the tile ID to get the next tile
		count++ // increment count to keep track
		
		// check if count is multiple of 25 (one complete row)
		mod = count
		mod /= 25
		mod -= floor mod
		mod *= 25
		
		// if yes, let's move to the next row
		if mod==0 then
			ytile++ // move our Y coord +1
			xtile = 0 // move our X coord back the start
		else
			// look ma, no hands!
		end
		
	end
	
end

I think the code is pretty well documented above, but here's what this code does when you enter a room:

  • Tell the code what tile ID to start with
  • It loops through every tile in the room, starting at 0,0, and places your new tiles sequentially
  • You are done! No more needing to manually build out complete rooms.

I was worried about the computing power needed to dynamically draw 375 tiles in a loop, but the Playdate seems to handle it fine. I've got a game coming together with a buncha rooms made this way, and they all load.

Let me know if you have any questions, or ways I should improve this. Or if I'm an idiot and there's a better way to do this. Onward!

15 Likes

This is incredibly helpful, thank you!

The only issue I had was that, while the above code worked on the first room, it wouldn't draw the background on any other room I entered...until I realised that you need to reset count, xtile and ytile to 0 on entering each new room!

This is great! I did a TON of bespoke rooms in Initial Daydream and this would have saved years (or at least hours).
It would REALLY clutter up the world tiles pretty quickly, especially cause you can't delete duplicates lest you break the sequence. I was already pretty disorganized so I don't know if that would really have hindered me, but that would be the thing to watch out for, from my perspective.

you don't need to find the mod-25 of count: just check the xtile value