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!

5 Likes