• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps A couple coding and development questions

Hello all! First off let me say thank you for reading! Now, I'll get right to it. I am creating an android 2d game and am already a bit of the way through. but I find myself at an interesting turn point.

I have a character who moves across the x axis along a VERY long background with multiple backgrounds moving at different speeds. The way I've chosen to do this is to have the character stay in place with a variable "speed" stat that determines how fast all the other elements move. My question is, is this the best way to do this?

My eventual intention is to have multiple areas that you transition to without stopping the game. I have read a few development books and have learned alot. But another problem is when I test my game I get good framerates (52 - 54) but I am noticing a frame dropping every few seconds or so. I feel that this is related to my previous question.

So to conclude, any help you have in the most concise and non hardware intensive way to accomplish these features? Again, thank you in advance for reading and any answers/help you can give.
 
This is one way to do it, and depending on the details of your game, could very well be the easiest. There is no one size fits all answer to how to solve this problem; there are always trade offs when choosing a solution to a problem, and which one you choose should be entirely based on weighing those trade offs against the problem's requirememts.

Also, for the second question, are you using opengl or the android graphics api?
 
Upvote 0
thanks for the quick reply!

the questions are kind of together, I am using opengl, and I was wonder if the method I was using was causing the frame drop. also, from the books I read I think they redraw the sprite instead of using gltranslate. so I have thought that maybe that was causing the frame drop.

to give some context, the character is launched and travels along a long distance horizontally, with the backgrounds and enemies flying past him at speeds decided by his "speed" stat which changes often.
 
Upvote 0
I highly doubt that your method is causing hte frame drop. If I had to guess, it would be the OpenGL calls themselves that are causing the drop. Unfortunately, the OpenGL library is a C library, and thus must be implemented via the Java Native Interface (JNI) in order to be accessible in Java. JNI calls have a large amount of overhead and FPS drops like this are not uncommon. Because of this, many games in Andorid are implemented almost entirely in C/C++ and only tap into the Java Android SDK for certain things, such as UI elements (buttons, text boxes, etc...), sensor management, or other more device-specific functionality.
 
  • Like
Reactions: donovanvaught
Upvote 0
so basically, all the time I've spent learning java, and working on the game, and I still need to go and learn another programming language? Ugh, I was made to believe that java was all I needed to finish a game, the test game I did in the learning process further solidified that thought.

Oh well, so I ask, if I don't implement my game in c++, I will continue to get frame drops? is there no other way to fix this issue? if so, how? if not, then any info you can point me towards on how to implement my game in c++?

I'm sorry if it seems like I'm badgering you but this project means a lot to me, and this isn't the first time I've gone far and had to start all over. Thank you once again for all your help, Jon, and thank you for any further help you give. It's all much appreciated! :)
 
Upvote 0
That's not necessarily the case. Depending on the complexity of your game, you may very well be able to continue on with Java. Regardless, you should look into optimizing your code and rendering so that you receive the best frame rates possible.

It's hard to give any more information than that without knowing how your game is coded already.
 
  • Like
Reactions: donovanvaught
Upvote 0
Well, I do want a robust game, but in terms of complexity I'm not sure how complex it would be, I don't know what constitutes complex on the android platform.

Without giving too much away I can give you a rundown of all the features I'm eventually going to implement, and you can tell me what I'll need to do (stick with java or implement c++/ get a game engine).

Multiple playable characters, each with one attack/ability that recharges on hitting enemies. Multiple types of enemies, some with special things that happen on death or require certain input to kill on collision. An in game currency, and a real-money currency, for unlocking more characters. an upgrade system for the playable characters.

That's pretty much all the stuff I think would make it complex. But there is one more thing. I think I might have an idea about what was causing the frame drop. It started from the very first feature I coded in, the infinite background. I had the character stay in place. Created 2 instances of a background class with the same texture. These objects are end to end, and move past the character to simulate his movement. When the first object leaves the camera view, it's position on x is immediately changed to the other end of the second image. this was how I created an endlessly repeating background, could this be the culprit?

Well, that's enough questions for this post, so, let me know what you can tell me about the complexity of my game, and your thoughts on the above paragraph. Thank you again so much for how much help your giving me.
 
Upvote 0
Frankly, I don't see the infinite scrolling background to be a problem. All you are doing is chaning the value of the object's transform. This shouldn't make much of a difference.

With that said, when I spoke of complexity, I was more referring to how many objects are on the screen (visibly; actually being rendered) at any give time, is the game 2d, 3d, are you using VBOs, vertex arrays, shader programming, etc... more technical details than design details.
 
  • Like
Reactions: donovanvaught
Upvote 0
actually, the infinite background was the fist thing I did, and from the start it was causing frame drops. so I think that maybe I'm using the wrong method to move it. Every time the background is moved, a position.x stat is changed, then the background is re-rendered with a spritebatcher at it's new position. Everything else is drawn this way too.

The game is 2d. planning to have many enemies on screen at once (about 10-12 at a time). using vertex arrays I think. The framework is copied over from a tutorial game I made. There really isn't anything else, mechanically. I have many moving and animating sprites that I want. but only some of this is implemented because I didn't want to continue until the frame drop was fixed. not using shader programming (don't know what is, so probly not).

I think my problem is that everything is being re-rendered every frame instead of tranform. so if you can point me to how to implement this? Or if this information tells you something else...... Your an amazing sport for sticking with me, thank you again for your help!
 
Upvote 0
Okay, well changing the value of position.x is simply changing the value of a particular spot in memory. This operation takes next to nothing in terms of efficiency and in no way should cause an issue. As far as rendering goes, you would be rendering the frame regardless, and weather the enemy is at x=0 or x=800, as long as 0 > x > screenWidth, it's going to be rendered regardless.

In all honesty, I haven't worked with the OpenGL JNI bindings in the Android SDK in a LONG time, so I can't speak for how well they perform on modern devices any more than "It's going to be slower than going full C++," but If there are only going to be around 20 animated objects on the screen at any given time, I would assume that modern hardware would be able to handle it no problem. Unfortunately, without seeing your actual code, I can't really give you any hints as to where you could optimize.

With that said, you will never see the case of a 100% consistent framerate throughout the game. That's just not physically possible. You will always have dips, no matter how hard you try. The question is, are the dips so severe that it adversely affects gameplay or are the just dipping to the point where they are slightly noticeable?
 
  • Like
Reactions: donovanvaught
Upvote 0
well, I guess I'll just have to live with it, but it's not the frame rate, it's literally a dropped frame. I get a consistent 52-54 fps. But every second or so I can see a frame being skipped. I am a cinephile and a filmmaker so I'm sure my eyes are biased,probly noone else will notice, so I guess I'll just keep plugging along. Hopefully the skipping doesn't get worse, but from what you've said, it shouldn't. Thanks again for all your help!
 
Upvote 0
oh wow, so i open up eclipse to make an apk for you, then plug in my phone to load it on there too real quick, and it disconnects my external hd which causes my data to be lost. Well, while I deal with this I need to see if I can recover my lost data. I'll pm you an apk as soon as I can get one (god I hope I can) :(
 
Upvote 0
Ok, so i tested it on my device galaxy s2) and there is no slow down or frame loss what so ever. With that said, one of the baxkground layers seems to br fudged. I attached a screenshot.

This is actually a pretty fun game and i love steampunk stuff so +1 for that too. Lol lastly, it crashed when i wemt to exit.
 

Attachments

  • uploadfromtaptalk1349229939302.jpg
    uploadfromtaptalk1349229939302.jpg
    119.3 KB · Views: 72
Upvote 0
ugh, well I'm back, and I still have no Idea what to do.

I have searched and searched and still see the problem. When I show to friends and point out the problem, they see it as well. When I start to add features, the problem becomes worse.

I'm at a total loss for what to do, I have no other android devices I can test on to see if it's just my device, I really want to keep working but it's bugging me too much and I waste too much time trying to fix it. What can I do? :(
 
Upvote 0
well, I'm testing on a rooted HTC Evo 4g. I do have some more insight. The skipping is consistent, it isn't random, also, I'v noticed that only the moving objects are skipping. By that I mean that the camera follows the main character, so he only appears to move along the y axis, when the other elements skip, he doesn't, leading me to believe that it isn't a frame problem, but a movement or rendering problem.

I've really got no other option then to just shoot you a copy of my source code, so if you feel like perusing it and giving me advice I'll send it. Just pm me ur e-mail and I'll send a zip file.

Out of my friends there's only one with a smart phone but I rarely see them, so until then this is my best course of action.

I have the very sneaking suspicion that the code I'm using from the book is what's causing this. In that it wasn't designed for faster movement. well, we'll see. let me know if you wanna check it out! :) and as always, thanks for your help
 
Upvote 0
What exactly are you seeing? Everything looks very smooth on my Galaxy Nexus, although sometimes I do feel like the enemies speed up for a split second sometimes. I have zero experience with OpenGL and even less on Android but I may have some things you can try.

If you have a main loop somewhere calling draw functions or whatever(Is this handled internally? I dunno.) and you're making the thread sleep 1000/TargetFramerate milliseconds, you need to remember all that drawing takes time and you must take this into account or you can get very inconsistent frame rates.

Now, this seems a little less likely but it's possible you could be using integers for positions and/or velocities or calculations, this could cause some mind boggling results that are very hard to debug.
 
Upvote 0
to Bojan, that's exactly what I'm seeing! The enemies seem to speed up for a split second, as if the skip a small distance. as for the movement and calculations, I'm using floats, should I use something else? and as for the draw calls, I'm not making the thread sleep at all, and putting that functionality in made no changes.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones