multitouch

Simulator Rendering bug in Particles Code01 Jan

Some of you may have found your way here from my chapter on particle systems in Advanced iPhone Projects. If you have tried out that code in the simulator, and you are running in Snow Leopard, you may have noticed that the buttons have groovy patterns on them for some inexplicable reason.

This is because I made a minor error in the code, one of the most common ones that should never happen, but tend to happen in cases like these where I am writing code for a book and so it doesnt get tested nearly as well as it should. (which is my fault :-) No, it is not the dreaded one-off error, but the rookie mistake of not initializing my buffers before using them. To try and justify: when working with images, it is not generally necessary to initiaize the buffers to anything and it usually is just a wast of cycles since you often just write over the whole thing anyway (so why do it twice?). That and I borrowed heavily from Apple's sample code, and now I have learned my lesson (again :-)

In this case, because of the way I am drawing into the resulting CGContext, the old stuff not getting properly overwritten. (so it looks a bit like a multi texture, or an overlay)

The Badness can be seen here:

Screen shot 2010-01-01 at 11.21.18 AM

The buttons on the right are not supposed to have snowflakes in them.

Luckily, this render bug doesn't really effect the actual functioning of the code, just the look of it, and just in the simulator. However, the fix is good to have in there even on your device, so.. here it is:

 
		memset(spriteData, 0, (width * height * 4));
 

It needs to go in the BBMaterialController.m file, in the loadTextureImage: materialKey: method, right after we malloc the buffer for the sprite image.

 
-(CGSize)loadTextureImage:(NSString*)imageName materialKey:(NSString*)materialKey
{
	.
	.
	.
 
	// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2.
 
	if(spriteImage) {
		// Allocated memory needed for the bitmap context
		spriteData = (GLubyte *) malloc(width * height * 4);
 
		// clear the memory
		memset(spriteData, 0, (width * height * 4)); // <----------- ADD THIS!
 
		// Uses the bitmatp creation function provided by the Core Graphics framework.
		spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
		// After you create the context, you can draw the sprite image to the context.
	.
	.
	.
}
 

Anyhow, there you go. Always initialize your variables :-) Once you have made this fix, you will be rewarded with a slightly less interesting, but correctly rendering app:

The Goodness:

Screen shot 2010-01-01 at 11.20.22 AM

This will also make the numbers on the bottom of the screen render properly as well, they were similarly being corrupted with bad starting data, so they were sometimes hard to read.

Cheers!
-B

BBTouch, Blog, Unity, code, multitouch

it’s a uniTUIO Xmas25 Dec

It is xmas morning here in oz, so for those of you who celebrate that sort of thing, I hope you are having a fun one! For everyone else, I hope that the wintery holiday season is similarly lovely for you as well.

In any case, I managed to stay up very very late a few nights ago and went through the Molecules codebase and extracted the essence into what we are calling the uniTUIO community edition.

If you have not heard of this before, the basic idea behind uniTUIO is to have a nice set of scripts to allow you to easily implement TUIO based multi touch input into any Unity3d application.

If you dont have Unity3d or dont know what it is, then you really should go to www.unity3d.com and get a copy. It is crossplatform and the basic version is free (and it really isn't very basic, I built a couple complete games using that version (back when it was called the indie version)).

Anyhow, the home of uniTUIO is at the xTUIO.com website. Ultimately I will be publishing posts like this one up there, but for now, since it is still early days and not that many people know about xTUIO.com I will post this here and have sandor crosspost it there.

Currently the uniTUIO CE is comprised of a unity project which has a couple basic scenes and a couple dozen scripts. Also, I made a couple videos showing how to use the various scenes.

There are two basic methods to get at the TUIO event information.

The first one, which is used by the BBCrosshairController and BB3dCrosshairController scripts, is a simple polling method. These scripts have access to all of the touch information for the entire surface and can act accordingly.

These scripts call up to a singleton script: BBTouchEventManager. It is the touch event manager that actually takes the TUIO information and converts it into a BBEvent object, which basically means that it converts the information from TUIO form into a Unity friendly format.

If you are building a 'traditional' sort of unity game where you have a central character that you are controlling, then using this polling method makes sense. This is basically the same thing as using the Input class in unity or the iPhoneInput class in Unity iPhone.

One example of this is the particles scene which uses a script called the BB3dCrosshairController which polls for all available events and spawns a particle system under any touch events. using this method you can replicate all the fun 'fire from the fingertips' sort of MT demos in about 3 minutes. (or longer if you are like me and love to just tweak the particle systems for ever and ever to get them 'just right'. Note: the particle system that I did for the examples is not 'just right', i just threw some values at it so that you would have an idea of how to do it yourself)

Picture 4

However, in many multi-touch applications you tend to have dozens and dozens of objects in the scene that all need to be aware of any touch events that are interacting with them. In this case it does not make good design sense to have each and every object grab a copy of all the events and try to figure out if any of them apply to that specific object. Instead we have a central distribution point that checks the incoming events against the scene full of objects and sends out event messages as appropriate.

This is where the BBTouchable scripts come in. The BBTouchEventManager takes the raw TUIO events and raycasts through the scene looking for any objects that are both in a special 'touchableObjects' layer and have a BBTouchable script attached to them.

The BBTouchable script provides some overrideable abstract touch input handling methods. For the most part, when doing MT apps that deal with lots and lots of different objects that need touch inputs, you will be subclassing BBTouchable to get your custom functionality.

In the uniTUIO scripts I have made a few example subclasses of BBTouchable. one is called BBBasicTouchManipulation, and it provides any object with the basic single touch to drag/double touch to scale and rotate gestures that are very common in MT apps.
Picture 2

The second one, BBTouchableButton shows how you can make a button that lives in 3d space and reacts to touch events.
Picture 3

You should have everything you need to get started with Unity and TUIO now. If you have questions, dont hesitate to comment here or on the xtuio site, or email me directly, or pm me at the unity forums, or whatever.

Cheers!
-b

Blog, iPhone

GameBook Teaser trailer!23 Dec

Tin Man and I just finished making the teaser trailer for the upcoming Gamebook Adventure release: An Assassin in Orlandes. It is pretty cool, check it out:

Assassin in Orlandes is nearly finished, we are planning for an early January submission to the App Store, so look for it in mid to late January!

Cheers!
-B

Blog, Unity, iPhone

Mole at GCAP: Very well received!09 Dec

(Note: this is cross posted from Escape Factory)

Chris and I just got back from the Global Connect Asia Pacific game dev conference here in Melbourne. We entered Mole into the GDAA Independent Games Awards 2009 and got selected as one of the finalists.

As a GDAA finalist we were invited to put up a table and show off our game at the conference. Chris whipped up a few posters and I grabbed a couple of the stray laptops that I have laying around and we hit the expo.

Mole_Icon_125x125

GCAP is not a gamer expo, it is a game developer expo, so all the people there are somehow involved in the creation of games. Over the two day expo, we spoke to a zillion talented and creative people and they all played Mole, and let us know what they think.

The response was overwhelmingly positive. We had people coming back two and three times to just sit and play Mole during the downtimes. We had people who just sat down to have a quick look end up staying for 30 minutes trying to dig deeper and deeper.

Best of all however was the ability to watch people play the game. We spent a huge amount of time before the conference making sure that the core game play was solid and that the game was fun, and we were richly rewarded for that effort. However, watching people play the game highlighted the areas of the user interface that were lacking. It made apparent the places where we need to change the words on the menus or add new buttons. For instance, when you go to the upgrade shop from the end-of-dig scorecard, it is not at all obvious how to get back. Similarly, when people play it for the very first time, they run out of air and get back to the surface and don't realize that they need to hit the 'finish digging' button to end the dig so they can start a new one. We even found a few gameplay bugs that we will iron out.

We are currently going through and tweaking all these little bits and pieces to try to hone the user experience before we release it to the app store. But we want people to play the game so I have put up the GCAP version online so that anyone can play it for free.

If you are into it: head over to the Mole page and hit the 'play now' link. You will need the Unity3d player, and you can get it from the game page.

Mole_Icon_512x512

We are planning on keeping the online version free to use, and we will be updating it alongside the iPhone version, so if you come back and notice some new tweaks here and there, that is why.

We love to hear what you have to say about the game, so send me an email, or leave a comment here!

multitouch

high Praise for my chapter on particles05 Dec

I just had a nice email back and forth with a guy named Scott. He was asking me about automatic atlas generation.

In my chapter for Advanced iPhone Projects, I include a small atlas of particles that I built using my atlas building tool. Along with the atlas image I also included a small .plist file that was autogenerated by my tool.

I didnt really have the time or page space to discuss the atlas builder in any detail and it was not really relevant to the discussion about particles, which is why there was no real mention of it in the chapter. However, Scott is the most recent in a long line of people who have asked me about my texture atlases and how to make them quickly and easily, so I will try and get my act together and clean up the atlas tool code and do a post about it before the end of the year.

Mostly I just wanted to say thanks to Scott for giving my chapter such high praise on his blog.

Cheers!
-Ben

About

meMy full name is Ben Britten Smith.

I go by Ben Britten because Ben Smith is a bit too common and using my full name is a mouthful.

I live in Melbourne, Australia and service clients all over the globe.

Contact

Have some questions?

Feel free to contact me directly at support@benbritten.com with any questions you might have about any of the applications I support.

Thanks!

PHVsPjxsaT48c3Ryb25nPndvb19hYm91dDwvc3Ryb25nPiAtIGFib3V0LXdpZGdldDwvbGk+PGxpPjxzdHJvbmc+d29vX2FkX2JlbG93X2ltYWdlPC9zdHJvbmc+IC0gaHR0cDovL2JlbmJyaXR0ZW4uY29tL3dwLWNvbnRlbnQvdGhlbWVzL3ZpYnJhbnRjbXMvaW1hZ2VzL2FkNDY4LmpwZzwvbGk+PGxpPjxzd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