Archive for April, 2014

SnapCode Update April 25: Added SnapImage

April 27, 2014

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

SnapCode is available here.

JavaFX Asteroids with Greenfoot and SnapCode

April 21, 2014

This week I wrote a simple emulation library (4 classes) to run Greenfoot applications without modification in JavaFX and SnapCode. My test case is Asteroids for Greenfoot from their wonderful programming book.

The following 2 minute video shows loading the Asteroids project from a simple HTTP repository at and running Asteroids. At the end, there is even some Asteroids modding. šŸ™‚

I haven’t done any performance work yet, but the game runs fine – even when I mod the game to fill the screen with asteroids. Check out the video below.



JavaFX Asteroids with Greenfoot and SnapCode


SnapCode Update April 18: Added Hit Detection

April 19, 2014

This week added some hit detection methods to the SnapActor class:


This makes it possible to determine whether a given actor overlaps (or “hit”) another actor and will be useful for most games. Additionally, we updated the KeyDown and KeyClicked functionality to handle multiple down/clicked keys at once – because it turns out that real gameplay often involves this (head-smack).

Early next week I’ll release our test case – a JavaFX/SnapCode version of asteroids. Below is the fullĀ list of improvements made to SnapCode this week.

– SnapActor: Added getIntersectingActor/getIntersectingActors
– SnapActor: Added getActorsInRange
– SnapScene: Fixed KeyDown to be a Set of KeyCodes instead of just one
– SnapActor: Fixed to have X/Y be at center of actor
– SnapAnimator: Fixed to animate X/Y instead of LayoutX/Y
– SnapAnimator: Added moveTo()
– SnapScene: Made default scene have main() and act() methods
– SnapPartStmt: Fixed dropNode on bottom of block statement
– SnapActor: Fixed setWidth/setHeight to preserve x/y
– SnapActor: Added getDistance(actor)
– SnapScene: Added removeActor()
– SnapScene: Made playSound() check /sounds directory
– SnapScene, SnapActor: Renamed MousePressed/KeyPressed methods to be MouseDown/KeyDown.

SnapCode Update April 11: Added ShowCoords and more

April 11, 2014

This week added a nice SnapCode feature for working with the standard graphics coordinate system: a new method on the Scene class called setShowCoords(boolean) to have the scene draw the coordinate system along with the current mouse point. This makes it easier to plot coordinates in the scene.

Additionally, there are a couple new methods to customize the scene and console. The Scene class has a getColor()/setColor() method. And you can now ask the Scene for the Console, which has new methods to set the Font and FontSize.

Finally, there are a couple of new actor methods to get the angle and distance to the mouse or another actor: getAngle(“Mouse/Actor-Name”), getDistance(“Mouse/Actor-Name”). These make it easy to have an actor point or move to the mouse or another actor.

Here is an image of the scene with ShowCoords enabled.


SnapCode Update April 4: Console I/O

April 4, 2014

This week added some console I/O so that Snap studio can print messages to the scene and request input from the user.

– Added getConsole() method to Scene class for console I/O
– Added println() to scene to handle console output
– Added getInputInt(), getInputString() to ConsoleĀ to get input
– Created JavaFX TextView for snap.text (ported from Swing version)
– Added TextStyle to snap.text to manage collection of attributes for TextRun

We still need to add support so that console I/O works well with actor/scene keyboard sensing, but below is an example of an app that asks the user how much to move the actor forward or backward. ConsoleIO