Results 1 to 8 of 8

Thread: Whats the best way to create animation???

  
  1. #1
    CT_Bolt's Avatar
    CT_Bolt is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Location
    With the humans
    Posts
    54
    Rep Power
    14

    Default

    This is my code for a start on an animation function(it's still pretty sloppy :():

    Code:
    -- Set up tables
    TabAnim = { Nam = "Table Name", Number = nil, DestImg = nil, SrcImg = nil, DestX = 0, DestY = 0, StartRow = 0, StartCol = 0, EndRow = 0, EndCol = 0, SrcWidth = 1, SrcHeight = 1, SpaceX = 0, SpaceX = 0, StartX = 0, StartY = 0, Delay = 10, DelayCtr = 0, CurrentRow = 0, CurrentCol = 0 }
    
    -- ************************** Functions ************************** --
    
    function DrawSection( DestImg, SrcImg, DestX, DestY, Row, Col, SrcWidth, SrcHeight, SpaceX, SpaceY, StartX, StartY )
    	if not Row then Row = 0 end
    	if not Col then Col = 0 end
    
    	DestImg:blit( DestX, DestY, SrcImg, ((SrcWidth + SpaceX) * Row)+ StartX, ((SrcHeight + SpaceX) * Col)+StartY, SrcWidth, SrcHeight )
    end
    
    function InitAnimation( AnimTable, Nam, Number, DestImg, SrcImg, DestX, DestY, StartRow, EndRow, StartCol, EndCol, SrcWidth, SrcHeight, SpaceX, SpaceY, StartX, StartY, Delay )
    	if not DestImg then DestImg = screen end
    	if not SrcImg then SrcImg = screen end
    	if not DestX or DestX < 0 then DestX = 0 end
    	if not DestY or DestY < 0 then DestY = 0 end
    	if not SrcWidth or SrcWidth <=0 then SrcWidth = 32 end
    	if not SrcHeight or SrcHeight <=0 then SrcHeight = 32 end
    	if not Number or Number <= 0 then Number = 1 end
    	if not SpaceX or SpaceX < 0 then SpaceX = 0 end
    	if not SpaceY or SpaceY < 0 then SpaceY = 0 end
    	if not StartX or StartX < 0 then StartX = 0 end
    	if not StartY or StartY < 0 then StartY = 0 end
    	if not Delay or Delay <= 0 then Delay = 10 end
    	if StartRow < 0 or not StartRow then StartRow = 0 end
    	if StartCol < 0 or not StartCol then StartCol = 0 end
    	if (SrcImg:width()-StartX) / (SrcWidth+SpaceX) < EndRow then EndRow = ((SrcImg:width()-StartX) / (SrcWidth+SpaceX)) - StartRow end
    	if (SrcImg:height()-StartY) / (SrcHeight+SpaceY) < EndCol then EndCol = ((SrcImg:height()-StartY) / (SrcHeight+SpaceY)) - StartCol end
    	
    	AnimTable.Nam = Nam
    	AnimTable.Number = Number
    	AnimTable.DestImg = DestImg
    	AnimTable.SrcImg = SrcImg
    	AnimTable.DestX = DestX
    	AnimTable.DestY = DestY
    	AnimTable.StartRow = StartRow
    	AnimTable.EndRow = EndRow
    	AnimTable.StartCol = StartCol
    	AnimTable.EndCol = EndCol
    	AnimTable.SrcWidth = SrcWidth
    	AnimTable.SrcHeight = SrcHeight
    	AnimTable.SpaceX = SpaceX
    	AnimTable.SpaceY = SpaceY
    	AnimTable.StartX = StartX
    	AnimTable.StartY = StartY
    	AnimTable.Delay = Delay
    	AnimTable.DelayCtr = 0
    	AnimTable.CurrentRow = 0
    	AnimTable.CurrentCol = 0
    
    end
    
    function UpdateFrame( AnimTable )
    	AnimTable.CurrentRow = AnimTable.CurrentRow + 1
    	if AnimTable.CurrentRow > AnimTable.EndRow then
    		AnimTable.CurrentCol = AnimTable.CurrentCol + 1
    		AnimTable.CurrentRow = AnimTable.StartRow
    	end
    	if AnimTable.CurrentCol > AnimTable.EndCol then
    		AnimTable.CurrentCol = AnimTable.StartCol
    		AnimTable.CurrentRow = AnimTable.StartRow
    	end
    end
    
    
    function Animate( AnimTable, DestX, DestY)
    
    	if DestX > 0 then AnimTable.DestX = DestX  end
    	if DestY > 0 then AnimTable.DestY = DestY  end
    
    	AnimTable.DelayCtr = AnimTable.DelayCtr + 1
    
    	if AnimTable.DelayCtr >= AnimTable.Delay then
                    AnimTable.DelayCtr = 0
    		UpdateFrame( AnimTable )
    	end
    
            screen:print(235,0, AnimTable.Delay, Color.new(255,0,0))
            DrawSection( AnimTable.DestImg, AnimTable.SrcImg, DestX, DestY, AnimTable.CurrentRow, AnimTable.CurrentCol, AnimTable.SrcWidth, AnimTable.SrcHeight, AnimTable.SpaceX, AnimTable.SpaceY, AnimTable.StartX, AnimTable.StartY )
    end
    
    
    -- *************************************************************** --
    
    -- Open USB connection
    System.usbDiskModeActivate()
    
    -- ************************* Load Images ************************* --
    
    -- Load Lua Player Logo
    ImgLuaPlayerLogo = Image.load("img/misc/luaplayer.png")
    
    -- Load Misc.
    ImgBlueFountain = Image.load("img/misc/Blue Fountain.png")
    
    -- ********************** Set up Animations ********************** --
    
    AnimBlueFountain = {}
    for i = 1,4 do
      AnimBlueFountain[i] = TabAnim
      InitAnimation( AnimBlueFountain[i], "Blue Fountain", i, screen, ImgBlueFountain, 0, 0, 0, 3, 0, 4, 107, 68, 0, 0, 0, 0, 10 )
    end
    
    AnimBlueFountain[1].Delay = 200
    AnimBlueFountain[2].Delay = 150
    AnimBlueFountain[3].Delay = 100
    AnimBlueFountain[4].Delay = 10
    
    -- *************************************************************** --
    
    -- ************************ Start Display ************************ --
    
    screen:clear()
    screen:blit((screen:width() - ImgLuaPlayerLogo:width()) / 2, (screen:height() - ImgLuaPlayerLogo:height()) / 2, ImgLuaPlayerLogo)
    screen:flip()
    
    -- *************************************************************** --
    
    ImgCurrentBoard = ImgBoard[1] -- Set current board
    
    while true do
    	pad = Controls.read()
    	if pad:start() then break end
    
    	screen:clear()
    	screen:blit((screen:width() - ImgLuaPlayerLogo:width()) / 2, (screen:height() - ImgLuaPlayerLogo:height()) / 2, ImgLuaPlayerLogo)
    
    	Animate( AnimBlueFountain[1], 0, 0)
            Animate( AnimBlueFountain[2], AnimBlueFountain[2].DestImg:width()-AnimBlueFountain[2].SrcWidth, 0)
            Animate( AnimBlueFountain[3], 0, AnimBlueFountain[3].DestImg:height()-AnimBlueFountain[3].SrcHeight)
    	Animate( AnimBlueFountain[4], AnimBlueFountain[4].DestImg:width()-AnimBlueFountain[4].SrcWidth, AnimBlueFountain[4].DestImg:height()-AnimBlueFountain[4].SrcHeight)
    
            screen.waitVblankStart()
    	screen:flip()
    end
    Now my question to all you wonderful Lua( Player) Programmers is how to make this function the best posible.
    Right now it works, but, the Delay(time before next frame) is the same for all of the animations.
    I don't want this to happen and I don't understand why it happens :mad: :/).

    I know there has to be a better way.;) Plz let me know(explain it well) how to do it better. :)

    PS. Dimentions:
    luaplayer.png = 144x95
    Blue Fountain.png = 428x340

    If you would like to test it. :)


  2. #2
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    Wow -- I'd just modify the lua player to account for animation. But to each his own.

    screen.waitVblankStart()

    use x (the amount of time you want to pause for

    so your saying pause for x
    x = 1 pause for 1
    x = 200 pause for 200

    or

    screen.waitVblankStart(AnimBlueFountain[x].Delay)

    simple is always best.
    july 19

  3. #3
    MikeG13 is offline -Hacks Newbie
    Join Date
    Jan 2006
    Posts
    48
    Rep Power
    14

    Default

    I'd have someone else do it

  4. #4
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    I'd personal modify the lua player but he seems to be looking for quick and easy. it's either that or the os.time() which I already mentioned to him.
    july 19

  5. #5
    CT_Bolt's Avatar
    CT_Bolt is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Location
    With the humans
    Posts
    54
    Rep Power
    14

    Default

    screen.waitVblankStart()

    use x (the amount of time you want to pause for

    so your saying pause for x
    x = 1 pause for 1
    x = 200 pause for 200

    or

    screen.waitVblankStart(AnimBlueFountain[x].Delay)

    simple is always best.
    So this freezes the whole screen for an amount of time taken from AnimBlueFountain[x].Delay correct?:|

    I just want a picture(frame of the animation) to stop, not the whole screen, so if that's what this does I don't mean that. :/

    Oh and why doesn't mine work in the way I'm talking about, I send a table with a different delay time and delay counter to the Animate Function Increasing the counter by 1 every time, then when it reaches the delay value it changes the frame and resets the delay counter but, everytime it's called it only goes up to the last delay value of the table(in my case the 4th value) instead of the table that is sent(which I use the delay value of.)

  6. #6
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    I thought there was no other processing going on then you want to use os.time() or make more frames of the same pic.


    As for your code way to man functions for me to want to follow it -- I'll leave it to someone else
    july 19

  7. #7
    CT_Bolt's Avatar
    CT_Bolt is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Location
    With the humans
    Posts
    54
    Rep Power
    14

    Default

    Heheh...yeah I like to use functions(although those are pretty sloppy).:)

    illfoundedmind wrote:

    I thought there was no other processing going on then you want to use os.time() or make more frames of the same pic.
    So, could you show me a sample of how exactly to use os.time(), plz comment. :o Oh and I don't want to make more pictures of the same image(that is just such a waste).:|

  8. #8
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    I think I already did ;)

    google it you'll find something ;)
    july 19

Posting Permissions

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