Kabaam is available

Hi everyone,

Daniel has already teased this in the recent podcast about Sparrow ;-) but now it is official: Our fun little project Kabaam has hit the App Store today. Naturally it’s a single malt Sparrow App seasoned with just a little bit of UIKit.

Beam it to your iPhone

As if that wasn’t enough happiness for today, there is one more sparrow-related thing I’d like to share that came up during development:

How to convert SPRenderTextures to UIImages

One thing Kabaam does is overlay some text bubbles onto a photo the user shot. The photos/comics can then be exported to email and diverse social platforms. In order to accomplish that the whole display tree has to be rendered to an exportable image. Although we’d love to stay 100% pure Sparrow for most of the time ;-) it makes sense to use UIKit to help us here. That’s why I extended the SPRenderTexture to allow rendering it to an UIImage. Many of you most likely already know how to do this, but maybe this snippet still helps one or the other to get earlier results.

Here is the interface extension:

@interface SPRenderTexture (RenderToImage)
- (UIImage*)renderToImage;
@end

And here is the magical part. In short, it makes use of the bundleDrawCalls method on the SPRenderTexture to get to the current GL context. It then allocates memory for the resulting image and reads the pixels from the GL context into the allocated array. After that we can feed that array to a CGDataProvider, a CGImageRef and then to an UIImage. All that’s left to do is tidy up some memory, which is unfortuantely very C-ish in this case: We have to register a releaseRawImageDataBufferCallback with the CGDataProvider in order to release the allocated array when everything is over. Check it out:

@implementation SPRenderTexture (RenderToImage)

void releaseRawImageDataBufferCallback(void *info, const void *data, size_t size)
{
	free((void*)data);
}

- (UIImage*)renderToImage
{
	__block UIImage *image = nil;

	[self bundleDrawCalls:^() {
		float scale = [SPStage contentScaleFactor];
		int width = scale * self.width;
		int height = scale * self.height;
		int nrOfColorComponents = 4; //RGBA
		int bitsPerColorComponent = 8;
		int rawImageDataLength = width * height * nrOfColorComponents;
		GLenum pixelDataFormat = GL_RGBA;
		GLenum pixelDataType = GL_UNSIGNED_BYTE;
		BOOL interpolateAndSmoothPixels = NO;
		CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
		CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

		CGDataProviderRef dataProviderRef;
		CGColorSpaceRef colorSpaceRef;
		CGImageRef imageRef;

		@try {
			GLubyte *rawImageDataBuffer = (GLubyte *) malloc(rawImageDataLength);

			glReadPixels(0, 0, width, height, pixelDataFormat, pixelDataType, rawImageDataBuffer);

			dataProviderRef = CGDataProviderCreateWithData(NULL, rawImageDataBuffer, rawImageDataLength, releaseRawImageDataBufferCallback);
			colorSpaceRef = CGColorSpaceCreateDeviceRGB();
			imageRef = CGImageCreate(width, height, bitsPerColorComponent, bitsPerColorComponent * nrOfColorComponents, width * nrOfColorComponents, colorSpaceRef, bitmapInfo, dataProviderRef, NULL, interpolateAndSmoothPixels, renderingIntent);
			image = [UIImage imageWithCGImage:imageRef];
		}
		@finally {
			CGDataProviderRelease(dataProviderRef);
			CGColorSpaceRelease(colorSpaceRef);
			CGImageRelease(imageRef);
		}
	}];

	return image;
}

@end

As soon as we have that UIImage in our hands we can (thanks to UIKit convenience) very easily convert this into JPG or PNG format using the UIImageJPEGRepresentation and UIImagePNGRepresentation helpers.

0 Comments

Sparrow-Framework.org hacked [solved]

Hi folks,

some of you might have had an unpleasant surprise on their last visit of the Sparrow-Framework pages. They were welcomed not with a cute, innocent, little bird — but with this serious looking security guy:

The security warning some users saw around 2011-08-25

You can imagine how thrilled I was at his appearance!

Well, the fact is: he was right. Some bad, unfriendly criminal (reportedly he was unshaved and rather fat — not a pretty view!) used a vulnerability in one of our scripts to insert some bad code into our web page.

Being a very cautious person, I’m always keeping the server software up-to-date, and the bad script was already fixed a few days ago. However, it seems that I was a little too late — the intruder had already exploited the vulnerability. However, we found the change he made and removed that code. It will take a while, though, until our domain is removed from Google’s blacklist.

Now, the important part: was this dangerous for our visitors? Fear not, I haven’t heard from any actual harm being done. Most malware does not work on up-to-date browsers and operating systems anyway (and are targeting Windows, while most of you will be running OS X).

So, all I can do now is apologize for the inconveniences this might have caused. We’ll do our best to avoid attacks like that in the future — but as we just learned, there’s no guarantee for anything; not even for our small chicken. Ehm. Sparrow. ;-)

EDIT (2011-08-26): Heureka, Google removed us from the blacklist! The warning page has gone.

7 Comments

Sparrow on the Cocos2D Podcast!

Yes, you’ve read the title correctly! April 1st is long gone, so this is no joke! :-)

Cocos2D banner thankfully borrowed from cocos2d-iphone.org ;-)

(I considered adding a few pink and red hearts between the two logos — but perhaps this would have been a little too cheesy *g*.)

Mohammad Azam and Steffen Itterheim, the creators of the Cocos2D Podcast, have been kind enough to invite me into their podcast. In a session of about one hour, we talk about different things related to the Sparrow Framework — like how it came to life, what sets it apart from its competition, and about the next steps that are planned. Furthermore, I have a mysterious announcement to make (!), and I shamelessly advertise for Gamua’s next Sparrow application, Kabaam! I’d be honored if you checked it out under the following link:

Cocos2D Podcast: Daniel Sperl explains the Sparrow Framework

Thanks again, Azam and Steffen — it has been a pleasure chatting with you!

5 Comments

New tutorials: Textures, PVRTC, Auto-rotation

There are some topics that pop up regularly in the forum. Instead of answering them over and over again in the forum, I thought it would be a good idea to take the time to write extensive tutorials on those issues!

The place for those tutorials is, of course, the Sparrow Wiki! Here are the new tutorials you’ll find there:

  • Texture Formats: Best Practices — Everything you always wanted to know about textures, but were afraid to ask
  • PVR Textures — what they are, why you should use them, and of course: how to use them!
  • Auto-rotating a game — what you have to take care of when you want to rotate your game when the device orientation changes.


I hope this helps some of you in your development process! Leave a comment if you find something important is missing.

5 Comments

User’s corner: “Caribbean Treasures”

After Go Usagi!, I’m proud to present another post in the “user’s corner” series! Today, the Ukrainian developer Kostya Teterin writes about his experiences when developing the puzzle game “Caribbean Treasures” for the iPhone. Thanks for taking the time to write that article, Kostya!

Who are you?

My name is Kostya Teterin. I am founder and owner of Emotion Rays Entertainment, and a big fan of computer games. I would like to tell you the story behind “Caribbean Treasures” and Sparrow.

Caribbean Treasures

Caribbean Treasures is a puzzle game that is available on the AppStore in two versions, a complete and a lite edition (which is free but limited to 20 levels, while the complete version contains 101 levels). It is a remake of my old PC game Caribbean Treasures (available here) that was developed back in 2004 and still sells. Since I had many positive reviews about the gameplay of the original game, I decided to “copy” it on iPhone with some features that are unique to the mobile devices (like gravity and “draw on sand with your finger”).

Why sparrow?

Caribbean Treasures is my first project for the iPhone, and when I googled for a free game engine, most links were about the Cocos2D. In my opinion, however, that engine has too much features implemented which makes it too big and hard to learn. I browsed through some samples and it was obvious that it might take several days or weeks to learn that engine on the level that is required to make a game.

Then I found the Sparrow Framework.

I was immediately attracted with 3 facts: it’s completely free, it’s open source (and I can make changes to the source or browse through it to learn how it works), and it is very intuitive. It took just a few hours to make a main menu for the game, and this was my first experience with the game engine. So the choice was obvious: I could focus on game code without spending lots of time trying to figure out how to define objects, scenes, sounds and to bring that all together. In three days I had my first playable level, and that was pretty fast.

Obstacles along the way

It just has to be said: Sparrow has a much better support team than most commercial applications. Almost all problems that I had were already solved, so I just learned on the forum how to fix them. There was a problem with the “Draw on sand” feature that took me a day to solve with the help of the forum, and it turned out that it wasn’t a problem of the game engine but rather a problem of the OpenGL implementation on iDevices. It was related to the speed of rendering to textures, which is quite low.

During the work on Caribbean Treasures I also learned Objective-C, which was a new language for me. So I had lots of memory leaks in the initial builds that were fixed just before the release. But there really weren’t any big troubles making this game, and — what’s more important — there weren’t any problems with the game engine (I didn’t encounter any bugs or errors).

Conclusions

Sparrow is a basic framework. It doesn’t have any advanced features like a set of GUI classes (sliders, modal dialogs and so on) or scripting engines or tools like scene editors and so on. And that was exactly what I was looking for! Because from my experience, many additional features are making a game engine just harder to learn, adding a lot of bulk just to display a simple sprite on the screen. As a basic framework, Sparrow is just great! It’s very intuitive, easy to learn, and well organized. It has everything that one might need to develop a game. The quality support provided directly by the engine developers and users is also an important feature that should be considered by everyone who is looking for a game engine for their game. As for me, I have no doubt about the game engine that will be used in my next game. It will be the Sparrow Framework of course!

1 Comment