- Home /
How can I move a camera on Android with a virtual button press - smoothly?
I am writing a 2D sidescrolling game for Android and coming from primarily PC development. Normally I'm used to using .translate() but that doesn't seem to move all that smoothly on my test machine - a Galaxy S3. After reading suggested tips, people seem to recommend using transform.position +=. I have two buttons set up to emulate a axis, supplying 1, -1 and 0 values for right, left and no detection.
What is the best way to ensure the camera moves smoothly on a horizontal plane, as long as these buttons are pressed?
How optimized is your game to a mobile device? A lot of draw calls, for instance might cause lag.
At the moment it uses 29, with a maximum allowed of 50. Both meshes and textures are optimized for mobile. I've got movement working semi-smooth but now running into control problems, related to the emulated axis. I'm using NGUI. Whenever I press and hold a button, it should keep moving. However.. it moves, and stops, then refuses to move until the axis buttons are pressed again:
public void axisUpdate(string dir)
{
switch(dir)
{
case "left":
horizontalControl = -1;
break;
case "right":
horizontalControl = 1;
break;
case "release":
horizontalControl = 0;
break;
}
if (horizontalControl != 0)
{
StartCoroutine("moveCamera");
}
}
IEnumerator moveCamera()
{
//moving = true;
float i = 0;
Vector3 camPosistion = transform.position;
Vector3 movePosistion = new Vector3(horizontalControl, 0, 0);
Vector3 destination = camPosistion + movePosistion;
Debug.Log(destination);
while (i < 1)
{
i += Time.deltaTime * 5;
transform.position = Vector3.Lerp(camPosistion, destination, i);
yield return 0;
}
//moving = false;
}
EDIT: 29 is highest possible currently. The normal is barely at 20.
Your answer
