Zampano

Members
  • Content count

    47
  • Joined

  • Last visited

  1. 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.
  2. 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.target, this); this._hasStarted = false; this.removeFromUpdateQueue(); var propnames = Object.keys(this.properties); for (var i = 0; i < propnames.length; i++) { this.target[propnames[i]] = this.properties[propnames[i]]; } } return this; }
  3. 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
  4. 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.
  5. 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?
  6. 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?
  7. Make Phaser.Game less accessible

    Got it, thank you
  8. 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?
  9. 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?
  10. 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
  11. 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!
  12. "Not an instance of Phaser.Game" Problems

    Ah, nice, thank you! (For the record, it's this.game.state.getCurrentState();)
  13. "Not an instance of Phaser.Game" Problems

    function x_collectible(game) { Phaser.Sprite.call(this, game, 0, 0, "x_collectibles", 0); this.anchor.setTo(0.5); this.value = 0; this.game.physics.enable(this); this.body.setCircle(17,3,3); this.sfx = {}; this.sfx["heart"] = this.game.sfx_collectibles["heart"]; this.sfx["superheart"] = this.game.sfx_collectibles["superheart"]; this.sfx["mine"] = this.game.sfx_collectibles["mine"]; this.sfx["ice"] = this.game.sfx_collectibles["ice"]; this.kill(); }; x_collectible.prototype = Object.create(Phaser.Sprite.prototype); x_collectible.prototype.constructor = x_collectible; the "this.game." calls are those that I don't know how to fix after the change.
  14. Hello, I just updated from Phaser 2.8.0 to 2.9.1 and I've got some complications that I don't know how to solve best. I'm using states in different js files with the object BasicGame to hold the states. In BasicGame.Play I create various items of a certain sprite class I wrote. Until now, I did it like this: var c = new x_collectible(this); So "this" is an instance of BasicGame.Play. With the new update, I got an error along the lines of "The value passed as the `game` argument ([object Object]) is not an instance of Phaser.Game.". I went ahead and tried to change it to: var c = new x_collectible(this.game); It worked, but now I'm having trouble accessing functions or variables of my BasicGame.Play state from within the collectible class. Before I used "this.game.variable" or "this.game.function()". What would be a proper solution to this? Adding BasicGame to the arguments when creating a collectible? Adding an isntance BasicGame as an attribute to my Phaser.Game and then do "this.game.BasicGame.Play.variable"? These don't really seem very practical to me...
  15. Soundmanager - managing sounds and volumes

    Thanks for your reply! Unfortunately it doesn't seem to work. The additional Soundmanager is initiated properly and the sound does play, but changing the master volume of this manager doesn't do anything while changing this.game.sound.volume still affects the music. I think I will go with a custom add sound function that also adds the sounds to a directory divided in sfx and music, give each sound a static volume factor and then process this in the runtime together with one master volume variable for each group.