×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    19

    How do I invoke a Command from code

    Hi all,

    Is it possible to invoke a command added to a GameCanvas from code?

    I want to activate the command in the game loop when getKeyStates() returns a specific value. Is that possible.

    /Jimmi

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Sure, you can call commandAction() yourself.

    shmoove

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    19
    Wouldn’t a call to commandAction on result in a direct call to

    public void commandAction(Command c, Displayable s)

    on the GameCanvas.

    If this is true then I see two problems:

    1) I want to invoke the commandAction from my game loop thread. This means that the commandAction is not called from the main midlet thread as usual but from my custom thread instead. Would this potentionally give some problems?

    2) It is not the GameCanvas that set as the commandListener in my situation. Instead it is a control class that handles all the events. So if I call GameCanvas.commandAction directly the control class will not receive the events.

    Are the two problems that I described above legitimate?

    Isn't it possible to invoke the command from code so it is invoked by the framework the same way as other commands?

    /Jimmi

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    1) Could be a problem if the command takes a while to be processed - it will stall your game loop. But you can just make a small thread and call it from there. Another option is to use Display.callSerially() if you want it on the main event thread.
    2) Just call the commandAction from your control class or wherever you implement it.

    shmoove

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×