Jump to content

Search the Community

Showing results for tags 'button destroy'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. What I am trying to achieve is an "initial buy" function for a unit. Basically, if the unit's buy flag is false, it show's the buy button. It's a one time button. If the unit's buy flag isn't false (aka, bought), it would delete the button and put something else in it's place. I tried to follow the example on the phaser site but it doesn't seem to want to work right. I've tried putting the destroy in it's own function, etc.. but no luck. Here is my gamestate.js - I'm looking specifically at the gameUnit1 function towards the bottom. Everything else in that function works as I want it to. var GameState = { create: function () { this.counter = 0; //styles this.headerStyle = {font: '30px Montserrat'}; this.HUDStyle = {font: '30px Montserrat'}; this.buttonStyle = {font: '15px Montserrat'}; //basic variables this.gold = 100; this.goldPerSecondBase = 1 //HUD text this.goldText = game.add.text(5, 5, "GOLD: " + this.gold, this.HUDStyle); this.goldText.anchor.setTo(0,0); this.goldPerSecondText = game.add.text(game.world.width-5, 5, "GPS: " + this.goldPerSecond, this.HUDStyle); this.goldPerSecondText.anchor.setTo(1,0); //gold button variables this.goldButtonValue = 200; //gold button this.goldButton = game.add.button(game.world.centerX, 120, 'goldCoin', function(){this.addGold(this.goldButtonValue)}, this); this.goldButton.anchor.setTo(0.5); this.goldButton.scale.setTo(0.4); this.goldButtonText = game.add.text(game.world.centerX, 175, "Click Value: " + this.goldButtonValue, this.HUDStyle); this.goldButtonText.anchor.setTo(0.5); this.goldButtonText.scale.setTo(0.4); //game unit 1 variables this.gameUnit1Name = 'Paladin Tank'; this.gameUnit1Bought = false; this.gameUnit1GoldPerSecond = 0; this.gameUnit1UpgradeLevel = 0; this.gameUnit1Button; }, //game unit 1 buttons gameUnit1: function() { if (this.gameUnit1Bought == false) { this.buyUnit1Button = game.add.button(100, 500, 'blankButton', function(){this.buyUnit1()}, this); if (this.gold <= 200) { this.buyUnit1Button.alpha = .1; } } else { this.buyUnit1Button.destroy(); this.unit1Text = game.add.text(12, 480, this.gameUnit1Name + ":", this.headerStyle); }; }, addGold: function(amount) { this.gold = (amount + this.gold); }, buyUnit1: function() { if (this.gameUnit1Bought == false) { if (this.gold >= 200){ this.gold = (this.gold - 200); this.gameUnit1Bought = true; this.gameUnit1GoldPerSecond = 1; this.gameUnit1UpgradeLevel = 1; }; }; }, calculateGoldPerSeond: function(fps) { this.goldPerSecond = ((this.goldPerSecondBase + (this.gameUnit1GoldPerSecond * this.gameUnit1UpgradeLevel))/fps); this.gold = (this.gold + this.goldPerSecond); }, update: function () { this.gameUnit1(); this.calculateGoldPerSeond(60); this.goldText.setText("Gold: " + ~~this.gold); this.goldPerSecondText.setText("GPS: " + ~~(this.goldPerSecond * 60)); } };
×
×
  • Create New...