Corroder Grandmaster Cheater Supreme
Reputation: 75 Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sat Jan 27, 2018 12:49 am Post subject: |
|
|
FreeER wrote: | The way I'd probably do it is have a table of each image and the index of the current image then in the timer you'd increment the index by one and change the image something like...
Code: | -- I don't think this is right for min values other than 1 but it seems to work here
local function wrap(value, min, max)
while value > max do value = value - max end
while value < min do value = value + max end
return value
end
function gifMaker(images, imageObject, interval)
if not images or type(images) ~= 'table' then return nil end
-- TODO check what the classname of CE's image object actually is... this is just a guess
if not imageObject or type(imageObject) ~= 'TCEImage' then return nil end
local gif = {}
gif.images = images
gif.current = 1
gif.imageObject = imageObject
-- TODO see if this is actually how you change the image lol
-- alternatively if you have multiple image objects then take a table of those
-- and hide all of them, then show the current by changing the Visible property
gif.updateImage = function() gif.imageObject.Image = gif.images[gif.current] end
gif.next = function() gif.current = wrap(gif.current+1, 1, #gif.images); gif.updateImage() end
gif.prev = function() gif.current = wrap(gif.current-1, 1, #gif.images); gif.updateImage() end
gif.timer = createTimer(gif.imageObject)
gif.timer.Interval = interval or 1000
gif.timer.OnTimer = function(t)
gif.next()
end
gif.updateImage() -- make sure the first is showing
return gif
end
|
Though I'd probably use a metatables for the common stff and lua's OOP with functions taking a parameter called "self" (arbitrary name) and calling them with gif:next() which is just syntatic sugar for gif.next(gif) |
I didn't see where is command to load pictures and store to gif table, so is it mean we need add and load gif pictures to form or gif table manually and then run gifMaker() function ?.
@Aylin
Quote: | How do I start multiple pictures sequentially with "onTimer"?
At the opening, if the trainer is brought to the scene with a robotic arm?
Can a GIF be built with Timer? |
DB provided it already, see topic : http://forum.cheatengine.org/viewtopic.php?t=579732
Code: | UDF1.show();
local ts,r=tostring,nil;
r = function(s,c,l)s,c,l=ts(s),ts(c),l+0;s=(#s<l and r(c..s,c,l) or s);return s;end; -- simple function to pad zeros
local main = UDF1.CEImage1; -- target
local fmin,fmax = 0,30; -- min frame, max frame
animation = animation or createTimer(getMainForm(),true);
animation.Interval = math.floor(1/30*1000); -- 30 fps
animation.onTimer = function (t)
local tag,id = string.match(main.Hint,"(%a+)_(%d+)"); -- find frame and the number from Hint
if (tag and id) then
id = (id+0>=fmax and fmin or id+1);
else
tag,id = 'frame',0; -- hint is not set, so let's set it.
end
local frame = string.format('frame_%03d.gif',id) -- frame_001.gif for example
main.Hint = frame; -- Storage.. lazy to use a variable;
main.picture.loadFromStream(findTableFile(frame).stream); -- find table file and load it into the image object
end |
The idea is store gif images to stream files and load it from stream in a sequences as picture image for image object (CEImage1 as example code above) by timer. Same to @FreeER function wrap()'s above.
On that example above, there are 30 frames (30 gif picture images) to be display, all gif's file name initial by "frame_xxx' (xxx = seq. numbers).
So, be careful with gif's file name, it must be same with gif file initial inside the function.
Also you can split a gif picture image to get all frames, use online tool, eq. : https://ezgif.com/split _________________ Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
|
|