Game Development Community

help resolving performance issue..

by Dillon Nys · in iTorque 2D · 01/14/2012 (3:55 pm) · 2 replies

In my game, a patch of grass is generated that looks like this
oi44.tinypic.com/14cxzyc.jpg

and then, randomly, it will be added to my scene using this code

if(isObject(%grassPatch) && $loadGrassPatch)
{
	%grassPatch.addToScene(sceneWindow2D.getSceneGraph());
	%grassPatch.setLinearVelocityX($platformVel);
	for(%i = 0; %i < 22; %i += 2)
	{
		%flower = $flowersList.getObject(%i / 2);
		if(isObject(%flower))
		{
			%flower.addToScene(sceneWindow2D.getSceneGraph());
			%offsetX = getWord(%grassPatch.LinkPoints, %i);
			%offsetY = getWord(%grassPatch.LinkPoints, %i + 1);
			%flower.mount(%grassPatch, %offsetX, %offsetY, 0, false, false, false, false);
			%flower.setLinearVelocityX($platformVel);
		}
	}
	$flowersList.clear();
	$loadGrassPatch = false;
}

where the grass patch is loaded, and then one by one the flowers are mounted on.
however, this creates extreme lag when running on my ipod touch 4th gen until it has completely loaded.
any suggestions on a more efficient way to do this?

#1
01/15/2012 (1:58 am)
Unsure what would cause a constant slowdown over a time and not a one time hit only when the texture is bound / datablock loaded (see below for how to tackle that) unless its due to your list that holds the data where you might want to simply use a SimSet and throw the items and and pull out without any 'indexing and searching' cause searching for an object by index is quite costly especially as you don't need any indices or alike, you simply need the next present object in your 'pool'


Datablocks & Texture Loading halt:

Ensure that the datablock is loaded already along the level datablocks and consider using the standard (for over a decade) loading screen technics where you actually draw every image in the scene behind the loading screen. Reason to do this is that the camera has to see and render it so OpenGL uploads the texture from RAM to VRAM for binding.
#2
01/15/2012 (2:02 am)
Don't add the flowers to the scene during gameplay, add them once when the level begins and simply leave them off camera. It's quicker to move and remount them to create random variants than to reload new ones.