Timers in MIDP 2.0 question

elo! i have a question regarding using timers in midp 2.0.. i have a series of frames for my player in order to show its "walking effect" on the screen. i used timer.shedule(TimerTask, long, long) and it showed the "walking effect" almost perfect. now, i have series of frames for my attack sequence (a player holding a sword for example).. is it possible to use different time delays between my frames? for example, i have 4 frames for my attack sequence, first frame for .5ms, second frame for 1ms, third frame for .7ms and so on..?
i really am wondering..

TimerTasks are not a very good way to control animations in MIDP. You should learn how to use a thread to run a game loop, and control the animation from there. For example:
class MyCanvas extends Canvas implements Runnable {
  boolean running, paused;
  void start() {
    running = true;
    paused = false;
    (new Thread(this)).start();
  void pause(boolean pause) {
    paused = pause;
  void stop() {
    running = false;
  public void run() {
    long lastTime = System.currentTimeMillis(), time, deltaTime;
    while (running) {
      time = System.currentTimeMillis();
      deltaTime = lastTime - time;
      // update all your variables. deltaTime is the time since the last update, so this way you can control
      // everything timed whatever way you want
      update(deltaTime);
      repaint();
      serviceRepaints();
      lastTime = time;
      Thread.yield(); // let other threads run so the app is not unresponsive
}But in general, having frames taking different amounts of time is not a very good idea. It will complicate the code too much. Instead have a frame sequence where if one frame has to take longer, you just repeat it. So if your walking animation has 4 frames that need to be displayed for 20 ms each, and your attack frame has one frame that needs to be displayed for 15 ms, a second frame for 30 ms, and a third frame that needs to be displayed for 35 ms - you can time your frames for each 5 ms. and have the following frame sequences:
walking: {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4}
attaking: {1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,3}
Every 5 ms you update the screen and look into the frame sequence array to decide which frame to draw. Check out the Sprite class' documentation (javax.microedition.lcdui.game.Sprite), as it has a good explanation of this technique.
(btw, unless the game is very very simple, one frame every 5 ms is not a very realistic figure on real phones)
shmoove

Similar Messages

  • Midp 2.0: is it possible to run 2 timers at the same time?

    elo! jz wondering if its possible to run 2 timers at the same time..

    actually, im going to use the first timer for the character's animation such as walking.. the other timer i'll use for timing the 'walking activity' of the character (let's say, 3 seconds walking).. after 3 seconds, the character will stop and do other activity aside from walking..
    p.s.
    im mentioning about timers in midp 2.0 :)

  • How to start with CDC?

    Hi, friends:
    I have read much online material about CDC, but I'm still confused.
    I knew that I can download the WTK2.2 or higher to develop the app based on the CLDC and MIDP.
    My question is how to start with CDC. For example, If I use JBuilder, what stuff should been downloaded and installed? and how about the Eclipse?
    And some online learning resource is better!
    Thanks in advance!

    See
    http://home.elka.pw.edu.pl/~pboetzel/
    for HOWTO run SWT application on PocketPC (emulator). I used CDC 1.1 Personal Profile 1.1. You will find exact instructions what to download and install to write and run CDC applications. And also links to other guides and tutorials.

  • Questions on MIDP Security

    Hi all,
    I've a few questions on MIDP security to seek help:
    1) Suppose I have a midlet to store confidential details on the mobile phone, if it doesn't make any connections to the internet, would anyone be able to retrieve the information I'd on the RMS?
    2) Again, assuming no internet connection is made by the midlet. Suppose I've a login screen that prompts for a password & uses MD5. Can anyone crack it?
    3) Is it possible to retrieve the midlet from the mobile phone itself onto a desktop?
    Thanks for the help!

    Yes, it is possible to retrieve the data stored in
    RMS.
    Just try it on a Nokia S60 phone:
    1. download and install FExplorer (free file
    explorer)
    2. go to: c:\system\midp\<vendor>\untrusted\<midlet
    name>\<?????> folder
    3. select rms.db
    3. choose options/send/SMS|MMS|e-mail|bluetooth|irda
    Of course cracking is a harder work...does this means that I can follow your step 1 & goto whichever midlet that I'm interested in & send the JAR/JAD file via SMS/MMS/Email/BlueTooth/IRDA?

  • Hi,all I have a permission question about midp's httpconnection class

    Connection conn=Connector.open("http://www.sina.com.cn");
                   HttpConnection hc=(HttpConnection)conn;
                   int len = (int)hc.getLength();
                   byte[] b=new byte[len];
                   hc.openInputStream().read(b);
                   hc.close();
                   g.drawString(new String(b),0,0,0);
    this is my code, in function startApp()
    the result of the execute is that the screen prompt me a question:
    is it ok to use airtime?
    and the execption is :
    java.lang.SecurityException: Application not authorized to access the restricted API
         at com.sun.midp.security.SecurityToken.checkForPermission(+331)
         at com.sun.midp.security.SecurityToken.checkForPermission(+15)
         at com.sun.midp.midletsuite.MIDletSuiteImpl.checkForPermission(+20)
         at com.sun.midp.midletsuite.MIDletSuiteImpl.checkForPermission(+13)
         at com.sun.midp.io.ConnectionBaseAdapter.checkForPermission(+67)
         at com.sun.midp.io.j2me.http.Protocol.checkForPermission(+17)
         at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+6)
         at javax.microedition.io.Connector.openPrim(+121)
         at javax.microedition.io.Connector.open(+15)
         at javax.microedition.io.Connector.open(+6)
         at javax.microedition.io.Connector.open(+5)
         at com.ipanel.j2me.test.TestCanvas.paint(+5)
         at javax.microedition.lcdui.Canvas.callPaint(+80)
         at javax.microedition.lcdui.Display.repaint(+77)
         at javax.microedition.lcdui.Display.registerNewCurrent(+237)
         at javax.microedition.lcdui.Display.access$400(+6)
         at javax.microedition.lcdui.Display$DisplayAccessor.foregroundNotify(+46)
         at javax.microedition.lcdui.Display$DisplayManagerImpl.notifyWantsForeground(+152)
         at javax.microedition.lcdui.Display$DisplayManagerImpl.access$100(+6)
         at javax.microedition.lcdui.Display.setCurrentImpl(+98)
         at javax.microedition.lcdui.Display.setCurrent(+29)
         at com.ipanel.j2me.test.Test.startApp(+16)
         at javax.microedition.midlet.MIDletProxy.startApp(+7)
         at com.sun.midp.midlet.Scheduler.schedule(+270)
         at com.sun.midp.main.CommandProcessor.run(+141)
         at com.sun.midp.main.CommandProcessor.dispatch(+49)
         at com.sun.midp.main.CommandProcessor.perform(+27)
         at com.sun.midp.main.Main.main(+171)
    i need to help... thanks

    You need to add permissions for some APIs in the JAD file.
    Ex. Add following line in your JAD (Java Archieve Descriptor) of your application.
    MIDlet-Permissions-Opt: javax.microedition.io.Connector.http
    Multiple permissions are to be separated with comma.
    Onkar

  • LV 5.11 Question for the old timers

    For reasons I won't get into here I am using LV 5.11 for this test.
    I have a couple arrays that are being initialized properly but not being updated and return to their uninitialized (grayed out) state when the program runs . (Min-Remain and Current State)
    Running the trace I see that the main for loop is not being executed.
    I don't think I have ever ran into this before.
    Any ideas?
    Message Edited by RTSLVU on 12-06-2007 11:55 AM
    Attachments:
    Fp1230 Battery discharge test.vi ‏254 KB

    A FOR loop iterates as many times as...
    The smallest number of (1) the value wired to N and (2) the size of the smallest autoindexing input array.
    You have an autoindexing tunnel containing an empty array (from the unititialized shift register!), thus the iteration count will be zero.
    It's not really a question for old timers. This behaves the same even in 8.5 and is correct and expected.
    Message Edited by altenbach on 12-06-2007 10:10 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    EmptyShifter.png ‏12 KB

  • New to Apple TV, question for the wise, old-timers

    Love this device but was curious about user experiences, trial and error throughout the years, and just plain ol' tech knowledge...what is truly going to be a better than "good" steaming bandwidth for all my 1080p purchases? I'm about to order faster cable internet (currently have DSL ) so here're some questions:
    A. Will a dedicated 10Mbps cable connection be sufficient to stream my 1080p movies instantly and steadily as if I was watching a Blu-ray disc? (I mostly have my movies and shows streaming from my computer HDD, not cloud)
    B. Does it matter if other devices, i.e., computers, iPads, iPhones, printers, TVs, disc players all have Wi-Fi enabled but aren't necessarily being used to stream at the same time as Apple TV? Like, should I turn Wi-Fi off temporarily on all other devices when trying to watch a 1080p movie.
    C. Any chance of installing VUDU or Pandora or anything else on the Apple TV?
    D. Can I run Windows on it? (just kidding)
    Thanks in advance for your suggestions and insights.

    A. Yes 10mbps is sufficient. If they are stored locally then you wouldn't be using the internet.
    B. No, but if you have a lot of Wi-Fi devices close together it may cause interference
    C. No. Pandora can be airplayed from an IOS device though.

  • Some Questions on MIDP 2.0 on non Symbian phones

    Hi,
    I have been reading around on this forum seaaarching for some answers.. but all i can seem to find is a mix of hazy suggestions. Nobody seems quite clear on these issues. i am windering if someone out there has some definate answers.
    1. I have been reading that you can listen for incoming SMS by listening at a specified port. From what i believe.. if you intercept the message and do whatever you need to do with it.. there is never any chance of it reaching the phones inbox. Is this correct?? If this is correct is there someway that you could listen for a message and if it was not from the specific sender.. dont process it and send it to the inbox?? Ideally in my application I would like to be able to intercept SMS, read them and then later be able to see them in my inbox.
    2. If I have my application running and I receive a phone call.. what happens?? Does it allow me to take the call and then return to my app?? Or do i have to intercept the call in my application and process it?? (If this is the case will I be able to see it in my call log). Also if I want to make calls from my application will i be free to use the number keys to punch in a number and the phone allows me to make a call?? If i call a number from within my code by clicking on a link I probably wont see this in my call log - is this true??
    3. Does the Wirelesss Messaging API allow me to process and send MMS messages??
    (Sorry but I just dont have a non Symbian MIDP 2.0 phone at the moment)
    All answers appreciated!
    Thanks,
    Brian

    Hi,
    Shmoove thought you were on vacation... you still have not answered my last post ;-) dukes wating for you!!!
    Brian, you can make calls from within your MIDlet using your MIDlet class's platformRequest() method.
    e.g.
    this.platformRequest("tel:"+ myNumber); //from your midlet class
    MyMIDlet.platformRequest("tel:"+myNumber); // from elsewhereAs for what does the phone do with an SMS bound for a specific port?
    well that depends on the idiot who was the project manager for that device model. Some pass it on to the inbox if there's no listener for that port, some dont. It's better if its not forwarded to the inbox as more often that not its not going to be in H.R.F.
    cheers.

  • A J2ME and MIDP 2 question

    2 Questions
    1. If I have a sprite on a layer but the layer manager is only showing a part of the layer and the sprite is not on that part of the screen are any resources being taken up by the sprite? If so what would be a good way to manage sprites (in this case enemies) that have a predetermined position on the much larger layer that need to be added to the layer when the screen is visible?
    2. What is the largest size I can use for a image that I am going to be using as my game area?

    1: yes, the sprite is using resources. it uses space from the offscreen buffer.
    i suppose that you are a game buff. there are two types of having bbiigg maps. one is zelda type (gbc). and the other is pokemon type(gbc). in zelda type, each screen is one layer, and you move from screen to screen by moving from layer to layer, with a 2d matrix of layers coming together to make a map.
    in pokemon type, there is one bbbbbbbbbbiiiiiiiiiigggggggggg layer through which you scroll smoothly. this is tougher. best is to have a condition for each sprite like isVisible. if it is false, suspend all animations for that sprite. if it is on the screen, start it's animation.
    You can divide this into smaller layers by using tricks like 'doors' through which you pass through to go to other layers. never have a layer too big because it will kill performance.
    for an image the largest size can be indeterminate, as long as you have the space for it on the heap. also only a part of it as large as the screen size can be displayed at once.
    hope this helps
    Arjun

  • Question about Canvas in MIDP 2.0

    HI ALL
    Can anyone tell me, is the function setFullScreenMode(boolean b) work
    on all phones wich support MIDP 2.0?
    I can only try on Nokia, Samsung, SonyErocsson
    Thank you.

    It doesn't work on SonyEricsson P900
    The canvas size will be untouched with the same resolution 208x253.
    On SonyEricsson P910 you may call setFullScreenMode after first paint is over only. If not you will get an exception.

  • Repaint question on j2me midp 2.0

    Hi,
    Is there a way to force repaint() happens at the time you want to call it instead of queueing it in an event queue? If I do that, what are the drawbacks?
    And on a real phone, what is the performance difference before repaint() a region verus repaint() the whole screen? And does setting up clipping rect help performance?
    Thank you.

    I think that you can call repaint() whenever you want in GameCanvas. The good thing is that you have the full control. The bad thing is that you will see the screen "flashing" if you call repaint() too frequently.
    The performance is dependent on the MIDP 2.0 implementation of the phone. MIDP 2.0-compatible phones might have different performance but they must have the same functionality.
    I have tried on Motorola V300 and V600, repainting on the clipped region is faster than repainting the whole screen.

  • Question about the front page of Timers Reader?

    Hi
       It is impressive to see the Timers Reader,  implemented by AIR and TLF,
       As we open the Timers Reader,  the first page into your eyes are a bunch of top news headlines.  I am trying to figure out how to create this by TLF ? is each headline a paragraph element of TextFlow  or  a container of TextFlow  ,  or just a  TextFlow ?

    I would guess that each one is its own a little TextFlow.  If you are using the Flex 4 SDK, there are documented methods of how to create horizontal list-type component like that with item renderers that utilize TLF to render the text.  You could also create a very simple component that uses TLF directly by using a TextFlow with either a container controller or a text line factory to render the headline text within the component.

  • J2ME and MIDP beginner questions

    Can anyone recommend editor/IDE, toolkit etc. for coding, building and testing MIDP2.0 apps/games?
    Until now I've coded a game using J2SE. I used Forte 3.0 for coding and compiling, and IE5.5 for testing.
    Now I want to code mobile games/apps using J2ME and MIDP 2.0. What software do I need? I downloaded Sun ONE studio 4 ME and wireless toolkit 2.0, but are kind of struggeling with it :)
    Regards
    Hallvard

    Ok, I found out that the toolkit compiled the .java files and could bulid the .jar and .jad files, and then test the MIDLet on the emulator.
    But what about a good editor/IDE for MIDLets? In Sun ONE studio ME i finally managed to create a HelloWorld Midlet (with new project wizard), and build and run it in the toolkit.
    I also heard that Borland JBuilder Mobile Edition was a nice IDE for J2ME/MIDLets.
    Hallvard

  • Timers question

    Hi, I would like you to confirm if this suspiction of mine about timers is true:
    If I have a Timer that executes a TimerTask each five seconds, but the TimerTask delay more than five seconds, the Timer waits until TimerTask execution finish to call TimerTask once again if I use schedule method, doesn't it? That's to say, there are not two TimerTask executions running at the same time with schedule method. �Is that correct?
    Thanks

    Hi,
    Yes, that's correct.
    Kaj

  • Question about pausing Timers

    When excuting this method ( Thread.currentThread().wait() ) inside a TimerTask Class, the associated Timer class will also be paused? If not, how could I achieve this?

    magaupe wrote:
    I'm using java.util. Another thing is that I must pause it in the middle of the method. Pausing only the Timer wouldn't make the method run til the end?If you are using swing, change to javax.swing.Timer
    The Timer is separate from your running code, you'll have to stop both.

Maybe you are looking for

  • Camera quality of my nokia 5800

    i have nokia 5800 quality of cam is 3.2 megapixel resolution 2048 * 1536 when i entered nokia website and compared it with nokia e66 i found that they have the same camera quality but in fact 5800 camera quality is very very bad in compare to nokia e

  • How do I get rid of the very annoying "find" tab that appears on the bottom of the page constantly???

    Whenever I try to type "anything anywhere", even after I have clicked on the appropriate place to search, a search box appears on the bottom of the page with a "find" option, and my search goes there instead of the actual place it should go to. Every

  • Using Essbase security filter in OBIEE request ?

    Hello, We would like to use OBIEE 11.1.1.6 with Essbase source. We already use Essbase security filter (on dimensions). For example, "userA" is allowed to access to Entity A and not Entity B and the opposite for "userB". If I loggin as "userA" in OBI

  • Unknown e-mail addresses appearing as options

    When choosing an e-mail to send to, there are various e-mails that appear as options that I don't recognise.  They are not in my contacts, and aren't addresses I've previously mailed. I would like to delete them, so they do not appear as options in f

  • Not all links work when migrating iweb to ftp

    I migrated my iweb site from mobilem to another host and now some of the movie links that I use are not working.  Everything else is working like text and photos but the movies I get the quicktime icon in the place for them.  What am Idoing