lifesuxtr Posted April 8, 2018 Share Posted April 8, 2018 There is a problem with game.state.add() function.For some reason game is undefined. Uncaught TypeError: Cannot read property 'add' of undefined at Object.init (main.js:51) at main.js:58 var socket; // global bir socket değişkeni. socket = io.connect(); // server a bağlantı isteği gönderir. //Server bağlantı isteğini dinler ve clientlara başarılı olursa geri "connect" mesajını emitler. //Oyunun ekrana oturması için boyutları ayarlıyoruz.Browserla ilgili. var canvas_width = window.innerWidth * window.devicePixelRatio; var canvas_height = window.innerHeight * window.devicePixelRatio; //Oyunumuzu belirlediğimiz divin içinde yaratıyoruz. var game = new Phaser.Game(canvas_width,canvas_height,Phaser.CANVAS,'gameDiv'); var gameProperties = { //oyunun gerçek boyutları.oyun dünyasının genişliği ve uzunluğu. gameWidth:4000, gameHeight:4000, } //Oyunun ana state i. var main = function(game){ }; main.prototype ={ preload:function(){ }, create:function(){ // oyun yaratıldığında çağrılır. console.log("Client yaratıldı.") //serverdan connect mesajı gelince onSocketConnected fonksiyonunu çalıştır. socket.on("connect",onSocketConnected); //serverdan gelecek connect mesajı için dinler.Socket.io bir client // servera bağlandığında otomatik olarak connect mesajını client a gönderir. //serverın clientlara mesaj göndermesine "emit" denir. }, } function onSocketConnected(){ console.log("Sunucuya bağlanıldı.") }; var gameBootStrapper = { init:function(gameContainerId){ game.state.add('main',main); //error here game.state.start('main'); } }; gameBootStrapper.init('gameDiv'); My index.html: <body> <div id="gameDiv"> </div> </body> <script src="client/lib/phaser.js"></script> <script src="/socket.io/socket.io.js"></script> <script src ="client/main.js"></script> Here there is a picture of index.html: https://i.stack.imgur.com/N6jU3.png if i console.log(game) everything looks ok http://prntscr.com/j2jzty Link to comment Share on other sites More sharing options...
rich Posted April 8, 2018 Share Posted April 8, 2018 The problem is you’re using code written for Phaser 2. It will not work at all in Phaser 3. Either swap to using Phaser CE or recode it into v3 code. Link to comment Share on other sites More sharing options...
Linzeestomp Posted May 28, 2018 Share Posted May 28, 2018 is the state/add methods no longer available in Phaser 3? ? Link to comment Share on other sites More sharing options...
prob Posted May 29, 2018 Share Posted May 29, 2018 21 hours ago, Linzeestomp said: is the state/add methods no longer available in Phaser 3? ? No, States are now Scenes: https://labs.phaser.io/index.html?dir=scenes/&q= Link to comment Share on other sites More sharing options...
Recommended Posts