Search the Community

Showing results for tags 'variable'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 6 results

  1. Hey guys, I have a quick question about 'Groups' as I'm kinda new to this Phaser HTML5 game dev. So my plan is to create multiple groups and have control over each one of them. First thing that came into my mind is to create a 'for loop' and be done with! Problem is that I don't know how to assign different names for a variable (wave).Example: Instead of doing this: this.wave00 = game.add.group(); this.wave00.enableBody = true; this.wave00.physicsBodyType = Phaser.Physics.ARCADE; this.wave01 = game.add.group(); this.wave01.enableBody = true; this.wave01.physicsBodyType = Phaser.Physics.ARCADE; this.wave02 = game.add.group(); this.wave02.enableBody = true; this.wave02.physicsBodyType = Phaser.Physics.ARCADE; I am trying to do this: for(i=0; i<10; i++){ this.['wave'+i] = game.add.group(); this.['wave'+i].enableBody = true; this.['wave'+i].physicsBodyType = Phaser.Physics.ARCADE; } So I'm sure you got the idea but this (['wave'+i]) is the problem. Can someone help me with this? What is the correct way of writing it? I've been searching but maybe I'm not questioning this correctly. Thanks and sorry for the noob question!
  2. hi, i'm searching to modify a variable with dat gui. Dat.gui appears on my screen and i have no error. The option "speed" appears also and i can modify the value but that do noting on my object. in fact i must access to this.weapon.fire() to update the result but i can't acess to it. What's the true syntax to access this function ? thanks for your help. _weapon = function(delay,posx,posy,speed,frequency,variance,angular,_flag,kill_with_world,special_color){ this.special_color=special_color this.kill_with_world=kill_with_world this.delay=delay this.posx=posx this.posy=posy this.flag_explode=false this.speed=speed this.angular=angular this.frequency=frequency this._flag=_flag this.variance=variance this.sound_pop=game.add.audio('pop') this._flag=true //canon Phaser.Sprite.call(this,game,this.posx,this.posy,'canon') this.anchor.setTo(.5,.5) this.angle=this.angular this.inputEnabled=true this.input.enableDrag(true) this.events.onDragStop.add(logic_position,this) this.events.onDragStart.add(show_grid_on_logic_position,this) this.input.enableSnap(40,40,true,true) game.physics.arcade.enable(this); if(this.special_color=="vrai"){ this.weapon=game.add.weapon(9,'bullet_color') }else{ this.weapon=game.add.weapon(9,'bullet') } if(this.kill_with_world=="faux"){ for (var i = 0; i < 9; i++) { this.weapon.bulletCollideWorldBounds=true this.weapon.bullets.children[i].body.bounce.setTo(1,1) } }else{ this.weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; } // Because our bullet is drawn facing up, we need to offset its rotation: this.weapon.bulletAngleOffset = 0; // The speed at which the bullet is fired this.weapon.bulletSpeed = this.speed; // Speed-up the rate of fire, allowing them to shoot 1 bullet every 60ms this.weapon.fireRate = this.frequency ; // Add a variance to the bullet angle by +- this value this.weapon.bulletAngleVariance = this.variance; // Tell the Weapon to track the 'player' Sprite, offset by 14px horizontally, 0 vertically this.weapon.trackSprite(this,0,0,true); game.time.events.add( this.delay,function(){this._flag=false},this ) } _weapon.prototype = Object.create(Phaser.Sprite.prototype) _weapon.prototype.constructor = _weapon _weapon.prototype.update = function(){ if(this._flag==false){ this.weapon.fire() } } //in state Level1// //var gui //var canon=[] canon[0]=new _weapon(800,200,800,900,2990,0,180,hero.flag_level_complete,"vrai","faux") gui=new dat.GUI() gui.add(canon[0],'fire') gui.add(canon[0],'speed',0,50) //
  3. Hello ! I really want to read the source code of phaser, but I am not that professional. the namespace Phaser is declared inside a function, so I am wondering how we can access it outside it ? (function(){ var Phaser = Phaser || {}; }).call(this); Phaser.something = 5; //Reference error, Phaser is not declared what things I ca learn to read the source code perfectly and have this awesome experience ?
  4. Hi, I want to get from database position of sprite and i am doing it with AJAX. In main file: var playerx = 0; var playery = 0; function start(){ $(document).ready(function(){ $.ajax({ type:"GET", /*Informacja o tym, że dane będą pobierane*/ url:"start.php", /*Informacja, o tym jaki plik będzie przy tym wykorzystywany*/ contentType:"application/json; charset=utf-8", /*Informacja o formacie transferu danych*/ dataType:'json', /*Informacja o formacie transferu danych*/ /*Działania wykonywane w przypadku sukcesu*/ success: function(json) { /*Funkcja zawiera parametr*/ /*Pętla typu for...in języka Javascript na danych w formacie JSON*/ for (var klucz in json) { var wiersz = json[klucz]; /*Kolejne przebiegi pętli wstawiają nowy klucz*/ var mapastart = wiersz[2]; playerx = wiersz[3]; playery = wiersz[4]; /*Ustalenie sposobu wyświetlania pobranych danych w bloku div*/ $("<span> mapastart: "+mapastart+"</span>") .appendTo('#wykaz') .append("<hr>") } TopDownGame.level = mapastart; console.log(playery); console.log(playerx); }, /*Działania wykonywane w przypadku błędu*/ error: function(blad) { alert( "Wystąpił błąd"); console.log(blad); /*Funkcja wyświetlająca informacje o ewentualnym błędzie w konsoli przeglądarki*/ } });}); }; An that i am adding sprite to the game: this.player = this.game.add.sprite(playerx, playery, 'player', 5);And in console after start i have that position what i have in database, but it looks like a words, and my sprite doesnt add to the game. Any idea what i can do with it? I will be gratefull.
  5. Hello, is there any way to create a shader code(v&f) that comes from an ajax request like stored in a variable ?? regards
  6. Hi, I'm trying to create a small javascript app which loads a JSON url and displays some html and divs based on the JSON data. It's got to be as small as possible so without using a frameworks like Phaser and jQuery. The javascript scope of variables is a bit tricky, and I'm having some trouble getting it to work properly. My question is, how can create the MyGame class with an imageShapes image and then reference that imageShapes in the onreadystatechange method of XMLHttpRequest? Here is my code:// namespacevar MyGame = MyGame || { gamedata: [], test123: 'This is a test value 123'};// game objectMyGame.start = function (jsonfilename) { // initialise image this.imageShapes = new Image(); // add gamedata and populate by loading json this.gamedata = []; this.test123 = 'This is a test value 123'; this.loadJSON( jsonfilename, this.onJSONsuccess, // <- function to call on successfully loaded JSON this.onJSONerror );}MyGame.start.prototype = { // load a JSON file loadJSON: function(path, success, error) { console.log('TESTING loadJSON : test123='+this.imageBackground); var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) { if ((xhr.status === 200) || (xhr.status === 0)) { // status 0 = local file testing if (success) success(JSON.parse(xhr.responseText)); // <- how to reference back to "MyGame" ? } else { if (error) error(xhr); } } }; xhr.open("GET", path, true); xhr.send(); }, // handle load json events onJSONerror: function(xhr) { console.log('MyGame.js - onJSONerror error loading json file'); console.error(xhr); }, onJSONsuccess: function(data) { // load data from JSON this.gamedata = data; console.log('TESTING -- data.imgshapes='+data.imgshapes+' test123='+MyGame.test123+' imageShapes='+this.imageShapes); // this.imageShapes is also undefined MyGame.imageShapes.src = 'img/mybackground.png'; // <- problem is here, imageShapes is undefined..? }};var test = new MyGame.start('js/mydatafile.json');When I try the code above, it fails in onJSONsuccess. The imageShapes cannot reference and it is undefined, even though I defined it earlier in the MyGame class. This is the error: Uncaught TypeError: Cannot set property 'src' of undefined test123.js:58