How would I use addFrameCallback to speed up animation
I have:
this.shipWillLaunchFromStation = function()
{
if (this._radarTimer)
this._radarTimer.start()
else
this._radarTimer = new Timer(this, this._radarCheck, 0.25, 0.25)
this.$radar = 0;
}
this._radarCheck = function()
{
this.$radar += 1;
if(this.$radar == 25) {this.$radar = 0}
this.$Hudchart = ("P" + this.$radar + ".png");
player.ship.setCustomHUDDial("fhud1", this.$Hudchart);
}
but the animation is not smooth; I believe addFrameCallback would be better but cannot get the code to work - any suggestions?
addFrameCallback
Moderators: winston, another_commander
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: addFrameCallback
Code: Select all
this.shipWillLaunchFromStation = function() {
this._setupRadarCheck();
}
this.shipDied = this.shipWillDockWithStation = function() {
this._stopFCB();
}
this._stopFCB = function _stopFCB() {
if (isValidFrameCallback(this.$fcb)) stopFrameCallback(this.$fcb);
}
this._setupRadarCheck = function _setupRadarCheck() {
this.$fcb = addFrameCallback(function (delta) {
var w = worldScripts.MyWorldScriptName;
w.$radar += 1;
if(w.$radar == 25) {w.$radar = 0}
w.$Hudchart = ("P" + w.$radar + ".png");
player.ship.setCustomHUDDial("fhud1", w.$Hudchart);
});
}
You should also only do the setCustomHUDDial when required with this methodolgy. That is, if you're not going to increment $radar, then don't do the rest of the function.
Re: addFrameCallback
Thanks phkb, the code looks interesting - I'll give it a go