onLoading method
Called repeatedly while game assets are loading.
Everytime an asset is loaded in the background onLoading
is called
instead of onUpdate/onRender
.
Bullseye provides a default implementation that shows a progress bar
but you can overwrite this method to provide your custom loader.
Once all loading is completed the app jumps back to onUpdate/onRender
again, when you return true
here. If you want to delay it or you want
to wait for user input, for example, return false as long as you want
to keep the loader active.
If you return true
but the loading is still in progress, your return
value is ignored.
If you want to disable the dispatching to onLoading
, you can deactivate
it, by setting isEnable
of loader
to false
:
loader.isEnabled = false
Implementation
//
/// Bullseye provides a default implementation that shows a progress bar
/// but you can overwrite this method to provide your custom loader.
///
/// Once all loading is completed the app jumps back to `onUpdate/onRender`
/// again, when you return `true`here. If you want to delay it or you want
/// to wait for user input, for example, return false as long as you want
/// to keep the loader active.
///
/// If you return `true` but the loading is still in progress, your return
/// value is ignored.
///
/// If you want to disable the dispatching to `onLoading`, you can deactivate
/// it, by setting `isEnable` of `loader` to `false`:
///
/// loader.isEnabled = false
///
bool onLoading() {
_loadCounter += 1;
_smoothFactor = min(12.0, _smoothFactor + 0.25);
gfx.setColor(0.1, 0.1, 0.2, 1);
gfx.clear();
double r = (width / 2.0) * 0.1;
double circleRadius = r * 0.13;
double x = width / 2.0;
double y = height / 2.0 - r / 2;
for (var i = 0; i < 360; i += 45) {
gfx.setColor(1, 1, 1, 0.5 + 0.5 * cosDegree(i - _loadCounter * 2));
double segmentX = x + sinDegree(i + _loadCounter) * r * 0.5;
double segmentY = y + cosDegree(i + _loadCounter) * r * 0.5;
gfx.drawCircle(segmentX, segmentY, circleRadius);
}
gfx.setColor(0.8, 0.8, 0.8, 0.75 + sinDegree(_loadCounter * 5) * 0.25);
y += 2 * r;
_loadingProgress = _loadingProgress + 0.001 + (loader.percent - _loadingProgress) / _smoothFactor;
_loadingProgress = min(loader.percent, _loadingProgress);
gfx.drawRect(40, y - 20, _loadingProgress * (width - 80), 12);
gfx.setColor();
if (_loadingProgress >= 1.0) {
_loadCounter = 0;
return true;
}
return false;
}