Search the Community

Showing results for tags 'state'.



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 73 results

  1. I get this error when restarting Game state. This line causing the error: this.player.healthbar = new HealthBar(this, {x:this.player.x, y:this.player.y-25, height:5, width:50}); It's all fine if i call world.removeAll in the state.shutdown function. shutdown: function(){ this.world.removeAll(); } Why am i have to call world.removeAll after switching states? Shouldn't it clear the game world itself when game.state.start is called? Docs says "but not the Stage, so if you've added your own objects to the Stage they will need managing directly" Is healthbar added to the Stage? If so, What is the stage? I'm using phaser.healthbar plugin to create health bars.
  2. Being rather new to Phaser I have run into a problem that have halted my progressed. The code in question is as following. //Gun this.weapon = game.add.weapon (20, 'missile'); this.weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; this.weapon.bulletAngleOffset = 0; this.weapon.fireAngle = 0; this.weapon.bulletSpeed = 400; this.weapon.fireRate = 100; this.weapon.trackSprite(sprite, 90,52) And it gives me the following error TypeError: Phaser.Weapon is undefined In my test project I have the exact same piece of code, the only difference is that my current project uses game states and the previous is contain in a single .js file Anyone had a similar error and/or have a solution? I have added the project as a .rar file in case that helps Heli-cop hero opgave_2.rar
  3. I'm doing a round based game. So after you've killed so many enemies it'll pop up, "Round 1", after some more, "Round 2" and so on. The amount of enemies doesn't change it's just the round that increases after you've killed say 20 enemies. I have a current variable at the top of my game.js file var currRound = 1; var EnemiesKilled = 0; Every time I kill an enemy I increment up the variable then in one of the collision handlers I do if EnemiesKilled == 20 then show some text newLevel.setText("Woo!! Round " + currRound + "!"); and restart the round via setTimeout(function() { game.state.start(game.state.current); }, 1000); The thing is, it whipes the variable of EnemiesKilled. How can I keep that variable so I always know how many enemies the player has killed?
  4. Does anyone know how to unload and destroy audio files appropriately? I have about 12 MB of audio in my game, or about 15 minutes. I do not load all of them at one time, since this will break any mobile browser. So I load them in the states they are needed. About 4 MB is loaded at the same time. According to the Task Manager in chrome, the memory used by my game just keeps growing and growing, easily above 1000MB by changing states. (Browsers decode audio to lossless => memory use is high, regardless of file format and encoding.) In all states I have a shutdown function that destroys all the sounds and purges audio loaded in the cache. This is my current code (very similar to how cache is cleared when changing states, but I have some assets I use everywhere and don't want to remove): function clearCache () { // Purge sound. var key = this.sound._sounds.length; while (key--) { this.sound._sounds[key].destroy(true); } // Destroy "everything" in cache. for (var i = 0; i < this.cache._cacheMap.length; i++) { var cache = this.cache._cacheMap[i]; for (key in cache) { if (key !== '__default' && key !== '__missing' && this.cache._doNotDelete.indexOf(key) < 0) { if (cache[key].destroy) { cache[key].destroy(); } delete cache[key]; } } }}(Note: This problem did not occur in previous Phaser versions, so I am suspecting that some reference to the audio files are lingering, but can't find out where.) Also, if anyone has a good way of profiling and debugging browser audio, please share, I haven't found a good way to figure out where all this memory goes (Chrome heap profiler says that I use | 20MB).
  5. Hi all, currently I got problem that I have a websocket thread to communicate with the server. and the game object is also start in the process, the situation is like this. when I got the response: A from the server, I will change the game to a new state by game.state.start('NEW STATE'); and then I will get the response: B, C from server, then I need to run some functions defined in the new state, like this game.state.callbackContext.function_in_new_state(); but it is not working, then I loged the state game.state.current I found that the current state is still the OLD ONE. I know the state change need some time, BUT is PHASER provide any callback method when the current state changed to another one, thx everyone.
  6. Hello :), i am facing an the following issue: How do i preserve my sprites, buttons etc. after switiching back from another state. Example: 1. First State: I have several sprites, which i drag an drop around, draw some lines etc. The moment i click on a certan button State 2 is loaded up Sso when i go back to State 1 from State 2,everything is resetted and my sprites are at the wrong place etc. Question: What can i do about it? greets and thanks
  7. Hi, I am new to game development and am trying to make a game where one stage has 6 characters and user can choose any number of characters from here and only those characters will be loaded in next stage. I am using different js files for each stage. Please help. Thanks in advance
  8. Hi there, Can anyone tell me what I'm doing wrong here? I just need an array of sprites with inputOver events. Right now it works on the first load of the menu and not thereafter. It needs to load 4 times in the game. Currently I'm doing this: var createPanels = function(){ // draw panels for (var i = 0; i < 4; i++) { lightPanels[i] = game.add.sprite(ProgressModel.gameRooms[i].x * game.width, ProgressModel.gameRooms[i].y * game.height, 'room-light-' + (i + 1)); lightPanels[i].name = i; lightPanels[i].inputEnabled = true; lightPanels[i].events.onInputOver.add(over, this); lightPanels[i].events.onInputOut.add(out, this); lightPanels[i].events.onInputDown.add(selectRoom, this); lightPanels[i].events.onInputUp.add(Up, this); } }; How should you create sprites in an array with events that are reusable on subsequent state loads? There are no errors, the inputOver event just doesn't fire (the input down works fine every time) Any input is much appreciated. Thanks, H
  9. Hay guys, trying to learn states and i've run into a problem. I've got this function. And when it is called, i need it to create some text. States and breaking my phaser game into several files is a first for me and i cant for the life of me figure this out. I need to create some text from the animationPass function, but i get this error: Uncaught TypeError: Cannot read property 'text' of undefined -- of line 7, and thats where the create introText line is. in my intro.js i've got function animationPass() { introText = this.add.text(320, 240, 'Write some text'); //i've tried this.introText - but that didnt work either. } var introMap = function (game) { var introText; } introMap.prototype = { create: function () { animationPass(); }, update: function () { } } And this has worked fine so far. Infact i've used this structure in another file and it works just fine there. Here i get however Uncaught TypeError: Cannot read property 'text' of undefined -- of line 7, and thats where the create introText line is. My preload.js looks like this preload = function (game) { WebFontConfig = { google: { families: ['Press Start 2P'] } }; } preload.prototype = { preload: function () { this.load.spritesheet('intro', 'img/introAnim.png', 172, 124, 25); }, create: function () { this.game.state.start("introMap"); } } I humbly ask for your assistance. And i'm sorry if the answer is obvious. I would not ask if i hadn't spend a great deal of time trying to figure out the answer myself.
  10. I would like to prevent players from switching to any game state by typing "game.state.start('name');" into the console. Has anyone found a way to prevent this from happening? Imagine you have a login-screen and any user can just type "game.state.start('play');" into the console and skip straight into the game. I have already tried using anonymous functions and closures but the problem is that the other states such as BootState, MenuState, GameState etc cannot access the game object created from new Phaser.game. I cannot be the only one who's worried that users can simply skip any game state by typing one line into the console. How have others dealt with this security breach? I tried googling but couldn't find any posts about this whatsoever. Thanks in advance for all answers!
  11. when i switch from menu state to game state and return at menu, the animation of star field that i have created is stopped. i post my code here: create: function(){ //create a 100 stars in random position this.sprites = this.game.add.spriteBatch(); for (var i = 0; i < this.max; i++) { this.xx[i] = Math.floor(Math.random() * this.game.width); this.yy[i] = Math.floor(Math.random() * this.game.height); var star=this.game.make.sprite(this.xx[i], this.yy[i], 'star'); this.sprites.addChild(star); this.stars.push(star); } // [....] other code }, update: function() { // shift the star at left for (var i = 0; i < this.max; i++) { this.xx[i] -= this.speed; if (this.xx[i] < 0) //return at right and give a new random y { this.xx[i] = this.game.width; this.yy[i] = Math.floor(Math.random() * this.game.height); } this.stars[i].x=this.xx[i]; this.stars[i].y=this.yy[i];//apply a new coords } } }; function play(obj) { obj.game.state.start('Game'); }
  12. Hello! I am making a waste sorting game and when the player loses all their lives, I wish to restart the game. I click the 'RETRY' text and the state reloads, but it seems that my life and garbage sprites never reload. I am wondering if it is because they are in an array (see this.garbage = []; and this.lifeSprites = [];). I have never used game.state.start to reload a state multiple times, I have only ever used it to call a state once. If I cannot get game.state.start to reload my game, I will create a restart() method with some re-positioning code and whatnot. BUT it would be way awesome if I could figure out why this doesn't work!! Below is my code and here is a link to my game so far (my code is still mucho messy). Arrow keys to rotate on desktop. BasicGame.Game = function (game) { this.firstDrop = true; this.garbage = []; this.MAX_TRASH = 5; this.lowestTrash = null; this.lastLowestTrash = null; this.lowestTrashType = null; this.lives = 3; this.lifeSprites = []; this.gap = 500; this.MIN_GAP = 250; this.fallSpeed = 3; this.MAX_FALL_SPEED = 5.5; this.sorter = null; this.rotationSpeed = 10; this.targetRotation = null; this.isRotating = false; this.clockwise = true; this.orientation = null; this.Orientation = { NORTH: 0, EAST: -90, SOUTH: -180, WEST: 90 }; this.TrashType = { BLUE: 0, COMPOST: 1, GREY: 2, YELLOW: 3 }; this.leftKey = null; this.rightKey = null; this.gameover = false; this.score = 0; this.scoreText = null; this.highScoreText = null; this.msgText = null; this.continuePrompt = null; }; BasicGame.Game.prototype = { create: function () { this.lowestTrash = 0; this.lastLowestTrash = this.MAX_TRASH - 1; var trash; for (i = 0; i < this.MAX_TRASH; i++) { trash = this.game.add.sprite(this.game.world.centerX, -this.gap * (i + 1), 'trash'); trash.loadTexture('trash', this.rnd.integerInRange(0, this.MAX_TRASH)); trash.anchor.setTo(0.5); this.garbage.push(trash); if (i == 0) { this.lowestTrashType = trash.frame; } } var life; for (i = 0; i < this.lives; i++) { life = this.game.add.sprite(0, 0, 'life'); life.anchor.setTo(0.5); life.x = (this.game.width - (life.width / 2 + 10)) - (i * life.width); life.y = life.height - 10; this.lifeSprites.push(life); } this.sorter = this.game.add.sprite(this.game.world.centerX, this.game.height, 'sorter'); this.sorter.anchor.setTo(0.5); this.orientation = this.Orientation.NORTH; this.targetRotation = this.orientation; this.scoreText = this.add.bitmapText(25, 25, 'arialPixelated', '0', 16); this.scoreText.align = 'left'; this.highScoreText = this.add.bitmapText(25, 50, 'arialPixelated', 'BEST: ' + BasicGame.highScore, 16); this.highScoreText.align = 'left'; this.continuePrompt = new SuperBitmapText(this.game, this.game.world.centerX, this.game.world.centerY + 100, 'arialPixelated', 'RETRY', 16, 25); this.continuePrompt.anchor.setTo(0.5); this.continuePrompt.align = 'left'; this.continuePrompt.alpha = 0; this.continuePrompt.inputEnabled = false; this.msgText = this.add.bitmapText(this.game.world.centerX, this.game.world.centerY, 'arialPixelated', '', 16); this.msgText.anchor.setTo(0.5); this.msgText.align = 'center'; this.game.input.onDown.add(this.rotateSorter, this); this.game.input.onDown.add(function() {if (this.continuePrompt.isDown){this.game.state.start('Game', true, false);}}, this); this.leftKey = this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT); this.rightKey = this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT); this.game.input.keyboard.addCallbacks(this, this.rotateSorter); //For mobile. Phaser.Canvas.setTouchAction(this.game.canvas, 'auto'); this.game.input.touch.preventDefault = true; }, update : function () { if (!this.gameover) { this.garbage.forEach(function(trash) { trash.y += this.fallSpeed; trash.angle += 0.25; }, this); if (this.garbage[this.lowestTrash].y > this.game.height - (this.sorter.height / 2.5)) { this.checkIfScored(); } } this.sorter.angle = Phaser.Math.snapTo(this.sorter.angle, this.rotationSpeed); if (this.sorter.angle != this.targetRotation) { this.isRotating = true; } else { this.isRotating = false; } if (this.isRotating) { if (this.clockwise) { this.sorter.angle += this.rotationSpeed; } else { this.sorter.angle -= this.rotationSpeed; } } }, resetTrash : function () { this.garbage[this.lowestTrash].y += -this.gap * (this.MAX_TRASH); this.garbage[this.lowestTrash].loadTexture('trash', this.rnd.integerInRange(0, this.MAX_TRASH)); this.lowestTrash++; if (this.lowestTrash > this.garbage.length - 1) { this.lowestTrash = 0; } this.lowestTrashType = this.garbage[this.lowestTrash].frame; }, checkIfScored : function () { if (this.lowestTrashType == this.TrashType.BLUE && this.orientation == this.Orientation.NORTH) { this.score++; if (this.gap > this.MIN_GAP) { this.gap -= 5; } else { this.gap = this.MIN_GAP; } if (this.fallSpeed < this.MAX_FALL_SPEED) { this.fallSpeed += 0.05; } else { this.fallSpeed = this.MAX_FALL_SPEED; } } else if (this.lowestTrashType == this.TrashType.COMPOST && this.orientation == this.Orientation.EAST) { this.score++; if (this.gap > this.MIN_GAP) { this.gap -= 5; } else { this.gap = this.MIN_GAP; } if (this.fallSpeed < this.MAX_FALL_SPEED) { this.fallSpeed += 0.05; } else { this.fallSpeed = this.MAX_FALL_SPEED; } } else if (this.lowestTrashType == this.TrashType.GREY && this.orientation == this.Orientation.SOUTH) { this.score++; if (this.gap > this.MIN_GAP) { this.gap -= 5; } else { this.gap = this.MIN_GAP; } if (this.fallSpeed < this.MAX_FALL_SPEED) { this.fallSpeed += 0.05; } else { this.fallSpeed = this.MAX_FALL_SPEED; } } else if (this.lowestTrashType == this.TrashType.YELLOW && this.orientation == this.Orientation.WEST) { this.score++; if (this.gap > this.MIN_GAP) { this.gap -= 5; } else { this.gap = this.MIN_GAP; } if (this.fallSpeed < this.MAX_FALL_SPEED) { this.fallSpeed += 0.05; } else { this.fallSpeed = this.MAX_FALL_SPEED; } } else { this.fallSpeed = 3; this.updateLives(); } this.resetTrash(); this.scoreText.setText(this.score); }, updateLives : function () { this.lifeSprites[this.lives - 1].loadTexture('lifeFull'); this.lives--; if (this.lives == 0) { this.gameover = true; this.msgText.setText('GAME OVER!\n' + this.score + ' responsibly disposed trashes!'); this.continuePrompt.alpha = 1; this.continuePrompt.inputEnabled = true; this.continuePrompt.input.useHandCursor = true; if (this.score > BasicGame.highScore) { BasicGame.highScore = this.score; this.highScoreText.setText('BEST: ' + BasicGame.highScore); } this.garbage.forEach(function(trash) { trash.kill(); }, this); this.game.input.onDown.remove(this.rotateSorter, this); } }, rotateSorter : function () { if (this.game.device.desktop && !this.gameover) { if (this.leftKey.isDown) { this.rotateLeft(); } else if (this.rightKey.isDown) { this.rotateRight(); } } else { if (this.input.y >= this.sorter.y - this.sorter.height) { if (this.input.x >= this.game.world.centerX) { this.rotateRight(); } else if (this.input.x < this.game.world.centerX) { this.rotateLeft(); } } } }, rotateLeft : function () { this.clockwise = true; switch (this.orientation) { case this.Orientation.NORTH: this.orientation = this.Orientation.WEST; break; case this.Orientation.EAST: this.orientation = this.Orientation.NORTH; break; case this.Orientation.SOUTH: this.orientation = this.Orientation.EAST; break; case this.Orientation.WEST: this.orientation = this.Orientation.SOUTH; break; } this.targetRotation = this.orientation; }, rotateRight : function () { this.clockwise = false; switch (this.orientation) { case this.Orientation.NORTH: this.orientation = this.Orientation.EAST; break; case this.Orientation.EAST: this.orientation = this.Orientation.SOUTH; break; case this.Orientation.SOUTH: this.orientation = this.Orientation.WEST; break; case this.Orientation.WEST: this.orientation = this.Orientation.NORTH; break; } this.targetRotation = this.orientation; } }; EDIT: My input listeners also get jacked up. I separate mobile and desktop but when the state restarts, my mobile listeners are firing when they shouldn't be because I am using desktop, not mobile.
  13. HI, I am beginning with Phaser development and started to read Interphase. Is it possible to re-use UI components in between states? I see that it is possible to pass data to the next state but somehow it is not really working for me. I have this in one state: gengine.IntroScreen = function(game) { this.exit; }; gengine.IntroScreen.prototype = { preload: function () { exit = this.load.image('exit', 'assets/shared/exit_sprite.png'); }, create: function () { this.exit = this.add.sprite(940,20,'exit'); this.exit.inputEnabled = true; this.exit.events.onInputDown.add(this.exitState, this); }, exitState: function() { // restart the game this.state.start('boot'); }, So the exit sprite is wired to a function that resets the game. Eventually I switch state in my code, trying to pass the exit sprite to the next state: this.state.start('next_state', false, false, this.exit); So then I was testing that in the next state, the sprite image was there since I didn't clearWorld() but it no longer responds to any click events. Is it better to just rebuild the UI every time from scratch? Thanks
  14. I was wondering is there function in Phaser that will allow me to generate pixel data object from current Phaser Scene (cover the whole canvas or part of it) and pass this object in I don't know which form to the second Phaser Stage and display it as it is at certain position? Something like this: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Pixel_manipulation_with_canvas Or I just fall back to plain Canvas API and use ImageData object?
  15. Hi people, I've recently just started using the Phaser framework 2 days ago and I am developing my first game, an RPG with phaser...I recently just ran into an issue in my character select state where my scope(this) becomes the window scope and does not recognize my internal functions. Any insight on my issue would be extremely helpful. thank you!!!
  16. ok. I have same problem in there: http://gamedev.stackexchange.com/questions/123954/p2-collision-not-working-after-state-change/124306#124306 I am digging all documentation and examples for solving that problem. But i have nothing really. I can post my own codes if anyone want. And that example: http://phaser.io/examples/v2/p2-physics/state-reset Its including same problem. If you run it carefully, you can see first place objects colliding world bounds, but after changing state its not colliding.
  17. Hello forum I am writing a game using phaser v2.4.8 which has several states. The general structure of my game is: Level list - the player can select a level to play on a draggable background Level - each level consists of 5 puzzles (mini games) Puzzle - each puzzle is a state I am fairly new to javascript and phaser (but not to programming or scripting languages). Enough introductions - after watching several phaser tutorials I just couldn't understand why states are defined in the following way: game.state.add('Boot', Game.Boot); ... //in a separate Boot.js file: var Game = {}; Game.Boot = function(game) { this.someVariableName = ...; ... }; Game.Boot.prototype = { preload: function () { this.add.image(...); ... }, create: function() {...}, ... }; Whereas my states are written as so: game.state.add('Boot', BootState); game.state.add('Preload', PreloadState); ... //in a separate js file: var BootState = { preload: function() { game.add.image(...); ... }, create: function() {...}, ... } //in a separate js file: var PreloadState = { preload: function() { game.add.image(...); ... }, create: function() {...}, ... } My questions are: What is the purpose of the 'game' parameter in Game.Boot = function(game) {...} ? Is the game object automatically passed as an argument in game.state.add('Boot', Game.Boot) ? Is there any reason for me to use the first approach instead of the other one? What are the differences? Thank you in advance for your responses Force out
  18. Hi, I've encountered a strage problem while building a little, mostly static mobile game using Intels XDK, Cordova and Phaser (2.4.6). It's targeted at Android and uses the Crosswalk web runtime. I basically followed Matt McFarlands menu tutorial, and created States to do stuff like booting up, loading all assets, showing a splash screen, showing a menu, the levels etc. I'm using one Phaser.Graphics object per State to draw on (my game only needs a few geometric items). Additionaly I'm using the SaveCPU plugin to avoid unnecessary render cycles. Unfortunately removing it doesn't seem to remove the flashing problem. The stage.background is set to white, in the HTML part backgroud colors are also set to white. When moving from one State to the next I nevertheless get strange black flashes after entering the new State. Sometimes they cover the whole viewable area, sometimes they seem to be a black rectangle originating at the canvas center and covering only the lower right quadrant. I only get those flashes on mobile devices, they don't happen in a browser on a PC. I also observed that they seem to appear only after I add the Graphics object to a State, States whithout Graphics objects don't flash. Unfortunately I wasn't able to find out when exactly a flash occurs, but it seems to be either in or before/after init(), preload() or create(). The typical structure of my States looks like that: MyState = function () {} MyState.prototype = { init: function () { game.stage.backgroundColor = "#FFFFFF"; this.graphics = game.make.graphics(0, 0); // do some more stuff, initialise variables etc. }, preload: function () { this.graphics.alpha = 0; this.graphics.width = game.global.canvasWidth; this.graphics.height = game.global.canvasHeight; // do some more stuff }, create: function() { // do some more stuff game.add.existing(this.graphics); // do some more stuff, set up input handlers etc. // graphics fade in game.add.tween(this.graphics).to({alpha: 1}, 1000, Phaser.Easing.Quadratic.Out, true); // rendering was set to 60 FPS in the previous state (probably unnecessarily), // as long as there are active tweens forceRender() of the SaveCPU plugin is called in update() game.global.saveCpu.renderOnFPS = 0; }, update: function () { if (game.global.saveCpu.renderOnFPS === 0 && game.tweens.getAll().length > 0) game.global.saveCpu.forceRender(); }, render: function () { this.graphics.clear(); // draw stuff like menu buttons game pices etc using graphics drawing methods }, // [ ... more methods for state specific stuff ... ] moveToNextState: function (stateName) { // fade out the graphics and move on to the next state game.global.saveCpu.renderOnFPS = 60; var theEndTween = game.add.tween(this.graphics).to({alpha: 0}, 1000, Phaser.Easing.Quadratic.Out, true); theEndTween.onComplete.add(function () { game.state.start(stateName, true, false); }, this); } } So I wonder if anybody has an idea about what causes the flashes and how I may avoid them?
  19. Is there some plugin or some tool inside Phaser that can help me draw a table of data. I have this image: As you can see I have two arrays of data and they are drawn in Phaser text field as string, but since the numbers inside are of different string length points array is longer than errors array and therefore cut if over the screen boundaires. How can I draw a table with this data, 3 rows by 15 columns? Also could I possibly create such plugin for Phaser?
  20. Hello, I'm having a problem when switching states with Phaser. I have one menu state and one game state. In menu there are different options and different sub-menu options. Something like this: menu: MenuOption1 - click calls function menu1Submenu() which creates sub menu which is overlayed over part of the Menu MenuOption2 MenuOption3 I set groups and images inside menu1Submenu function this way: this.menu1SubmenuGroup1 = this.menu1SubmenuGroup1 || this.add.group(); because you can go back and fort however you want I don't want to create a new group for submenu content everytime - when I already created one before. So I just change renderable to false/true instead and change inputEnabled to false/true depending whether the submenu is active or not. One of the options in submenu is to start the game (thus changing states occurs). I first remove all events I set on all elements of my groups which I created then destroy them and the destroy group as well, to make sure everything is clean I set all the groups to undefined. Then I change state: this.start.state('game'); In the game I have a button which leads back to menu, that buttons simply does: this.start.state('menu'); When I get back to menu animations start, everything seems ok but the moment I click on MenuOption1 to open submenu nothing happens or more precisely when I comment destroying, removing events and setting all groups to undefined I get errors: phaser.js:40129 Uncaught TypeError: Cannot read property 'events' of nullPhaser.InputHandler.start @ phaser.js:40129Phaser.Component.InputEnabled.inputEnabled.set @ phaser.js:45418(anonymous function) @ menu.js:1323Phaser.Timer.update @ phaser.js:65567Phaser.Time.update @ phaser.js:64890Phaser.Game.update @ phaser.js:35146Phaser.RequestAnimationFrame.updateRAF @ phaser.js:60028_onLoop @ phaser.js:60012 83 phaser.js:40273 Uncaught TypeError: Cannot read property 'scale' of null When I set my groups as: this.menu1SubmenuGroup1 = this.add.group(); Everything works ok, but even when I destroy groups and all their content and set the property to undefined it brings this error. Could someone advise me how to remove the stuff properly in this case? I want to keep the groups but don't want to have them declared before because that just adds more content which is needed most of the time (imagine that you don't always open settings, and so on so there is no need to create them all the time), and I also don't want to stick only to this.menu1SubmenuGroup1 = this.add.group(); because this way everytime anyone clicks on any option adds more groups to phaser object (correct?), so a few times clicking back and forth can give dozens of groups which all link to same object (?) or at least polute the memory (I suppose I could always destroy groups set undefined when going through menu but that doesn't seems as a nice effective way). I'm not sharing the entire code because it's too long and I managed to reduce the problem to lines mentioned above. Thank you very much I really appreciate any advice. PS: I used latest stable Phaser version 2.4.7.
  21. I get a error when I use game.state.start() function in phaser.min.js 2.4.6. I want back to previous state(in my code ,it is "Main" state) with a button tap function in "Play" state.so I use the code:game.state.start("Main").but there throw a error:Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D'. It seems like that the preload function in "Main" state been called again,because the game run well when I replace the code to : game.state.start("Main",true,true).In fact ,I must keep the game.Cache in game ,so the gamer woudn't wait for a long time. Who can help me?Thanks to any replies!
  22. Hello everyone, I am trying to create a timer that will count down three minutes after the state was started. I am not sure how to make a text that will visualize the timer.(00:00) Can you guys help out?
  23. So I want to make states which can have custom constructor parameters of some sorts. This is my testState: export class TestingState extends Phaser.State { constructor(firstVar: any, secondVar: any, thirdVar: any) { console.log(firstVar); console.log(secondVar); console.log(thirdVar); super(); } } The firstVar is always the Phaser.Game variable, but the second and third are supposed to be custom parameters. I start my state like this: this.game.state.add('testState', GameStates.TestingState, false); this.game.state.start('testState', false, false, 'Hello', 'test'); The firstVar just logs the Phaser.Game and the second and third print out undefined. But if I remove the 'test' argument, it doesn't log anything the third time.
  24. I am testing whether I can have two states move back and forth while properly updating some shared variables (it's a game with randomized content, so it's important that I can run create() each time). I have the state switch bound to separate keys and the update function of each state polls them, once key in each state. However, in the menu state, the transition works fine but in the Level state it causes a crash. All of the global test variables increment the way they are supposed to, so that's fine. The code behaves the same if I use signal events instead of the update function, so I am misunderstanding something about state transitions. What is it? /** * Menu state. */ function Menu() { Phaser.State.call(this); } /** @type Phaser.State */ var proto = Object.create(Phaser.State); Menu.prototype = proto; Menu.prototype.preload = function() { }; Menu.prototype.create = function() { this.pressKey = this.game.input.keyboard.addKey(Phaser.Keyboard.A); var sprite = this.add.sprite(this.world.centerX, this.world.centerY, "tap-to-start"); sprite.anchor.set(0.5, 0.5); //this.input.onDown.add(this.startGame, this); //this.pressKey.onDown.addOnce(this.startGame, this); }; Menu.prototype.update = function(){ if(this.pressKey.isDown){ this.startGame(); } }; Menu.prototype.render = function(){ this.game.debug.text(testvar, 100, 118); this.game.debug.text(testobj.testvar2++, 100, 128); this.game.debug.text(testobj.prot.testvar3, 100, 138); this.game.debug.text(state1++, 100, 148); //this.game.debug.text(state2, 100, 158); //this.game.debug.text(state3, 100, 168); }; Menu.prototype.startGame = function() { this.game.state.start("Level"); }; /** * Level state. */ function Level() { Phaser.State.call(this); } /** @type Phaser.State */ var proto = Object.create(Phaser.State); Level.prototype = proto; Level.prototype.init = function() { }; Level.prototype.create = function() { this.aKey = this.game.input.keyboard.addKey(Phaser.Keyboard.X); //this.aKey.onDown.addOnce(this.quitGame, this); }; Level.prototype.update = function() { state1 +=1; if(this.aKey.isDown){ this.quitGame(); } }; Level.prototype.render = function() { this.game.debug.text(testvar, 100, 118); this.game.debug.text(testobj.testvar2, 100, 128); this.game.debug.text(testobj.prot.testvar3, 100, 138); this.game.debug.text(state1, 100, 148); this.game.debug.text(state2, 100, 158); this.game.debug.text(state3, 100, 168); }; Level.prototype.quitGame = function() { testvar1 +=1; this.game.state.start("Menu"); };
  25. Hello, a few days ago I started a small game project with Phaser for a task at our school. Everything works fine without any understanding problems, but what's the thing with the states? I think they are very useful for my case to create a menu and so on, but I can't get them to work nicely. Here is my code, a bit shortened: var ASSET_PATH = 'assets/game/'; var bootState = function(game) {}; bootState.prototype = { preload: function() { this.load.image('logo', ASSET_PATH + 'phaser.png'); this.load.image('spaceship_1', ASSET_PATH + 'spaceship_1.png'); this.load.image('starfield', ASSET_PATH + 'starfield.png'); }, create: function() { this.state.start('menu'); } } var menuState = function(game) { this.nameLabel; this.startLabel; this.wkey; }; menuState.prototype = { create: function () { this.nameLabel = this.add.text(80, 80, 'SpaceFight', { font: '50px Arial', fill: '#ffffff' }); this.startLabel = this.add.text(80, this.world.height-80, 'press the "W" key to start', {font: '25px Arial', fill: '#ffffff' }); this.wkey = this.input.keyboard.addKey(Phaser.Keyboard.W); this.wkey.onDown.addOnce(this.start, this); }, start: function() { this.state.start('play'); } }; var playState = function(game) { this.starfield; this.spaceship; this.esckey; }; playState.prototype = { create: function() { this.starfield = this.add.tileSprite(0, 0, 800, 600, 'starfield'); this.spaceship = this.add.sprite(this.world.centerX, this.world.centerY, 'spaceship_1'); this.spaceship.anchor.setTo(0.5, 0.5); this.spaceship.scale.setTo(0.1, 0.1); this.spaceship.rotation = -67.5; //this.spaceship.rotation = 0.5; this.physics.arcade.enable(this.spaceship); this.esckey = game.input.keyboard.addKey(Phaser.Keyboard.X); this.esckey.onDown.addOnce(this.stop, this); }, update: function() { if (this.physics.arcade.distanceToPointer(this.spaceship, this.input.activePointer) > 10) { this.physics.arcade.moveToPointer(this.spaceship, 600); } else { this.spaceship.body.velocity.set(0); } }, stop: function() { this.state.start('menu'); } }; var game = new Phaser.Game(800, 600, Phaser.AUTO, ''); game.state.add('boot', bootState, true); game.state.add('menu', menuState); game.state.add('play', playState); The code works at the first try: At first it loads the required game data, then it calls the menu and if I press w, I can play the (at this point) minimalistic game. But if I press x to get back to the menu, the menu appears to be there (because I can press w to play again), but there is a black screen. I read something about a function to switch from state to state at a very clean way, but I don't get it working. Do you have any idea? Thanks in advance. Regards, Jonniboy