Created
June 4, 2014 18:22
-
-
Save jdeagle/d625a0a3ef215ba7ef51 to your computer and use it in GitHub Desktop.
draw a circle loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createPie : function (game, w, h) { | |
console.log("create pie", w, h, this); | |
var mask = game.add.bitmapData(w, w), | |
bmd = game.add.bitmapData(w, w), | |
canvas = bmd.canvas, | |
context = bmd.ctx, | |
size = 270, | |
degreesToRadians = function (degrees) { | |
return (degrees * Math.PI) / 180; | |
}; | |
var drawPie = function () { | |
bmd.clear(); | |
context.save(); | |
var centerX = Math.floor(w / 2); | |
var centerY = Math.floor(w / 2); | |
var radius = Math.floor(w / 2); | |
var startingAngle = degreesToRadians(270); | |
var arcSize = degreesToRadians(size); | |
var endingAngle = startingAngle + arcSize; | |
context.beginPath(); | |
context.moveTo(centerX, centerY); | |
context.arc(centerX, centerY, radius, startingAngle, endingAngle, false); | |
context.closePath(); | |
context.fillStyle = 'rgba(0, 0, 0, 1)'; | |
context.fill(); | |
context.restore(); | |
bmd.render(); | |
}; | |
drawPie(); | |
game.cache.addBitmapData("loaderMaskBMD", bmd); | |
var maskImage = game.add.image(348, 221, bmd); | |
console.log("maskImage", maskImage); | |
// doesn't work | |
//game.cache.addImage("loaderMaskImage", maskImage); | |
game.load.onFileComplete.add(function (progress) { | |
console.log("load", progress); | |
size = (360 / 100) * progress; | |
drawPie(); | |
}); | |
// doesn't work | |
//mask.alphaMask('preloaderRingLoaded', maskImage); | |
// doesn't work | |
//mask.alphaMask('preloaderRingLoaded', game.cache.getBitmapData("loaderMaskBMD")); | |
// doesn't work | |
//mask.alphaMask('preloaderRingLoaded', game.cache.getImage("loaderMaskImage")); | |
var sp = game.add.sprite(348, 221, mask); | |
sp.width = w; | |
sp.height = h; | |
console.log("sp", sp); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment