kelthar

Better performance with XNATouch

Posted in iPhone Development by kelthar on January 12, 2011

Well, as most ppl know, there are some performance issues with XNATouch right now. These can be circumvented somewhat.

SpriteFonts

SpriteFonts load very slow, this is due to the format the Texture2D is in when it’s loaded. You can circumvent this with this post.

Merge textures

Since the SpriteBatch has been rewritten, it’s much faster. To improve loading speeds, you should merge you textures (.png/.jpg/etc) together in bigger files. Up to 1024*1024 pixels. This will also improve drawing speed since the object/vertex-buffer will be drawn whenever the framework wants to use a new texture.
So … If your Draw() looks like something like this

public pseudo Draw()
{
spriteBatch.Draw(alot of background sprites);
spriteBatch.Draw(alot of different platforms);
spriteBatch.Draw(alot of enemies);
spriteBatch.Draw(player sprites);
spriteBatch.Draw(more foreground sprites);
}

Then you should merge the textures in that order. First all background, if there’s more space in it, merge in the platforms and so on. You shouldn’t split a set (like all platforms OR all enemies) into separate textures since the SpriteBatch will have to load Texture1 when it needs to draw the platform of type A and B, and then jump to Texture2 for type C and D, and then jump back to draw one of type A again. Yeah, you get my drift.

Save resources, avoid garbage collection

Instead of storing all data and game logic inside objects which you create and throw away after they have been used you can create fixed size arrays which holds data for your elements/sprites/game objects.

I used to new Platform() every time I put out a new platform on screen. Now I have a dictionary of the different types of Platforms and it only contains the code needed to Update and Draw the platforms. All the data have been moved out to an array. Look at this pseudo-example:

object PlatformData
{
	bool Active;
	Vector2 Position;
	Type PlatformType;
	bool HasBeenHit;
	bool DeadlyToHit;
	int LowerPlayerHealthBy;
	Color DrawColor;
}

class SomePlatform : Platform
{
	override void Update(GameTime gameTime, PlatformData data)
	{
		// update data, calculate new position, etc
	}

	override void Draw(SpriteBatch spritebatch, PlatformData data)
	{
		// draw the sexy platform
	}
}

class SomeGame : Game
{
	Dictionary PlatformLogic = new Dictionary();
	PlatformData[] PlatformData = new PlatformData[40];

	override Update(GameTime gameTime)
	{
		for (int i=0;i<PlatformData.Length;i++)
		{
			var data = PlatformData[i];
			if (data.Active)
			{
				var logic = Platform[data.PlatformType];
				logic.Update(gameTime, data);
			}
		}
	}
}

PlatformData hold all information about the element. Platform holds all the logic about Update and Draw. And the SomeGame contains references to both.

Tagged with: , , , , ,

Convert Visual Studio XNA solution to MonoDevelop

Posted in iPhone Development by kelthar on August 20, 2010

Moved to: http://games.fourtwo.se/posts/convert-visual-studio-xna-solution-to-monodevelop

I’ve slapped to a program for windows that let’s you convert your XNA Visual Studio solution and projects to MonoDevelop. It fins all Xna content-projects and include the files from them aswell. It can “replace” the using-statements in your .cs-files aswell.

What I mean with replace is that it puts all of the Microsoft.Xna.Framework* namespaces and puts them within a #if-#endif statement. So when you are using the .cs in Visual Studio, the Microsoft.Xna using statements are used and when you load the converted projects in MonoDevelop, the XnaTouch using statements are used.

This makes the solution/project-conversion totally automatic (excepts for SpriteFonts, etc. Will add that feature later).

XNA Solution convertor

It’s still in beta, but soon I’ll post a link to it. (Yeah, I know the title says XNATouch project converter instead of XNATouch solution converter :))

And if you want to convert MonoTouch projects to Visual Studio, check this out:
MonoTouch in Visual Studio

Unsigned iPhone app with MonoTouch

Posted in iPhone Development by kelthar on August 17, 2010

Moved to http://games.fourtwo.se/posts/unsigned-iphone-app-with-monotouch

I recently bought a license for MonoTouch professional to develop a game in Xna for iPhone. I have enrolled in the apple development program and it have taken ages. I have faxed my information twice and they still ask me to send in the papers. Hence, I havn’t got my certificate to sign my code with.

So I sought some answers on how to betatest my application without getting the certificate from Apple. The thing is, that when I try to compile something in Monodevelop with MonoTouch it tells me that it can’t find my provisioning profile. That isn’t very strange, since I havn’t obtained one. Unfortunatly the signing process can’t be turned off.

To make this work, you need a license of MonoTouch and you also need to have a Jailbroken iPhone.

Follow these steps:
1. Make sure the build output is visible (this can be activated/shown from the menu in MonoDevelop)
2. Set the mode in MonoTouch to Release|iPhoneSimulator and try to compile it.
3. Compile it.
4. Copy the complete command that has been run to compile the solution (will start with the executeable “mtouch” and alot of parameters).
5. Paste this into a script file and change the parameter “-sim” in the command lind to “-dev”. The commandline should also contain the parameter “-nosign”. I place the script in the same directory as the MyProject.sln.
6. Run the script that you just created and voila! You got yourself a build for your iPhone.
7. Transfer the MyProject.app to the Applications-folder in the root of your iPhone. I use WinSCP to tranfer the files, remeber to enable ssh on your phone.
8. Install the application ldid from cydia.
9. Connect to the iPhone via ssh (Windows: Putty)
10. Change the directory to where the app is located (i.e cd /Applications/MyProject.app).
11. Use “chmod 755” on the executable (i.e “chmod 755 MyProject”)
12. Run ldid -S on the executeable (i.e “ldid -S MyProject”)

And now just click the Icon of your app!

Sometimes the app doesn’t appear right away. If it’s the first time you transfer an app to your device, you might need to reboot it before seeing it.

 

There are other ways aswell, I just find this way the easiest since the other way forces you to recompile MonoTouch. Since you put it on a jailbroken device, you can also sign with a certificate you have created by yourself, I just don’t know how to set up a provisioning profile which does that :).

Tagged with: , , ,