math.round implementation

Hi folks and folkettes,

I’ve caught my eye on math.round which i suspect is exactly what i need.

But i’m unsure how to implement it.

Camera Control

if (RobotPlayer.x \> 240 and RobotPlayer.x \< 1680) then  
 game.x = -RobotPlayer.x + \_W/2  
end  
if (RobotPlayer.y \> 160 and RobotPlayer.y \< 480) then  
 game.y = -RobotPlayer.y + \_H/2 --   
end  

game.x and game.y control the ‘camera’ and keep it focused on the character. I have the correct values there, but i don’t know how’d i’d stick math.round in.

Any ideas?

I want game.x and game.y to be rounded to the nearest integer.

Thanks.
Matt.

[import]uid: 91798 topic_id: 20269 reply_id: 320269[/import]

game.x = math.round(-RobotPlayer.x + _W/2)

Though you don’t need to do this. .x and .y can be fractional. I’d guess that under the hood, Corona SDK is already rounding them off when it come time to draw the object, so you’re just inserting more CPU instructions that won’t buy you anything.

[import]uid: 19626 topic_id: 20269 reply_id: 79218[/import]

Well the reason for this is to test whether it fixes a problem I’ve got. 

When my character moves the screen moves with him, some images become blurry. Game.x is something like 10.93662729 or something. 
When I move the game back to 0 they become sharper images again. 
I suspect it’s because of the gracing we part. 

This is in the simulator and might not be on device. I’m checking later. 

Thanks for the reply and your thoughts. 
:slight_smile:

[import]uid: 91798 topic_id: 20269 reply_id: 79221[/import]