Jump to content

RadialGradient for BitmapData fillstyle


Recommended Posts

Hey, I'm having from trouble with the BitmapData module. When I assign a radial gradient to Phaser.BitmapData.ctx.fillstyle, nothing I draw renders to the screen. The code below in in the 'create' function.

var gradient = bitmap.ctx.createRadialGradient(x,y,0,x,y,radius);gradient.addColorStop(0.5,"white");gradient.addColorStop(0.4,color);gradient.addColorStop(1,"black");bitmap.ctx.fillStyle = gradient;bitmap.circle(bitmap.width/2,bitmap.height/2,10);

I know my other code is working because when I make the fillStyle = '#FFFFFF', I get a white ball. Does the BitmapData module allow me to set radial gradients as the fillStyle? It is my understanding that anything I can do on a canvas I can do with BitmapData. Or is there something I'm overlooking? I need help! Please and Thank You.

Link to comment
Share on other sites

Can't really tell without seeing all of your code, but it looks fine to me so long as the values are correct. Here's a complete working example of my own:

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { create: create, update: update });var bmd;var innerCircle;var outerCircle;function create() {    //  Our BitmapData (same size as our canvas)    bmd = game.make.bitmapData(800, 600);    //  Add it to the world or we can't see it    bmd.addToWorld();    //  Create the Circles    innerCircle = new Phaser.Circle(200, 200, 100);    outerCircle = new Phaser.Circle(200, 200, 300);    game.add.tween(innerCircle).to( { x: 100, y: 100, radius: 1 }, 3000, "Sine.easeInOut", true, 0, -1, true);}function update() {    var grd = bmd.context.createRadialGradient(innerCircle.x, innerCircle.y, innerCircle.radius, outerCircle.x, outerCircle.y, outerCircle.radius);    grd.addColorStop(0, '#8ED6FF');    grd.addColorStop(1, '#003BA2');    bmd.cls();    bmd.circle(outerCircle.x, outerCircle.y, outerCircle.radius, grd);}

Note: Coded for Phaser 2.2, but if you just change the tween from "Sine" to something like Phaser.Easing.Exponential.InOut it'll work fine in 2.1.3.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...