Hello everyone, I'm making an Android Game
I'm still really young programmer, without big experience, so I would like to ask couple of questions (not related to making game, just some Java questions)
Game run's smooth, but I think still there are ways to improve performance (I think its always good to improve code if possible)
I decided to improve code responsible for handling events after collisions/contact between objects.
a) every game object has its ID, like for example "Wall", "Monster", "Coin" so I can know which action should be handled after contact
I have "contact listener" which is checking ID of the two object's which collided, and handling objects, more or less it looks like this (plenty of if checks)
1. So I'm comparing STRING objects, so I thought that comparing int should be faster (or I'm wrong?)
2. Second question, in android development, I'm forced to avoid creating new objects, so I should create all objects at game start up, to avoid garbage collecting which may cause slow downs, and I'm wondering if in previous code, its better to use x1.getBody().getUserData() method tree times (Which returns ID) or create temporary
String s = x1.getBody().getUserData();
and use this s object in those checks ?
3. Last question, since I will switch from using STRING to INT in game objects id, i thought that I should use switch statement, instead of multiple if's. I have been reading that it should be faster.
Thanks for answer.