- Home /
Loop code for block stack slows to 3fps on android...why?
Hello everyone:
I am making a game featuring blocks that drop and stack similar to Tetris. The game runs perfectly on PC at 60fps. However, on Android the game slows to 3fps halfway through the screen using the Samsung GALAXY S VIBRANT.
I used three methods to address this concern: 1) Physics; 2)Raycasting; and 3) Code below (loop). So far, only Raycasting preserves the 60fps.
I would greatly appreciate any suggestions concerning the script below. I am happy to lend my expertise as well.
Thank you in advance.
A.G.B.
// Block Drop Script
var top : int = spawner.transform.position.y + 1;
//move down
transform.Translate(Vector3(0, -1 * amtToMove,0));
if(transform.position.y <= posY)
{
transform.position.y = Mathf.Round(transform.position.y);
}
//eval at every whole number
for(var i = top; i >= posY; i--)
{
if(Mathf.Round(transform.position.y) == i)
{
//gameObject.GetComponent.<blockEval>().Start();
// if theres a block below, stop
for(var child : Transform in spawner.transform)
{
if(Mathf.Round(transform.position.y) == Mathf.Round(child.transform.position.y + 1) &&
transform.position.x == child.transform.position.x)
{
//transform.position.y = Mathf.Lerp(transform.position.y + 0.15, Mathf.Round(transform.position.y),1); // stoft drop
transform.position.y = Mathf.RoundToInt(transform.position.y); // hard drop
stop = true;
}
}
// if you reach Ypos, stop
if(i <= posY)
{
stop = true;
transform.position.y = Mathf.Round(transform.position.y);
//transform.gameObject.GetComponent(blockDrop).enabled = false;
}
if(transform.position.y == -0.05200243)
{
stop = true;
Destroy(gameObject);
}
// else keep moving.
else
{
stop = false;
}
}
}
Comment
Your answer
