Jump to content

set visible=true no use in Phaser


ZHOUDAHAO
 Share

Recommended Posts

I'm making a game similar to the traditional magic tower,and now I have a problem when dealing with the battles between the monster and the braver. here's my code in update():

function update(){ ... game.physics.arcade.collide(braver, monsters, battle, null, this); ... }

and here's my battle():

function battle(player, monster) {
    var x = (player.attack > monster.defence ? player.attack - monster.defence : 0);
    var y = (monster.attack > player.defence ? monster.attack - player.defence : 0);
    battleScene.visible = true;
    while (1) {
        if (Date.now() > battleTimer) 
        {
            battleTimer = Date.now() + 1000;
            monster.health -= x;
            if (monster.health <= 0) {
                monster.kill();
                player.gold += monster.gold;
                player.exp += monster.exp;
                break;
            }
            player.health -= y;
            if (player.health <= 0) {
                player.kill();
                break;
            }
        }
    }
    battleScene.visible = false;
}

battleScene is a group,the battle box,What makes me crazy is that battleScene doesn't show on the screen at all(even with battleScene.visible = true),I've tried game.world.bringToTop(battleScene); but it doesn't work,too.So how can I fix that bug?

Link to comment
Share on other sites

You have no draw calls between making it visible and hiding it again...

You show the battleGroup, then you sit there and process the battle, then you hide it, then exit the function and continue regular program processing... All in one update call...

You need to make it visible, then run several loops of the program to process the battle scene, then hide it once the battle is over...
You will need to rethink using the while loop in there...
 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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