• Content count

  • Joined

  • Last visited

  1. PhysicsElapsed & Monitor Refresh rate

    I see. But the monitor's refresh rate seems to put a cap on it, I don't have 144 logic updates on my 60hz monitor as far as I can tell. So can I just globally leave it at 144 or would it be better for performance to put a system in place that checks the max fps and adjusts desiredFps accordingly in common refresh rate steps?
  2. PhysicsElapsed & Monitor Refresh rate

    Oh. It actually works. But I don't exactly get why it does... and moreso, why is it even there in the first place then and not "set to infinite"? And I guess this also means that 30hz monitors wouldn't have that problem, doesn't it?
  3. Hey guys, I had related topics before, but let me give a short summary: I am working on a time-based game, roughly similar to guitar hero. For that, I use deltaTime and PhysicsElapsed like this: update: function() { deltaTime = (this.time.elapsedMS)/(1000/60) this.time.physicsElapsed = this.time.elapsedMS*0.001; } So if the framerate drops to 30, deltaTime = 2 and physicsElapsed will also be double the value it is normally (1/60 as in 1/desiredFPS). It always seemed to work perfectly fine. Sure, it leads to a loss of accuracy whith lower framerates or bigger lags, but that's another story. I've tested it with 30fps (forced with a screen capture tool) and it was running at the same speed as it would with 60, so everything is alright. Just yesterday, I found out that when played on a 144hz monitor, the game runs in slow motion. I've checked all the vars above, and I could not find a problem. The game runs at 144 fps, deltaTime is around 0.42 as it should be and physicsElapsed naturally also has the value I expected (0.006999999999999999 for example). But all the motions are at half speed. Or more like 0.42x speed. The spawns, which are also tied to the game time are correct, so no problems there, but everything just moves too slow. The big mistery is: if somebody has a 30hz display, will it run at double speed which wouldn't be playable at all? I just can't think of a reason why this would happen as everything works fine with software caused differences in fps and especially since all the values seem to be in check. Maybe I am overlooking something? Maybe the hardware has some other effect that takes place outside of my code logic? I read that there are issues with other refresh rates, but I was under the impression my code would take care of that. Please help D:
  4. Global key event in all states

    Hey there, I'm trying to get a key to always call a certain function, regardless of which state my game is in. At the moment, my code is this: var escKey = null BasicGame.Boot = function (game) { //... }; BasicGame.Boot.prototype = { init: function () { escKey = game.input.keyboard.addKey(Phaser.Keyboard.ESC); escKey.onDown.add(function(){console.log("esc")}, game); } And so on. escKey stays defined in all states, but onDown doesn't trigger. If I move the two lines within init to a state, I can use ESC in that state, but not in any state after that. Is there a way to do this?
  5. Stop and restart a tween/recycling tweens

    I think that's a good idea. I had quite some trouble finding out that the "problem" is kind of intended, especially since isRunning was true.
  6. Stop and restart a tween/recycling tweens

    Thank you both! Tom's approach was more like it since I want to use the exact tween again and not delete it's properties. I ended up doing it like this: Phaser.Tween.prototype.removeFromUpdateQueue = function () { var i = this.manager._tweens.indexOf(this); if (i !== -1) { this.manager._tweens.splice(i, 1); } else { i = this.manager._add.indexOf(this); if (i !== -1) { this.manager._add.splice(i, 1); } } } Phaser.Tween.prototype.skip = function () { if(this.isRunning || this.isPaused) { this.isRunning = this.isPaused = false; this.onComplete.dispatch(, this); this._hasStarted = false; this.removeFromUpdateQueue(); var propnames = Object.keys(; for (var i = 0; i < propnames.length; i++) {[propnames[i]] =[propnames[i]]; } } return this; }
  7. Hey guys, I've run into yet another case of "don't know how to do this best" and I'm looking for help Here's my Scenario: I've got a sprite with a certain tween. The tween is supposed to be skippable, which means it stops and all properties of the sprite will be set to the target values of the tween and the onComplete function will be fired. After that, it can be played again and so on. Here's the Tweens setup: this.portrait.inFocus = false; this.portrait.focusTween = this.add.tween(this.portrait).to({alpha: 1}, 1, Phaser.Easing.Linear.None, false, 0).to({alpha: 0}, 1000, Phaser.Easing.Quintic.Out, false, 0); this.portrait.inTween.onComplete.add(function(){this.inFocus = true}, this.portrait); Problem: Using stop() also marks the tween for deletion and it won't play again. My ideas: - Using stop() and adding a new tween each time. As I see it, the downside would be that I need to add the onComplete function every time, too. Also, I'm not so sure about the memory usage for this one. - Overriding the stop() function to not remove the tween. I tried it bycommenting out this.manager.remove(this), but it's already causing some weird behaviour with the tween jumping to it's start randomly after completing, and I'm a little bit afraid that could cause other damage elsewhere anyways.. So... I'm very open to suggestions and/or clarification
  8. sound.destroy / sound.remove not working?

    Okay, you're right, the context is empty. However, the audio object is still there after changing states. Let me back up a little: I set up a system that allows the user to change volumes for sfx, music and voices independently. For that, I've got globally available arrays into which I push instances of sounds, like this: this.sfx_loading_complete = this.sound.add("sfx_loading_complete"); game.sfx_Manager.sfx_index.push(this.sfx_loading_complete); So when changing the state, I want to clear the sounds that will not be used again from memory. I'm not sure how to check if that's really the case though.
  9. Hey there, I've encountered some weird behaviour when trying to clean up not longer used sounds. I boiled it down to this: this.sfx_loading_complete = this.sound.add("sfx_loading_complete"); console.log(this.sfx_loading_complete); this.sfx_loading_complete.destroy(); // or //game.sound.remove(this.sfx_loading_complete); console.log(this.sfx_loading_complete); Both console logs put out the fully functional sounds, regardless of whether I use remove or destroy.. What am I missing?
  10. Make Phaser.Game less accessible

    Maybe just one more question Does that mean it is not necessary/of any further use to try to make ANY variables inside the IIFE harder to access? So "this.score" in my Game State etc instead of making it only accessible from within would be fine?
  11. Make Phaser.Game less accessible

    Got it, thank you
  12. Make Phaser.Game less accessible

    Thank you for the recommendation, I will definitely check those out! To be clear, would enclosing the entire code really make manipulation impossible or is it "only" making it a lot harder?
  13. Make Phaser.Game less accessible

    Right, about that: I've read about that and did so here, but all the code in external javascript files (Boot, Preloader, Game States...) is loaded in the index.html head area. BasicGame is declared as a global variable in Boot.js so this means it's outside of the anonymous function... Is there a way to move it all in there?
  14. Shake Camera but don't shake UI

    I had the same problem and the solution I came up with was a custom shake function to which you can give an element or an array of elements to shake. Maybe this helps you, too. If you want to shake multiple objects at once, pass them as an array or otherwise they will be shaken independently of one another. setBaseXY = function (element) { element.xbase = element.x; element.ybase = element.y; } shakeElement = function(element, game, x = 15,y = 15, delay = 0, duration = 1200, loops = 0) { //ALWAYS SET BASE XY var e = []; if(isArray(element)) e = element; else e[0] = element; var x_arr = []; var y_arr = []; if(loops === 0) loops = game.math.roundTo(duration/200,0); if (loops < 1) loops = 1; for (var ii = 0; ii < loops*2; ii++) { x_arr[ii] = game.rnd.sign()*game.rnd.integerInRange(x/3,x)*((loops-ii/2)/loops) y_arr[ii] = game.rnd.sign()*game.rnd.integerInRange(y/3,y)*((loops-ii/2)/loops) } for(var i = 0; i < e.length; i++) { if(typeof e[i].xbase === "undefined") { console.log("########## WARNING: NO BASE XY FOR OBJECT: "); console.log(e[i]); setBaseXY(e[i]); } var x_arr_e = []; var y_arr_e = []; for (var iii = 0; iii < x_arr.length; iii++) { x_arr_e[iii] = e[i].xbase+x_arr[iii] y_arr_e[iii] = e[i].ybase+y_arr[iii] } x_arr_e.push(e[i].xbase); y_arr_e.push(e[i].ybase); e[i].shaketween = game.add.tween(e[i]).to({ x: x_arr_e, y: y_arr_e }, duration, Phaser.Easing.Cubic.Out, true, delay); } } Edit: for some reason whenever I pick javascript as language for the code element^ it does not save the choice... so sorry for the lack of syntax highlighting
  15. Make Phaser.Game less accessible

    Hey there! We've established before that javascript and therefore phaser games can be manipulated via console and that this can only be prevented by double checking everything with the server. Now aside from that, I wondered if it would to a certain extend help to 'hide' BasicGame, which usually is a global variable and can therefore be accessed easily. My idea is this: (function() { var cfg = { width: 1280, height: 720, renderer: Phaser.WEBGL, antialias: true, parent: 'gameContainer', enableDebug: false }; var states = [] states.push(['Boot', BasicGame.Boot]) states.push(['Preloader', BasicGame.Preloader]) states.push(['MainMenu', BasicGame.MainMenu]) states.push(['Intro', BasicGame.Intro]) states.push(['XMode', BasicGame.XMode]) BasicGame = null; var game = new Phaser.Game(cfg); for(var i = 0; i < states.length; i++) if(isDefined(states[i]) && states[i] != null) game.state.add(states[i][0], states[i][1]); game.state.start('Boot'); })(); I've implemented that into my index.html and it works fine. I imagine it makes the game way harder to adress via console, but many some of you with a deeper understanding of javascript could tell me if there really is any use to it, since there's the small downside that when working with global functions, I always need to pass game to them. Thank you!