int x; // pixel position int xscaled = 0; // pixel position scaled by 1000 ... int movement=BULLETSPEED*deltaT; /// v*t = d // don't divide by 1000 here
xscaled += movement; // calculate movement more accurately x = xscaled / 1000; // scale down only when you want to plot draw(x); If you scale by 1024, you can also write x = xscaled >> 10; // divide by 1024. Could be faster than integer division. Peli www.openintents.org On Oct 15, 11:55 am, TjerkW <[EMAIL PROTECTED]> wrote: > On 15 okt, 00:48, hackbod <[EMAIL PROTECTED]> wrote: > > > The emulator in no way tries to emulate the performance > > characteristics of real hardware. > > > For this and many other reasons, every developer should run their > > application on real hardware before considering it to be ready for for > > release to the public. > > I do not have to money to buy a android phone. > I thought the emulator emulates a real phone, too bad. > > > Re: > > > > I thought about decoupling the movement from the framerate (speed = > > > pixels/second), but this > > > requires the use for floats, which make the calculation rather slow. > > > In a game you should never tie the speed of movement to the frame > > rate, because that will of course vary across different hardware. > > Even if we were doing a "google phone" and completely controlling the > > hardware, we'd want to release new hardware in the future that goes > > faster, and your game then wouldn't work well with it. > > I understand that. > > > Also there should be no reason to need floats to deal with this, you > > can use fixed point integers. > > How should i do it. > > Supposei have the following: > int BULLET_SPEED=30; // 30 pixels/second > > // then on a frameDraw > long deltaT=thread.getFrameTime(); // the time it took to move to a > new frame, in millis > int movement=(BULLETSPEED*deltaT)/1000; /// v*t = d > > The problem here is that movement is always zero because the devision > is done with 1000 (1 second). > So either i use this: > > int movement=(int)((BULLETSPEED*deltaT)/(float)1000); > > Which required FLOATING POINT calculation. > > Or i make the bullet speed a float. But this also requires floating > point calculation. > > So how is it done, without the need of floating points? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---