• Content Count

  • Joined

  • Last visited

About diegoalmesp

  • Rank

Contact Methods

  • Twitter
  1. Hello guys! I'm having a big, big bug and I cannot see if it's just my code or a phaser attribute that I'm missing (I'm sure is my code hehe). This is a tic tac toe game, with a multiplayer mode. So you can send your movement to the other player and he can watch the new piece being added in real time. And also, after there are 6 pieces in the board, both players can drag them to keep playing (turn based of course). My problem is: player 1 starts, and only he can see the piece being dragged over the board (I mean: you move the piece in the mouse and the piece is visibly being moved to the new place, I'm talking about the animation itself) But that doesn't happen with player two, he wont see the image being moved event when the drag actually works (cause the values show me that the piece was moved to the new position and this move is emitted to player one, which can see the piece in the new position). So, my question: which part of the framework allows you to see the piece being moved to another place (dragged with the mouse) and how can you activate or deactivate that with phaser (I guess I have deactivated this somehow when player 2 plays). To explain myself better and my problem, let's see this example: http://phaser.io/examples/v2/input/drag now we assume that when I click and drag that image (the keyboard) I cannot see it being moved, but if I release the mouse button somewhere else, it will appear in the new place. If you need to see my code please ask, though is pretty long and messy (I didn't started this game, and is my first with Phaser) and I'm not sure that you need it to help me with this, but if you do, please let me know. Thanks in advance! Edit1: I created a bitbucket repo with the portion of the game: https://bitbucket.org/diegodigital/tictactoe-multiplayer/src
  2. Thanks for answer! I'm using yeo-man generator and node to work with modules and compile them into one single file. Thanks! that seems to be my problem! One more thing. As you can see on the second file I posted (PlayerVsCpuGame) I was adding stuff with 'this', and I need to access that in the third module (cpu_play_hard.js), should I add those functions to 'this.game' instead? would that be a right approach?. And yes, the idea is in the future to add a multiplayer instance, scores, etc so I need this to be as much "ordered" as posible. Thanks guys!!!
  3. Hello guys! I'm having some "problem" (not really, more a doubt). Working with Node js (firstime) I'am organizing an already made game. My problem is to acces the "game object" outside the modules. So, how would you make the game object (var game = new Phaser.Game(SCREENWIDTH, SCREENHEIGHT, Phaser.CANVAS, 'game') available to all the sub-modules in the app?. I'm sending the game as a parameter but I don't think this is a good approach. This is what I have now: main.js: 'use strict';// var PlayScene = require('./play_scene.js');var GlobalVariables = require('./main_variables.js');var MenuScene = require('./modules/menu/menu.js');var PlayerVsCpuGame = require('./modules/pvscpu/player_vs_cpu_game.js');var BootScene = { ...};var PreloaderScene = { ...};window.onload = function () { var SCREENWIDTH = window.innerWidth; var SCREENHEIGHT = window.innerHeight; var game = new Phaser.Game(SCREENWIDTH, SCREENHEIGHT, Phaser.CANVAS, 'game'); // var game = new Phaser.Game(800, 600, Phaser.AUTO, 'game'); game.state.add('globalv', GlobalVariables); game.state.add('boot', BootScene); game.state.add('preloader', PreloaderScene); game.state.add('PVsCPUGame', PlayerVsCpuGame); // game.state.add('play', PlayScene); // Main Menu For the Game game.state.add('menu', MenuScene); game.state.start('boot');};Then the PlayerVsCpuGame (where I can access the game object easily): var CpuPlayHardMod = require('./libraries/cpu_play_hard.js');var PVsCPUGame = { handleResize: function(){ var w = window.innerWidth; var h = window.innerHeight; this.game.width = w; this.game.height = h; var ratio = 1600/900; var windowRatio = w/h; RATIO = w/1600; if (windowRatio > TaTeTi._RATIO) { TaTeTi._RATIO = h/900; } }, this.handleResize(); this.physics.startSystem(Phaser.Physics.ARCADE); this.preloadBG = this.add.sprite(0,0,'generalBG'); this.preloadBG.width = TaTeTi._WIDTH; this.preloadBG.height = TaTeTi._HEIGHT; this.board = this.add.sprite(TaTeTi._WIDTH/2+TaTeTi._RATIO*30,TaTeTi._HEIGHT/2,'board'); this.board.anchor.set(0.5,0.5); this.board.scale.setTo(TaTeTi._RATIO*0.35,TaTeTi._RATIO*0.35); this.board.name = 'THE BOARD'; TaTeTi._GAMESTARTED = true; this.HitZoneGroup = this.add.group(); // the group for player pieces this.playerPieces = this.add.group(); // the group for cpu pieces this.cpuPieces = this.add.group();.... As you can see on top of that file, I'm calling a new module, and here is where I'm having the problem: // Hard Level CPUvar cpuPlayHard = function (game){ // if the game has ended then I'll skip this function if(TaTeTi._GAMESTARTED === false) return; // if all the pieces are on the board, then it will use the // randomCpuKeepPlaying() function which moves the CPU pieces to // keep playing if(TaTeTi._COUNT > 5 ) { return false; } self = this; ...because I need to call cpuPieces which is in the "parent module", and other methods as well. For now I'm passing the "game" object as a paremeter, but I intend to use more libraries like this one, and as I'm very new to node, I'm not sure how to do this in a right and clean way. Hope you guys can help me with this. Thanks in advance! Diego.
  4. thanks substandardgaussian ! I tried that but I get the same error. Maybe is the way I'm assigning physics to the sprites?, this is the code in the create function: create: function() { this.handleResize(); // some custom function this.physics.startSystem(Phaser.Physics.ARCADE); this.preloadBG = this.add.sprite(0,0,'generalBG'); this.preloadBG.width = TaTeTi._WIDTH; this.preloadBG.height = TaTeTi._HEIGHT; this.board = this.add.sprite(TaTeTi._WIDTH/2+TaTeTi._RATIO*30,TaTeTi._HEIGHT/2,'board'); this.board.anchor.set(0.5,0.5); this.board.scale.setTo(TaTeTi._RATIO*0.35,TaTeTi._RATIO*0.35); this.board.name = 'THE BOARD'; this.HitZoneGroup = this.add.group(); this.playerPieces = this.add.group(); this.initPlaces(); for(var i = 0; i < this._COORDINATES.length; i++){ this.square = this.add.sprite(0,0,'square'); this.square.anchor.set(0.5,0.5); this.square.alpha = 0; this.square.x = this._COORDINATES[i]._x1; this.square.y = this._COORDINATES[i]._y1; this.square.name = this._COORDINATES[i]._ID; this.square.inputEnabled = true; this.square.scale.setTo(TaTeTi._RATIO*0.4,TaTeTi._RATIO*0.4); this.square.events.onInputDown.add(this.onDown,this); this.HitZoneGroup.add(this.square); } this.physics.enable(this.HitZoneGroup, Phaser.Physics.ARCADE); this.physics.enable(this.playerPieces, Phaser.Physics.ARCADE);},because the line in question (on phaser.js) is: enableBody: function (object) { if (object.hasOwnProperty('body') && object.body === null) <--- this one { object.body = new Phaser.Physics.Arcade.Body(object); }},Many thanks for your help!!
  5. I'm having that error too, I have no idea what is going on. This happends when I restart the game. I have a restart function in which, after the user clicks on a "restart" button, I reset all the variables (inside an object) and start the game with this.game.state.start("Game"); The full error is: Uncaught TypeError: Cannot read property 'hasOwnProperty' of undefined c.Physics.Arcade.enableBody @ phaser.js:62117 c.Physics.Arcade.enable @ phaser.js:62097 TaTeTi.Game.dragGame @ Game.js:311 TaTeTi.Game.controlPlace @ Game.js:294 TaTeTi.Game.onDown @ Game.js:231 c.SignalBinding.execute @ phaser.js:19057 c.Signal.dispatch @ phaser.js:18880 c.Events.hasOwnProperty.e.indexOf.c.Events.(anonymous function).c.Events.(anonymous function) @ phaser.js:35189 c.InputHandler._touchedHandler @ phaser.js:30876 c.Pointer.start @ phaser.js:29001 c.Mouse.onMouseDown @ phaser.js:28020 c.Mouse.start._onMouseDown @ phaser.js:27936The dragGame function: dragGame: function(){ for(var i = 0; i < Piece.length; i++){ if(Piece[i]._IS_PLAYER){ this.physics.arcade.enable(this.playerPieces.children[i]); this.playerPieces.children[i].name = Piece[i]._NAME; this.playerPieces.children[i].place = Piece[i]._CURRENT_POS; this.playerPieces.children[i].inputEnabled = true; this.playerPieces.children[i].events.onInputDown.add(this.onDownForDrag,this); }else if(this.playerPieces.children[i].key == 'square'){ this.playerPieces.children[i].inputEnabled = false; } }},controlPlace function: controlPlace: function(square){ if(TaTeTi._ALLPIECESINPLACE){ this.dragGame(square); }else{ var name = square.name; var posX = square.x; var posY = square.y; if(!this._COORDINATES[name]._TAKEN){ this.drawPiece(posX,posY,name); this._COORDINATES[name]._TAKEN = true; }else{ console.log('OCUPIED!!'); } }},and onDown: onDown: function(theSquare,pointer){ this.controlPlace(theSquare); this.playerPieces.add(theSquare);},Hope you can help me, thanks guys!! Edit: btw! phaser version is 2.3.0
  6. Thanks man!! I was looking for something like this, the initial setup is great and clean. Good job!