Skip to content

The case of the invisible bullet

Well, I promised some posts on gotchas I’ve encountered when making my first game. So here’s the first post in that series.

The game I’m making is a type of side-scrolling shooter. I have the “ship” being rendered using an image file, but I felt that it would be better to just draw a small circle to represent the bullets shooting out of the ship itself. I setup all the logic and just threw out a sample bullet, which never appeared.

Now, I’d had issues previously with the ship itself, where I’d forgotten to actually add it to the world I was rendering, but that wasn’t a problem here.

I could tell because I had some debug code enabled, which drew in the collision boxes around all the entities on the screen, and I could see the box around the bullet appear on the screen, just not the bullet itself. After poking around alot, I found my problem.

You see, playn.core.Canvas.setFillColor(int color) takes an integer color value, which can be represented as a hex value. I was supplying a hex color value for RGB directly to the function, but was neglecting to include a value for the alpha channel. As such, it defaulted to 0×00, which of course is transparent! D’oh!

In my searching I also found the nice playn.core.Color.rgb(int r, int g, int b) method, which takes three integer values (0-255) for red, green, and blue, and produces an integer color value with a fully opaque alpha channel value. Yay! ;) With that, the issue of the invisible bullet was solved.

Post a Comment

Your email is never published nor shared. Required fields are marked *