mattlangr

Members
  • Content count

    9
  • Joined

  • Last visited

  1. mattlangr

    Getting a reference to events

    Thanks. Great info. M
  2. mattlangr

    Getting a reference to events

    That would be great. I was thinking it might be the case but didn't want to risk it. Thanks.
  3. mattlangr

    Getting a reference to events

    Thanks for the fast reply. Yes performance is paramount and I appreciate the choices, and am impressed by Phaser 3. I think I confused my question by speaking about events in general when I really am asking about preventing memory leaks by destroying dynamically generated timer events. The response is really helpful offering info about the event system in general - thanks. I still need to dive deeper into the event emitter. Looking at: http://labs.phaser.io/view.html?src=src\time\remove timer event.js I saw one can use .remove(false) on the event object. Your example though used a single timer event in a global variable. Here's what I did. Included in the event handler each time a card is clicked, if it's the second card and not a match (concentration game) a timer is included to allow the user to see the cards before they flip back: ... _flipBackTimerStack.push( this.time.addEvent({ delay: 1200, callback: this.returnCards, callbackScope: this, loop: false, args: [holdFirst,holdSecond ] }) ); and then returnCards(firstCard, secondCard) { _flipBackTimerStack[0].remove(false); _flipBackTimerStack.splice(0,1); if (firstCard != null) firstCard.startFlip('back'); if (secondCard != null) secondCard.startFlip('back'); } Again this is a bit lame as it depends on the last in first out. Sorry this is another boring matching game, but it has the good example of generating lots of timer events that need to be removed from memory. They don't destroy themselves right? And no way to get a reference to the timer event if in a local variable, or no variable anonymous event, right? The alternative for this game would have been to use a single global and only one timer event, and if another pair is created while waiting the 1.5 seconds, override the delay and make the timer event trigger immediately, clearing the previous cards, then use the single global variable to hold a new timer event. I was going to ask this as a separate question but wanted to dig deeper, so far I have not found a method to override the delay in the docs. Of course if there is a way that's only a solution for this game mechanic and not the issue in general. Thanks sorry to stretch out a simple question but maybe it's useful.
  4. mattlangr

    Getting a reference to events

    In other languages, libraries and frameworks, when using and event listener the event object would be be sent as an argument to the event handler. This is useful for getting the target, etc, but more important for removing the event. Typically one could then generate events dynamically, say needed in a for loop, in local variables and destroy the event and null the variable after it calls the handler/callback. I don't see this kind of thing in Phaser 3. Am I missing it? I have gotten around the issue in a current game by creating a stack/array of timer events then destroying the oldest. I was only able to do it this way because the events all had the same delay (basically they are delayed calls), so oldest out worked. Thinking forward I am wondering if there is a way to get the event object as an argument? I did try putting the timer event into a local variable and then including that variable in the arguments but it didn't work. I'm still new to phaser and probably missing something. Thanks in advance.
  5. mattlangr

    can't get frameName setter to work

    My bad, I see I was looking at wrong docs. That explains a lot. Thanks again.
  6. mattlangr

    can't get frameName setter to work

    Thanks Rich! It didn't seem to like it when I used an integer on a frame with a filename of "tile_back". In that case I was getting an error telling me it was looking for name which sent me in the right direction. Yes in this case I am playing it fast and loose and using strings that can easily convert from numbers, maybe better to concatenate a prefix... Is there something I was doing wrong with frameName´╗┐? no matter, great to have setFrame() exposed. Thanks again.
  7. mattlangr

    can't get frameName setter to work

    I was wrong about setFrame(), it is looking for name and does work. I am using that for now.
  8. mattlangr

    can't get frameName setter to work

    Sorry - accidentally posted this to Phaser 2 forum at first. Reposting here... I expect admin will delete the first one. I am very new to Phaser (one day of coding) and am jumping in with v3. I am trying to create a simple matching game and using an atlas for the tiles, no I am not using the tilemap at this point. this.load.atlas('match_tiles', 'assets/img/MatchingGameJ.png', 'assets/img/MatchingGameJ.json'); I have a simple card class tracking card data and when a card is clicked, to start, I want to change the card face. I will add the animation next, first I just want to get frameName to work. For now I am also keeping the added sprite object in an array indexed with a card's tileNum as shown below. A click is calling this method: clickCard(cardObj) { console.log(cardObj); console.log(_tileArray[cardObj.getTileNum()]); console.log(cardObj.getCardFace().toString()); console.log("frameName", _tileArray[cardObj.getTileNum()].frameName); _tileArray[cardObj.getTileNum()].frameName = cardObj.getCardFace().toString(); } Using the getter, I see frameName as undefined but then becomes defined with the string after clicking the tile the first time - js creating a property that didn't exist. I can see in the filename in the sprite object's frame.customData.filename property but changing that has no effect. I was able to get this to work using the setFrame() method which is documented as exposed for plugins and custom classes, but that's based on an index, not the filename string. frameName seems to be what should be used. My JSON looks like this - came from Adobe Animate and I hand modified it adding pivots to match what I thought would come out of texture packer: { "frames": [ { "filename": "1", "frame": {"x": 0,"y": 0,"w": 50,"h": 50}, "rotated": false, "trimmed": false, "spriteSourceSize": {"x": 0,"y": 0,"w": 50,"h": 50}, "sourceSize": {"w": 50,"h": 50}, "pivot": {"x": 0.5,"y": 0.5} }, ... I even tried adding fileFrame and filename keys into the JSON based on a comment in another tread. That I can get setFrame() had me thinking about the JSON though this JSON works to put the frames up when first adding the sprites. What am I missing? Thanks in advance.