This week I added a class to SnapCode to facilitate “sprite” programming with SnapActor. The class is called SnapImage and it has methods to load an image from a file name, and methods to do all kinds of drawing and basic image manipulation: flipImage, rotateImage, sizeImage, setColor (for a pixel), etc.
SnapActor now has a primary attribute that is a SnapImage, so you can easily create actors with custom drawing and you can easily change the look of an actor on the fly by resetting or manipulating the SnapActor.Image.
Additionally, I added a new SnapActor subclass to make it possible to have compound or nested actors. This class is called SnapParent, and it basically has a list attribute called Actors that lets you add/remove child actors, and it has methods to do hit detection on those child actors and/or retrieve subsets of the actors by class. Since this essentially what SnapScene does, I made SnapScene a SnapParent subclass to get more consistency and code re-use.
Here is a full list of the week’s changes:
– SnapImage: Added class to add rendering and drawing functionality to Actors
– SnapImage: Added flipImageX/flipImageY/rotateImage() to get current image in new orientation
– SnapImage: Added getColor(int,int) and setColor(int,int,color)
– SnapImage: Added Opacity attribute
– SnapImage: Added fillRoundRect, strokeLine, strokeRect, strokeRoundRect
– SnapImage: Added drawImage(image, x,y)
– SnapScene: Added start/stop methods
– SnapParent: Created Actor subclass that can have child actors
– SnapScene: Made this a subclass of SnapParent so it gets same Actor/Image management