I'm creating a web game using Ruby on rails. A text or an image appears and the player has to take it or not, and I neeed to measure his reaction time precisely (in milliseconds).
I can't start the timer in the controller method because of the delay between the server and the player.
Is there a way to start the timer when the page has finished loading ? Or is there an other way to do ? I haven't found any solutions..
You can do it in javascript land - save performance.now() in body onLoad or similar ($(function(){ ... }) if you're using jQuery),
For an image - take first measurement in its onload event, because image may be loaded and shown later than just text. Also take into account custom fonts loading that may also delay rendering.
Then on user reaction take second value, difference between these will be in milliseconds.
Related
For the slideshow feature, the images are on a remote server, then can we implement a batch look ahead download of the images? We want say 'n' images ahead downloaded when an image is being viewed - this helps in providing a smoother viewing experience. Is this a good way to get zero latency for the slideshow or is there any better way than this.
To provide a smooth viewing experience as well as reduce (not zeroing) the latency for your slide show, I agree with caching mechanism.
I assume that you have a list of image urls, now as soon as the slide show displaying on the screen, start loading visible items. Trigger scroll view did scroll and load in the background the next n images after the last visible index, then cache them. So that whenever user scrolling to next indexes, images almost the time will be there in your memory and displayed instantly.
Why we should trigger scroll view did scroll. Firstly, because that is the idle time that allows you start doing things without user's notice. Secondly, if you start loading images while scrolling, at the time it is set to UIImageView, your slide show will be lag due to that task executed on main thread.
As the answer above, SDWebImage is a good library that can help you finish your task.
By the way, if you will consider of using SDWebImage, I would suggest you config this option
/**
* By default, image downloads are started during UI interactions, this flags disable this feature,
* leading to delayed download on UIScrollView deceleration for instance.
*/
SDWebImageLowPriority = 1 << 1,
I hope my answer will contribute 2 cents to solve your problem.
In my opninion, use SDWebImage https://github.com/rs/SDWebImage to preload images and clean memory cache if if exceed memory-limit.
I'm implementing map exporting functionality using OpenLayers 3.
But there is one problem: one cannot determine whether the map view is completely loaded or a few tiles is missing yet.
It seems there is no such API or event. The close one is tileloadstart - tileloadend pair. But OpenLayers loads tiles asynchronously, and before the tile is actually loading the tileloadstart is not fired - that is, a tile that is queued in the tile queue does not fire the event before actually loading.
Hot can I detect the map view is completely loaded?
postrender event seems to do the trick, like this:
map.once('postrender', function(event) {
doyourmagic();
});
Works at least from OpenLayers 3.8.2. There is fine answer there about the subject.
I eventually implemented the export function successfully. Below is the rough explanation.
Register tileloadstart, tileloadend, tileloaderror event handlers on the ol.sources using ol.source.on(), and start managing the tile load count.
Register postcompose event handlers on the ol.Map using ol.Map.once().
call ol.Map.renderSync(). This triggers the tile loading, so from now if there is no tile loading, it will mean that all tile have been loaded.
On postcompose event handler, capture the map content from event.context using event.context.canvas.toDataURL(), and register postrender function using event.frameState.postRenderFunctions.push() (a bit hacky).
On the registered postrender function, check the tile load count (which can be managed by the tileload* event handlers). If the count is not zero, abandon the captured content. Else, the capture is done.
On tileloadend and tileloaderror, if the tile load count becomes zero, retry from the step 3 above.
Meanwhile, OpenLayers provides a much sought after rendercomplete event which may be handy.
Basically to make sure everything is rendered on your map you need to listen for loadend events for each layer you have on the map. For wms and wfs layers this is clear and I guess you know how to do it.
For the tile layers , check this example here
As the application loads, I want to make an image load at the same time, for example, a line would elongate form either side as the application loads, and when it has finished, the line would have reached its maximum length. I have seen this in a few websites, like rime arodaky for example, but I want to this for an iOS application. I have searched on Google but couldn't find anything!
Does anyone know how to do this?
The launch process if we REALY simplify it to accommodate your question, can be split into two parts.
The first part you do not have any control over, and during which a launch image is shown.and it ends with a delegate call-back on the application delegate called
applicationDidFinishLaunchingWithOptions
The second part is you might have some application specific behaviour which requires no activity from the user but you app still isn't interactive.
You need to implement such a progress bar yourself. There is no built in support for this in any of the app templates in Xcode.
You can only do what you want during this second phase. But you have absolutely no control over the first phase, except for that static non-animated launch image.
I think you can just add a photo as a launch image, launch image is just an image.Then you can add the animation when your first view controller appears.You can fake it this way.
I've built a scroller prototype using WebGL. The problem is, when it's combined with other non-WebGL elements on the same page, the scroller becomes jittery and the quality is quite poor. You can see a demo here (scroller is at the bottom, ignore the Chinese characters) - http://viewer-test.appspot.com/Viewer.html?type=presentation&id=6a169bb8-e440-4338-9e3a-8b5e429f32ee&showui=false Even if I take out the video, the scroller still slows when the CPU spikes every time that RSS feed top right shows a new feed snippet.
I had considered using Web Workers to run the scroller on a different thread, but came across another post in this forum that said that Web Workers can't be used with WebGL. What are my other options to ensure smooth scrolling?
Thx.
Are you using RequestAnimationFrame for your animation callbacks? If not, you should. It's managed by the browser to time the draw of your element with the others on the page and with the system screen sync, so you get the smoothest presentation possible. If you do your animation using setTimeout or setInterval, you'll almost always end up out of sync with the pages rendering, which leads to dropped frames and stutters.
I have a script that takes lots of content and builds 1000s of MovieClips on the stage, does lots of drawing etc. Due to the high amount of work needed when the frame first loads this can sometimes be delayed by a second or two.
The more the user uses the application the longer and longer this is likely to be (more data to siphon through and build).
My question to you is how do I make sure the frame doesn't show (serve a loading image or something) until it is built? I don't want the user to see the skeleton of the page and then everything appear a second or two later.
The way we do it:
Frame 1 is a loading frame. It simply continually polls progress (onEnterFrame) until it is sufficiently "complete" to move on to the frame that is needed. In your case, it might be that you're testing to see if you've instantiated enough objects, in our case it was whether framesloaded was sufficiently high.
We often put a "loading graphic" in frame 1. Other than that we have the "am I ready to finally move on yet?". Most recently our loader just had a circle which continued rotating.
As a side note: wait until everything is completely ready if you're working with an AS3 loader. Loading half-cocked left me working until 3 AM on Easter one year. I was not happy.