Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: E's Lua Dev Thread

                  
   
  1. #21
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    87

    Default

    Quote Originally Posted by jman420
    its flexible, it uses a timer for the time that the button is pressed, therefor, as long as the button is pressed, it will count up untill it is told to reset

    it works just fine

    and the multiple if statements dont slow down the usability, the if statements are just there for when the assigned is done...
    You misunderstood. Here is the code for your animation:
    if timerL >= 10 then characterL = playerL2 end

    -- change when numbers are hit --

    if timerL >= 20 then characterL = playerL3 end

    if timerL >= 30 then characterL = playerL4 end

    if timerL >= 40 then characterL = playerL5 end

    -- change when less then 10 --

    if timerL <= 10 then characterL = playerL end

    -- other animation directions --

    if timerR == 50 then timerR = 0 end
    if timerR <= 10 then characterR = playerR end
    if timerR >= 10 then characterR = playerR2 end
    if timerR >= 20 then characterL = playerR3 end
    if timerR >= 30 then characterL = playerR4 end
    if timerR >= 40 then characterL = playerR5 end

    if timerD == 20 then timerD = 0 end
    if timerD <= 10 then characterD = playerD end
    if timerD >= 10 then characterD = playerD2 end
    if timerD >= 20 then characterL = playerD3 end
    if timerD >= 30 then characterL = playerD4 end
    if timerD >= 40 then characterL = playerD5 end

    if timerU == 20 then timerU = 0 end
    if timerU <= 10 then characterU = playerU
    if timerU >= 10 then characterU = playerU2 end
    if timerU >= 20 then characterL = playerU3 end
    if timerU >= 30 then characterL = playerU4 end
    if timerU >= 40 then characterL = playerU5 end
    Without changing the animation control code (above), how would an extra attack animation that is 3 times long fit in? More if statements? Bad design move.

    Currently you have 24 if statements running each loop, that is 24 branches of code and it WILL slow down the framerate (at least it does on complied languages). Now considering that this section of code is just for the player graphic, what happens when we have 20 NPCs on the screen at the same time? Taking the current coding method it would be 20 x 24 more if statements ran each frame. Not good for framerate.

    The usability is fine, the performence is what worries me.

  2. #22
    DCEmu Coder HardHat's Avatar
    Join Date
    Feb 2006
    Posts
    163
    Rep Power
    71

    Default

    There are two ways to improve it:

    move to elseif:

    if timerD == 50 then
    timerD = 0
    elseif timerD <= 10 then
    characterD = playerD
    elseif timerD <= 20 then
    characterD = playerD2
    elseif timerD <= 30 then
    characterD = playerD3
    elseif timerD <= 40 then
    characterD = playerD4
    else
    characterD = playerD5
    end


    (which improves the number of tests) or of course make it use tables:

    earlier (after images are loaded, but before the main while loop):

    playerDframe={playerD,playerD2,playerD3,playerD4,p layerD5}

    then instead of the list of ifs/elseifs:

    if timerD == 50 then timerD = 0 end
    characterD = playerDframe[math.floor(timer/10)]


    Edit: fixed cut and paste errors.

  3. #23
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    87

    Default

    I would have done the latter as there would only be two tests per frame per object. One for the time passed and another to reset the current frame in the table if it reaches the last frame.

  4. #24
    DCEmu Coder HardHat's Avatar
    Join Date
    Feb 2006
    Posts
    163
    Rep Power
    71

    Default

    Quote Originally Posted by yaustar
    I would have done the latter as there would only be two tests per frame per object. One for the time passed and another to reset the current frame in the table if it reaches the last frame.
    And as an added bonus, there is less chance of cut and paste errors. Just fixed two more from my example.

  5. #25
    DCEmu Pro jman420's Avatar
    Join Date
    Oct 2005
    Location
    Colorado, USA
    Posts
    756
    Rep Power
    76

    Default

    wait, did you copy that exactly? because yeah, thats realy messed up, I didnt mean to move the frame direction changes around..


    Edit:
    Yeah, that code was realy Funky, the directions werent supposed to change, so I modified it and made all the directions correct... I should have checked it before I posted it eh?

Page 3 of 3 FirstFirst 123

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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