Liranan

Members
  • Content Count

    18
  • Joined

  • Last visited

About Liranan

  • Rank
    Member

Recent Profile Visitors

691 profile views
  1. Hi everyone. I'm trying to learn something about how to load database information in my phaser games. Currently, I want to load some questions for a quizz game from a SQL database. I've searched online and I found a method that works but I don't know if it's the best option. Making a XMLHttpRequest I can load a PHP file in which I load the db info and then parse it into a JSON. As I said, it works, but then I don't know how to send the results back to the game, since is an asynchronous proccess. Let me explain myself with the code: Quizz.Game.prototype = { create: function(){ this.getQuestion(); }, getQuestion: function(){ var request = new XMLHttpRequest(); request.open('POST', 'getQuestion.php', true); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); request.onload = function(){ if(request.status >= 200 && request.status < 400){ //Correct var result = JSON.parse(request.responseText); this.sendQuestion(result); } else{ //Error } } request.send(); }, sendQuestion: function(){ //The next code } }; In this example I tried to load the question and then print it on screen or something, but I get the error 'this.sendQuestion()' is not a function, seems like the context is no longer 'this'... I guess my question is if you have some procedure you usually use for do this, or if there's a better way of doing it. Thank you for sharing! Gonzalo.
  2. Ok, I got it, I expected this so... no big problem. Thank you for your answers and your wisdom.
  3. Hello friends. I've a security question. I've done two mini-games for my company. I really enjoyed the chance of using Phaser in my work and not for fun, as I usally do. My boss liked it too, so good news. But he is concern because everybody are able to see the code with the elements inspector. My question is if there's some easy way to hide or protect the code from visitors, in order to avoid that our competititors steal the code for their own pages. Any advice? Thanks a lot!
  4. Amazing Game! Greaper you did a fantastic work on here. At first sight it looks like the classic idea too complicated to work well, but when you start playing you realize it's not. Its original, well-done and fun to play. Congratulations. In the other hand, I found an error. if you click too fast in several tiles, the monster appears but it doesn't die. This happens if you click in a square with a monster inside before the previous animation ended. I had all the 4-level monsters at the end of the game, and when I was sure, I clicked on all pretty fast. Some of the monsters didn't die and the game didn't end, even when there were no more 'rocks' to destroy. Either way, good job! Gonzalo.
  5. Really interesting game Skeptron. I specially like the graphics and animations. Great work! Maybe you should tell the commands somewhere before the game starts (I speak for the desktop version) I found the first robot with 3 stars unbeatable hehe. Congrats!
  6. Thank you for your answers. Tom Atom, you're absolutely right, I was being inaccurate while naming my variables. I should call 'state' to the variable I received in the constructor. I already fixed that. I tried passing to parameters (this as the state and this.game as the game) but for some reason it didn't work. Str1ngS, you give me the solution. I change the context in the Phaser.Sprite.call function, from 'state' to 'state.game'. By doing this, I can use the variable from the state function and I can also add the animations. Anyway, you're probably right about the static variable. The final code looks like this, in case somebody has the same doubt in the future: 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); } } } }; Tile = function(state, column, row){ var posX = state.tileSize * column; var posY = state.tileSize * row; Phaser.Sprite.call(this, state.game, posX, posY, "tile"); this.state = state; this.animations.add('shine', [0, 1, 2, 3], 4, true); this.animations.play('shine'); }; Tile.prototype = Object.create(Phaser.Sprite.prototype); Tile.prototype.constructor = Tile;
  7. Hello Rich, I've recently finished the Interphase book.

    I found it really interesting and helpful and I've noted you called it 'chapter 1'. I guess my question is, are there any news about the chapter 2?

    I can't wait to learn more from you, in a comprehensible and clear language.

    Thank You.

    Gonzalo.

  8. 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.
  9. Thank you a lot Rick, it worked pretty good. I'm keeping my system for some things because I need to re-order some of the element's depth, but the 'addChild' function will help me with some minor elements. One of the (many) good things Phaser have is you can have an answer from the guy who do the code. Thanks!
  10. Hello everyone, I have this doubt (little introduction before): I think is really helpful to use a sprite property to "store" another sprite. For example, when I have several enemies and I want all of them to have a health bar I can do something like this: var enemies = game.add.group(); for(var i = 0; i < 5; i++){ var enemy = game.add.sprite(0, 0, "enemy", 0); var health = game.add.sprite(enemy.x, enemy.y, "bar", 0); enemy.health = health; enemies.add(enemy); } By doing this, I can easily locate the health bar in the game later. For example if I want to change the bar's frame I only have to: enemies[i].health.frame = 1; I can do this several times, for example if I want to add a magic bar to the enemies, a text with the name, etc. The problem is, when I want to move the enemy sprite. At this moment, I create a tween for the 'main' sprite, and another tween for each of the properties: game.add.tween(enemies[i]).to({...}); game.add.tween(enemies[i].health).to({...}); game.add.tween(enemies[i].magic).to({...}); This is ok when you have just one property for each sprite, but when the numbers go up, it starts to look... problematic. Specially when each enemy have different properties. I was wondering if there's a way to move a sprite and 'all the sprites that belongs to them' at the same time with a single tween. Thank you! Gonzalo.
  11. That's it! It works perfectly! Thank you very much Gob0!
  12. Mmm, it sounds good but I had the same answer for 'mainState.myFunction()' Uncaught TypeError: mainState.myFunction is not a function If I move the listener and the function out of the prototype it works, but it's useless to me because I've to refer the elements inside the prototype
  13. Hello Gob0 and thanks for your answer. I'm sure the problem is about the reference "this" but I use it in all the functions of the game and it always works but this time, I assume for being inside the document listener. I've tried with 'myClass' but it doesn't work either. This is an example of how the code is set if it helps: var mainState = function(){}; mainState.prototype = {create: function(){game.input.onUp.add(this.test, this); //this worksdocument.addEventListener('mouseout', function(){ this.test(); }); //this doesn't work},update: function(){ },test: function(){console.log("test correct");}}; I've also tried this solution update: function(){game.input.mouse.mouseOutCallback = this.test();} But it acts like the mouse always was outside the screen. If I launch the game, the console writes endless texts no matter if the mouse is on the screen or out I've also tried checking in the update function if the mouse coordinates were in or out the screen. At last, it was the method that worked better, but still sometimes miss the movement.
  14. Thanks for the answer drhayes I've tried doing this: document.addEventListener('mouseout', function(){ this.myFunction(); }); But didn't work. It said "myFunction" didn't exists (and it did). I'm guessing you can't launch a phaser game function inside a DOM listener
  15. Hello everyone, here's my issue. In the game you make lines in a tilemap by click (input.onDown) and moving the cursor over them. When you release the cursor (input.onUp) the lines disapear. The problem is: when I move the cursor out the screen, it doesn't detect the event as input.onUp, and I can release the button, come back to the screen and select a new line without destroying the previous one. What I want to know is: is there some way to launch a function when the cursor (in web or mobile) leaves the screen? I've tried some methods, but none of them worked. Thanks!