Jump to content
  • entries
    298
  • comments
    862
  • views
    243,464

Mucking around with iOS SpriteKit

EricBall

478 views

I have this idea for a game, which I'm trying to program for iOS (using Swift). As this is a considerable step beyond my typical C & ASM skill set, it's been slow going. Swift itself is a post C object oriented / procedural language so isn't that difficult to understand, and I can certainly appreciate _not_ having to learn Objective C.

No, the problem is the frameworks. Swift on it's own can do very little. It needs libraries like UIKit and SpriteKit. So unlike C where you can do a lot with just a small portion of the standard library functions, here I need to learn how work within these complex frameworks (which seem to assume implicit knowledge) to accomplish anything.

But on the plus side - the frameworks have a lot of features built in. SpriteKit has a whole 2D physics engine baked in - so I don't need to worry about collision detection or bouncing. It will even automatically generate the collision models based on the alpha channel in an image.

I recently learned SpriteKit also has dynamic lighting - including "normal maps". My 2D sprites are actually 3D objects, so I'm hoping the normal maps will make them look more 3D. So I whipped up some C programs to generate the normal map texture and the alpha channel for the collision models. Dropped them all into a test app and started to play around.

The physics portion worked great, but the dynamic lighting was strange as only part of the textures were responding to the dynamic lighting. In the middle of the night I realized the problem - the dynamic lighting was picking up the alpha channel part of the image which I'd used for the collision model. I'd used 255 for solid parts and 0 for empty parts. So the empty parts weren't being lit. (The alpha channel on the light color works in the same way as a general dimming factor.) In theory this could be used to bake shadows into the normal map, but for me it wasn't what I wanted. The solution is to redo the alpha channel to use 255 & 253 and use 254 as the decision point.




* I have no illusions about making millions from this game. In fact, my plan is to make the game free (gratis) to download & play. No in-app purchases, no advertising, no information gathering. Just my gift to the world.

** For iOS development you just need a Mac running the current version of MacOS. The rest of the development tools can be downloaded from Apple for free. There's even a simulator if you don't have an iOS device to test with. To actually publish an app you'll need to sign up for Apple as a developer (<$100) and you need a domain name & website (beware of teaser offers).



0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...