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

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

multitouch

Mole picked as a finalist in the GDAA Indie Game Awards 2009!14 Nov

moleHeartgdaa

Good news!

Our game: 'Mole' was picked as one of the nine finalists in this year's Game Developer's Association of Australia Indie Game Awards.

We will be showing it at the GCAP 2009 conference in Melbourne in just a few weeks.

We are pretty excited about this, however it does mean that the iPhone release probably will not be out by Xmas which was the plan had we not gotten into GCAP. We hope to get some great feedback on the game and gameplay during GCAP and be able to make the game even better, so it will be worth the wait.

If you haven't already, you can play an early version of the game online, just go to the Mole page, and hit 'play now'.

Cheers!
-Ben

multitouch

I am joining forces with Tin Man Games for Gamebook Adventures14 Nov

tinmanGA

A few weeks ago, I was approached by Tin Man Games to see if I was interested in helping them bring their GameBook Adventures to the iPhone. I am very happy to announce that earlier this week, I took over as the lead developer on the GameBook project.

The first two books are titled: "An Assassin in Orlandes" and " The Siege of the Necromancer".

gatitles

If you like adventures and you can read, then you will like these gamebooks.

As a side note: Tin Man Games is running a promo right now that if they get a few hundred new twitter followers then they will make one of their games free on the AppStore. so go and follow @tinmangames.

while you are at it, follow me too: @benbritten.

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+PGxpPjxzdHJvbmc+d29vX2FkX2JlbG93X3VybDwvc3Ryb25nPiAtIGh0dHA6Ly93d3cud29vdGhlbWVzLmNvbTwvbGk+PGxpPjxzdHJvbmc+d29vX2FsdF9zdHlsZXNoZWV0PC9zdHJvbmc+IC0gYmVuYnJpdHRlbi5jc3M8L2xpPjxsaT48c3Ryb25nPndvb19ibG9ja19pbWFnZTwvc3Ryb25nPiAtIGh0dHA6Ly9iZW5icml0dGVuLmNvbS93cC1jb250ZW50L3RoZW1lcy92aWJyYW50Y21zL2ltYWdlcy9hZDMzNi5qcGc8L2xpPjxsaT48c3Ryb25nPndvb19ibG9ja191cmw8L3N0cm9uZz4gLSBodHRwOi8vd3d3Lndvb3RoZW1lcy5jb208L2xpPjxsaT48c3Ryb25nPndvb19ib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