Frames per second - or something

Does anyone have an idea how many fractions of a second it takes to put an image onto the screen, and clear it? If I did that 1000 times, could I create a one or two second animation? Or is it even more than that? If you don't factor in lag for slow computers, is there a set "frames" (or activities of that size, ie: show picture - clearscreen) per second?
I will benefit even from well educated guesses, here, if no one has access to the actual number.
I would really like to try it.


The frame rate would be whatever you set it to. If you add an image then remove it again, it probably wouldn't be visible because the script does not wait for the image to be displayed before continuing.

So if you wanted to do frame based animation, it would be up to you to decide how long to wait between drawing an image and removing it.


Can I make it be 1/4 of a second per image?


I just thought that if, since the timer only works with seconds, I could add an image and clear screen 500x and have at least a blip of that image (if at 50% opacity), then, a different image 500x, and so on image a, image b, image c, image b, and loop it. Would that not be half visible? And it could look like a hologram of something in three positions.

Is there a way to find out, would it be 1000 activities per second, or 1,000,000,000? I know I couldn't do 1,000,000,000, but I could do 1000.


If there is a way to cut seconds in half, I would take that.


Why not use a gif? I feel like doing that many actions in such a small timespan is bound to cause something funky.


Quest's timers can be up to a second earlier or later than the time you specify. To do something like this, you would need to use a javascript setTimeout, which takes a time in milliseconds as its parameter. However, if you want to create an animation it would probably be much more efficient to use an animated GIF or some other format that supports it. If necessary, you could add a couple of seconds of the last frame, and then use a timer to remove it after it finishes.


Thanks! It was actually easy to find. I'll see if I can make it work.


I haven't been able to upload animation or anything to Quest. Maybe, my connection is too slow. I might be able to use the setTimeout for milliseconds, though.


Is this how that would be done? The page I was reading wasn't specific to Quest, so this is my best guess. Hmm.
picture ("")
JS.setTimeout (ClearScreen, 300)
JS.setTimeout (picture (""), 600)
JS.setTimeout (ClearScreen, 900)
JS.setTimeout (picture (""), 1200)


So, no. That didn't work because "ClearScreen" was an unknown object.
Alright. I have discovered using tabs and typing in .5, instead of 1, which works, incredibly.
I would never have guessed.


If it's working, I think that's a good thing. But I suspect the timing will be erratic, especially playing online. Hope it works for you :)


For the JS.setTimeout option you would need to pass a javascript command as the parameter. I think there is a JS ClearScreen function; but not sure if it has the same name.

In this case, I suspect that rather than removing the image, it would be better to hide it; so that to display a new one you can just take the one that already exists and change it to a different image.

Off the top of my head (and typing on my phone, so sorry for any typos) I think you could use something like:

$(function() {
  var timerid;
  var img = $('#divOutput img').last();
  var frames = [];
  window.animateImage = function() {
    frames.push(arguments);
    if (!timerid) {
      processFrame();
    };
  };
  var processFrame = function() {
    timerid = 0;
    while (frames.length) {
      var i = frames.shift();
      if (!i) {
        img.hide();
      } else if (isNaN(i)) {
        img.show().attr('src',i);
      } else {
        return(timerid = setTimeout(processFrame, i));
      }
    }
  };
});

OK, that's probably a little over-engineered.
An example usage in Quest (with the code compressed a little) might be:

picture("image1.png")

JS.eval("$(function(){var t,n=$('#divOutput img').last(),a=[];window.animateImage=function(){a.push(arguments),t||e()};var e=function(){for(t=0;a.length;){var i=a.shift();if(i){if(!isNaN(i))return t=setTimeout(e,i);n.show().attr('src',i)}else n.hide()}}});")

JS.animateImage(500, "", 500, GetFileURL("image2.png"))
JS.animateImage(500, GetFileURL("image3.png"))
JS.animateImage(1000)
JS.animateImage(0)

In this case, the new function JS.animateImage can take as many parameters as you want to give it. "" or 0 tells it to hide the image, a URL tells it to show that image, and a nonzero number tells it to wait for that many milliseconds. Calling it more than once adds instructions to the end of the queue, so you can put each picture on its own line, or all on the same line, whichever you prefer.


How does the game engine know how to GetfileURL for the .png?
I tried with offline png, first, and with online URL, copylink, instead of .png, after that, but neither worked. I am a bit behind the times, so I am still not sure how to include the URL based ".png"
The bottom script with cop and paste gives me a blank image, meaning the first image has shown, the second two weren't accessed. I think maybe a single second would be appropriate if it weren't for the timer lag I usually get from the tab timer. Using ".5", with the tab, blipped really fast, too.
I think when (and if) I find out how to attach online images (or offline) with this script, I might use it for full second images or 7.5 or something. (Don't worry. I can do that much math myself.)


The picture command calls GetFileURL internally. If you're passing images to a javascript function, you need to use the function to convert a filename to an actual URL. If you're using the URL of an image hosted on an external site, you don't need the GetFileURL.

GetFileURL just adds a prefix to the filename, so the browser knows where to find files that are part of the game package. I think it's something like http:/‌/media.textadventures.co.uk/(game-ID)/(filename) when you're playing online, and res://(filename) when playing offline; but I don't remember the exact format.

That code was all typed out on my phone and without access to the documentation, so I can't be sure that there aren't some mistakes on it.


Slight tweak to the code… I changed 'img' to '#divOutput img'; so it'll replace the last image in the game's output area rather than the last image on the page (thought I'm not sure whether there would be any images outside the output area or not)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums