Graphics clear() works only when I put debbuger and open developer tool

Recommended Posts



I'm new to Phaser and that just got the problem with graphics object. What I want to do is display a bar of "energy" so that when I press the SPACEBAR keyboard the energy bar will be fulfilled until the key is released. In addition I want to tracking the previous charged energy so when the key was released I will fulfilled the energy bar with the graphic alpha is 0.5. Please look at below:


The tracking energy is clear that I don't know why, because I think I draw right after I clear all. This doesn't work until I try to put the debugger and open the developer tool (in Chrome). You can try yourself to see that.




var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { create: create, update: update });
    var spaceButton;
    var currentEnergy = 0;
    var MAX_ENERGY = 500;
    var chargingEnergyGraphic;
    var previousChargingEnergyGraphic;
    function create() {
        chargingEnergyGraphic =, 0);
        previousChargingEnergyGraphic =, 0);
        var graphics =, 0);
        graphics.lineStyle(2, 0xFF0000, 1);
        graphics.drawRect(50, 50, 500, 20);
        spaceButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
    function update() {
        if (spaceButton.isDown && currentEnergy <= MAX_ENERGY) {
            currentEnergy += 10;
            chargingEnergyGraphic.lineStyle(2, 0xFF0000, 1);
            chargingEnergyGraphic.drawRect(50, 50, currentEnergy, 20);
        if (spaceButton.justReleased()) {
    function trackPreviousEnergy() {
        previousChargingEnergyGraphic.alpha = 0.5;
        previousChargingEnergyGraphic.drawRect(50, 50, currentEnergy, 20);
        currentEnergy = 0;

Share this post

Link to post
Share on other sites

I was using Phaser 2.1.3 that justReleased is available. If you run the code on Phaser 2.1.3 you will get the same problem. Fortunately I've just upgraded to Phaser 2.2.1 and the problem does not exist



Share this post

Link to post
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.