Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
    <title>Phaser Examples</title>
</head>
<body>
   <div id='phaser-example'>
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                var config = {
    width: 800,
    height: 600,
    renderer: Phaser.AUTO,
    parent: 'phaser-example',
    state: {
        create: create
    }
}
var game = new Phaser.Game(config);

function create() {
    let arc = _makeArc()
    let parentGroup = game.add.group()
    let childGroup = game.add.group(parentGroup)
    parentGroup.alpha = .2
    parentGroup.scale.set(.2)
    childGroup.addChild(arc)
    childGroup.cacheAsBitmap = true
    // HERE WE SET CACHE OF CHILD GROUP TO TRUE
    // THE PARENT'S TRANSFORM HASN'T BEEN APPLIED YET BECAUSE A RENDER HASN'T TAKEN PLACE
    console.log('cache set to true for child group')
    
    setTimeout(()=> {
      console.log(`updateCache of child group - worldAlpha is ${childGroup.worldAlpha} - worldScale is ${childGroup.worldScale}`)
      // HERE WE UPDATE THE CACHE OF THE CHILD GROUP WHICH APPLIES THE ALPHA OF IT'S PARENT GROUP (BAD)
      // IT DOES NOT APPLY THE SCALE OF THE PARENT GROUP (GOOD)
      childGroup.updateCache()
    }, 1000)
    
    setTimeout(()=> {
      console.log('set the parent group back to alpha 1 and scale 1')
      // HERE WE SET THE PARENT GROUP BACK TO ALPHA AND SCALE OF 1, PROVING THAT
      // PREVIOUS ALPHA OF THE PARENT GROUP HAS BEEN APPLIED TO THE CHILD GROUP'S CACHE
      // AND THE SCALE (CORRECTLY) HAS NOT
      parentGroup.visible = true
      parentGroup.alpha = 1
      parentGroup.scale.set(1)
    }, 2000)
}

function _makeArc() {
  var thickness = 44
  var radius = 150
  var w = (radius+thickness) * 2
  var bmd = game.add.bitmapData(w, w)    
  var c = bmd.ctx
  c.strokeStyle = '#ff0000'
  c.lineWidth = thickness
  c.lineCap = 'round'

  var percent = .8
  var angleOffset = 0
  c.beginPath()
  c.arc(radius + thickness, radius + thickness, radius, -angleOffset, -(angleOffset + (Phaser.Math.PI2 - angleOffset*2) * percent ), true)
  c.stroke()
  c.closePath()

  var img = game.make.image(200, 200, bmd)
  return img
}

              
            
!
999px

Console