Jump to content

Search the Community

Showing results for tags 'passing variables'.

  • 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. Hello everyone. I'm learning about extending classes so excuse me if I'm asking a silly question. What I want is to get a variable from the state and use it in the extending class constructor and functions. The state looks similar to this MyGame.Game = function(){ this.tileSize = 80; }; MyGame.Game.prototype = { create: function(){ for(var i = 0; i < 8; i++){ for(var j = 0; j < 8; j++){ var tile = new Tile(this, i, j); this.add.existing(tile); } } } }; Then, I've a extended class like this: Tile = function(game, column, row){ var posX = game.tileSize * column; var posY = -game.tileSize + (game.tileSize * row); Phaser.Sprite.call(this, game, posX, posY, "tile"); this.game = game; }; Tile.prototype = Object.create(Phaser.Sprite.prototype); Tile.prototype.constructor = Tile; It works fine, it creates the tilegrid and I'm able to use the "tileSize" value I've defined in the state function. The problem happens when I try to add some animations to the tile class. If I add the "this.animations.add('shine'...)" command in the constructor, I get an error (this.animations is not defined) I've searched in the forum and I've found a solution, instead of "var tile = new Tile(this, i, j)" I should use "var tile = new Tile(this.game, i, j)" That's correct, if I do that, I can add the animations, but then I cannot use the state variable "tileSize". Is there a way to do both things at the same time? Thanks a lot. Liranan.
×
×
  • Create New...