2018-04-02 17:43:20 +00:00
|
|
|
function Scratch(){
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
self.dom = $("#scratch");
|
|
|
|
|
|
|
|
self.scratchIn = function(){
|
2018-04-20 18:47:58 +00:00
|
|
|
|
|
|
|
// SOUND!
|
|
|
|
SOUNDS.scratch_in.play();
|
|
|
|
|
|
|
|
// anim
|
2018-04-02 17:43:20 +00:00
|
|
|
self.startUpdateLoop(false, function(){
|
|
|
|
self.dom.style.display = "none";
|
|
|
|
});
|
2018-04-20 18:47:58 +00:00
|
|
|
|
2018-04-02 17:43:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
self.scratchOut = function(){
|
2018-04-20 18:47:58 +00:00
|
|
|
|
|
|
|
// SOUND!
|
|
|
|
SOUNDS.scratch_in.play();
|
|
|
|
|
|
|
|
// anim
|
2018-04-02 17:43:20 +00:00
|
|
|
self.dom.style.display = "block";
|
|
|
|
self.startUpdateLoop(true);
|
2018-04-20 18:47:58 +00:00
|
|
|
|
2018-04-02 17:43:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
self.startUpdateLoop = function(out, callback){
|
|
|
|
var frame = 0;
|
|
|
|
var xOffset = out ? 0 : -100;
|
|
|
|
var handle = subscribe("update", function(){
|
|
|
|
var yOffset = Math.floor(frame)*(-100);
|
|
|
|
self.dom.style.backgroundPosition = xOffset+"% "+yOffset+"%";
|
|
|
|
if(frame>19){
|
|
|
|
unsubscribe(handle);
|
|
|
|
if(callback) callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
frame+=0.5;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|