bandi94 Posted July 31, 2013 Share Posted July 31, 2013 I am creating a costum GUI theme. (rebuild it with Dx) I made a function to animate move on X axis. All good when i call it 1 time. But when i call it 2 time's at the same time , to move 2 element's (images) at the same time , It get bugged , as far as i find it's that onClientRender it's not removed (only one of them is , every call create's one onClientRender.) function DGTAnimateStaticImage(Element,from_x,speed) local x = getElementData(Element,"x") setElementData(Element,"animation",true) setElementData(Element,"x",from_x) move_image = function() local x1 = getElementData(Element,"x") if not x1 then removeEventHandler('onClientRender',getRootElement(),move_image) end if(x1<=x) then setElementData(Element,"x",x1+speed) else removeEventHandler('onClientRender'getRootElement(),move_image) outputChatBox("removed") setElementData(Element,"animation",false) end end addEventHandler('onClientRender',getRootElement(),move_image) end Link to comment
denny199 Posted July 31, 2013 Share Posted July 31, 2013 Why not use interpolateBetween with tables and one "onClientRender" with a loop trough the table to show all costum windows? Link to comment
bandi94 Posted July 31, 2013 Author Share Posted July 31, 2013 Well i don't need to use "interpolateBetween" , my way is more easy bk i need only a linear X axe move. I don't used table bk i wanted to save "onClientRender" (my way stop's the EventHandler when the move is completed , table mode will not stop the EventHandler bk he need to check if there is any new element in the table, so i can't stop it). One way would be to send a tabel and call it only once. But this way will not work if i wanna a delay between the starting time's. So i gues the table mode is only way. Link to comment
Moderators IIYAMA Posted July 31, 2013 Moderators Share Posted July 31, 2013 What is wrong with table mode? What is wrong with writing directly to the ram? It can't be faster can it? Tables can do everything, even stop things. There is and function called: https://wiki.multitheftauto.com/wiki/IsElement Loop through the table and when you notice the element is gone you can simply remove it from the table. setElementData is a function a table isn't, so use local tables or data ...... they almost don't have any delays/lagg. Link to comment
Moderators IIYAMA Posted July 31, 2013 Moderators Share Posted July 31, 2013 This is how I script this: local imageTable,renderImage = {},false local move_image move_image = function() for element,data in pairs(imageTable) do if isElement(element) then local x1 = data.from_x if(x1<=x) then data.from_x = x1 + data.speed else imageTable[element]= nil end else imageTable[element]= nil end end if not next(imageTable) then removeEventHandler('onClientRender',root,move_image) renderImage = false end end function DGTAnimateStaticImage(Element,from_x,speed) imageTable[Element] = {from_x = from_x,speed = speed} if not renderImage then addEventHandler('onClientRender',root,move_image) renderImage = true end end You can delete images every single moment you want and the render function will stop when there isn't anything to render. imageTable[element]= nil Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now