Space Force Devlog

spaceforce1

Developer Log - Day 2(ish)

“Space Force”, a remake of missile command

I was super excited to get the SDK. (It took 10 days for my device to actually arrive on this Monday) Even before I had access to the SDK, based on a comment in the Twitch stream introducing the developer tools, I got started with Love2d and brushing up on coding in general. If you are new to Lua in general and game development specifically, I highly recommend the CS50 series from Colton Ogden. Very good material and he presents it well.

I have game ideas coming out of my ears right now, so picking what to start with was tough. I went with this idea because it doesn’t require a ton of design assets and it was simple enough conceptually but complex enough to explore the SDK and learn the ins and outs of how to make things work on this little platform.

I like the Class system and the lightweight OO available out of the box in the Playdate SDK, it’s jiving really well with me. I’ve run into a few quirks working with the sprite lib and it was very frustrating at the start to determine why my game objects were not drawing. One, it appears that when calling playdate.graphics.sprite.update() to update all of your sprites, it messes with other screen drawing - even just calling the drawFPS function wasn’t working once I added sprite.update() to my game loop. Two, when sprite updates are called indirectly from the sprite.update() function, the sprite doesn’t draw primitives such as things drawn from drawLine.

All of my current game objects still inherit from graphics.sprite, but when I switched to calling the update function directly from my gameloop everything started drawing. I know your first thought is “You need to call addSprite()”, but I was doing that. I was also calling setZIndex(). I could see the execution entering my update function on my sprite but nothing went to the screen. I need to root around a little more and figure out what’s going on, but at this point I was just trying to get game objects on the screen. I’ll try to put together a project to reproduce it.

I wanted an event engine so I could post events and have listeners in the classic OS pub/sub model. I had one that I wrote in Javascript 20 years ago. I was able to re-write it into Lua over the course of one evening. For me, having that ability just makes it easier to manage communication between objects, even if it can make debugging harder later. That was a blast to get working. I can share it out if anyone is interested.

The basic game mechanics are working in that you can shoot down one or more invaders. I found the game, at least the way I have implemented it, is easier to control on the device than in the simulator. I can see the value of using the device to provide input controls to something running in the simulator. I’m much better at shooting the bad guys on the device.

The other issue, which you can see in the video, is that there are some drawing artifacts left on the screen. This is happening even though I’m doing a full screen draw rect with a white background at the start of the game loop. I need to figure out what is going on with that. Once a “bullet” reaches its target, the entire object is removed from the game, so the lines should go away when the object is deferenced. I’ll probably have the opportunity to explore the memory poking tools, so it’ll be a learning experience.

I do want to add, I’m using the end to end Panic toolchain, doing development in Nova. I’ve run into a few quirks that I need to document. The biggest being that when I have the simulator menu open and I try to run a game from Nova, it hangs and I have to force quit the simulator. I’ve been super focused on just getting something running up until now.

So far, I’ve been having a great deal of fun working with the Playdate.

1 Like

This catches me out every single new prototype. I need to create better boilerplate code to reuse.

1 Like

What was your solution or workaround to the above problem?

1 Like

Yes, I have also suffered with this problem for a long time. It’s solved very simply: use the clear() and update() only one time and only in the main script.
Like this:
function playdate.update()
playdate.graphics.clear()
playdate.graphics.sprite.update()
end

1 Like

What we are seeing is the following

function playdate.update()
    playdate.graphics.clear()
    first:draw(0,0) -- this image does not appear!
    playdate.graphics.sprite.update()
    second:draw(0,0) -- this image appears
end

OK, I found the solution

Drawing images alongside sprites

playdate.graphics.sprite.setBackgroundDrawingCallback(drawCallback)

You need to register a callback function, inside of which you draw your background first:draw(0,0) and everything is good!

1 Like

try this:
function playdate.update()
playdate.graphics.clear()
playdate.graphics.sprite.update()
first:draw(0,0)
second:draw(0,0)
end

that works, but that way everything is drawn over/above sprites.

my goal is to draw under sprites.

zIndex doesn’t help?

sadly not.

anything drawn before sprite update is trashed unless you use the callback above.