GreenCloversGuy

Members
  • Content Count

    10
  • Joined

  • Last visited

About GreenCloversGuy

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. GreenCloversGuy

    "Preparing" a scene before it shuts down

    Thanks for the update, however sleep is not the same as pause. I wanted the player to still see the main game when opening the menu, sleeping the scene stops it from rendering. Also when I transition back to the main scene, if I've paused the scene I'm transitioning to, the scene does not resume, it restarts. Not perfect! I managed to create the effect I wanted by creating two additional scenes. class WorldToDiaScene extends Phaser.Scene{ constructor(){ super('WorldToDiaScene') } create(){ this.scene.transition({ target: 'DiaScene', duration: 1000, }) } } class DiaToWorldScene extends Phaser.Scene{ constructor(){ super('DiaToWorldScene') } create(){ this.events.on('transitioncomplete', ()=>{ this.scene.stop('DiaToWorldScene'); }) this.scene.resume('WorldScene'); } } I launch the first scene from my main scene, which transitions into the menu. Then, when my menu is closed, I have it transition to the second scene, which resumes my main scene and, after the transition is completed, stops itself.
  2. GreenCloversGuy

    "Preparing" a scene before it shuts down

    Having come back to it after a day, I can see that a transition will do most of what I want. I was treating them more like tweens then as, for lack of a better word, handlers. I still have an issue with being unable to work with paused and resumed scenes, having to force them to sleep instead which isn't perfect. Is it possible to run a transition and have it pause the scene instead? Possibly by having a go-between scene which is launched and which instantly transitions to the scene I want to see?
  3. GreenCloversGuy

    "Preparing" a scene before it shuts down

    Hello all, I have a scene in my game, a menu UI scene, which I want to "Dismantle" before it shuts down. Basically, I want the text boxes to fade away and the character art to move out of the screen. I've used tweens to have the items enter the scene when the scene is created, and I've set up the tweens so that they will yo-yo and I've paused them just before they start to yo-yo, so all I need to to is resume the tweens on my gameobjects. My issue is that I need to set up my game so that when a scene should stopped, it instead resumes these tweens, waits for them to finish and then stop the scene. I'm aware that I could do by having any code that closes the scene first emit a "stopscene" event, have my gameobjects listen for this event, resume the tween and then emit an event after they have both finished, however this seems messy and complicated. I've looked into transitions but I don't believe you can use transitions on scenes that have paused or launched and when I tried playing with them earlier, I found myself resetting the scene I was trying to resume. Is there a nice easy way for me to "prepare" a scene for stopping, perhaps through the scene manager or by extending the scene and overriding the code that will stop the scene?
  4. GreenCloversGuy

    Container With Sprite + Text - Centering Text

    Sorry to revive a sorted issue, but I have to ask, why is the origin of text different to the origin of other game objects? Are there any other game objects with origins other then (0.5, 0.5)? And wouldn't it make sense to make reference to this in the API? I know the API is still being worked on, but I nearly went crazy trying to get my text to align properly because I didn't realise that the origin was (0, 0) and not the default 0.5. Is this an issue I should raise on github? https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Text.html#originX__anchor
  5. GreenCloversGuy

    Chaining multiple animations together

    Should be able to use the onCompleteEvent, using the name 'animationcomplete' and adding an event listenter onto your sprite. Example here: How I would do it: this.player.anims.play("left", true).on('animationcomplete', () => {this.player.anims.play("right", true).on('animationcomplete', () => {this.player.anims.play("turn", true)} )} ) Edit: Whoops, seems more complicated than this, I just tried the code and this code seems to cause an infinite loop for the third animation in the list. I think it's because I used the on on the animation and not on the sprite, which is kind of annoying, if understandable. You'll probably need to create a single 'animationcomplete' listener on the sprite that changes which animation is next based on the animation that's just ended. Example: (animation) => { if (animation.key == "left") this.player.anims.play("right", true);
  6. GreenCloversGuy

    Can I apply pixelArt + Round pixels to a sprite only?

    I believe you can create an extra camera for your player in the scene, have the main camera ignore your player and the extra camera ignore everything but the player and then use the setRroundPixels method on the extra camera. You can see a similar effect with blurring one image and not the other in this example. EDIT: Quick example of the idea here without all the extra pipeline stuff.
  7. GreenCloversGuy

    How do I call a callback function when two objects stop overlapping?

    I suppose I could do, but I'm trying to learn Phaser 3 and make use of it's features! In addition, using bodies and physics helps make my code more structured in a way that makes sense to me. I'd rather control both my player and my NPC and their interactions though methods in the classes and through the scene they are both placed in. It wouldn't be impossible to create a method for the NPC class that would take a list of objects for my NPC to interact with and test the distance, but just trying to think through it now is making my head hurt. That is interesting. Thanks for confirming my assumptions about the engine. I have rewritten my code to include your first post earlier with success, but I might edit it so I can create an "addOverlap" method for my class, as it makes sense to me the way I've written my program. I was a bit annoyed by how difficult this was, but now seeing this I understand the logic a bit better.
  8. I am someone who enjoys making diagrams when I'm programming something complicated to make sure I understand what I'm doing. I tend to do this when making object orientated programs as it helps me work out which objects are linked to what and help me create a more modular program. I created a diagram for part of my latest game which I've attached. It helped me think about how my game is currently coded and how I can improve it, in this example by having my objects send a message to my scene which will launch my new scene, reducing the number of connections between the scene into a single connection. Do you use visualisation diagrams to help you design? Which do you use, and why?
  9. GreenCloversGuy

    How do I call a callback function when two objects stop overlapping?

    Thank you for your response! Out of curiosity, do you think that using an overlap and a modified body is the correct way of doing this?
  10. I am a hobbyist game developper and I've been trying to get into Phaser 3 recently as I enjoy using Javascript. I'm making an rpg-like and I'm trying to make a very basic "Press x to talk" system. I'm trying to get an image to show when the player is within range of an NPC. class WorldScene extends Phaser.Scene{ constructor(){ super('WorldScene') } preload(){ } create(){ this.NPC = new NPC(this, 200, 90, 0x00FF00) this.player = new WorldUnit(this, 50, 100, 'player', 0) this.cursors = this.input.keyboard.createCursorKeys(); this.player.addOverlap(this.NPC); this.NPC.addOverlap(this.player); } update () { this.player.update(); this.NPC.update(); } } class Unit extends Phaser.GameObjects.Sprite{ constructor(scene, x, y, texture, frame) { super(scene, x, y, texture, frame); scene.add.existing(this); } addOverlap(targetCollider, func){ this.scene.physics.add.overlap(this, targetCollider, func, false, this.scene); } } class NPC extends Unit { constructor(scene, x, y, color){ super(scene, x, y, 'player', 1); scene.add.existing(this); scene.physics.add.existing(this); this.setTintFill(0x000000); this.body.setCircle(20, -10, 0); this.talkalert = new Phaser.GameObjects.Image(scene, x, y-10, 'icons', 49) this.talkalert.setScale(0.2) this.talkalert.alpha = 0; scene.add.existing(this.talkalert) } addOverlap(targetCollider){ super.addOverlap(targetCollider, ()=>{ this.talkalert.alpha = 1; }) } update(){ } } I've not shown the WorldUnit class as there is currently no events being shared between the two so I believe that the code can only be completed in the NPC class. I'm able to use my addOverlap method to add the overlap event to my program, and it does cause my "talk" icon to show up, however it stays there forever and I can't find any code that will set the alpha of my icon back to 0. I have tried multiple things, including the following: this.body.touching.none (Taken from this example) Does most of what I want it to do, however if the player is inside of the code and does not move then this.body.touching.none becomes true and the icon disappears. I do not know why this is happening. addOverlap(targetCollider){ super.addOverlap(targetCollider, ()=>{ //this.talkalert.alpha = 1; }) } update(){ this.talkalert.alpha = this.body.touching.none ? 0 : 1; } ' setting the alpha back to 0 in the update loop (Taken from this Phaser 2 forum post) Causes the alpha to be constantly set to 0, I believe that update is running after the collider callback is running so, even though the callback is setting the alpha to 1, it's being set back to 0 before the image can be rendered. addOverlap(targetCollider){ super.addOverlap(targetCollider, ()=>{ this.talkalert.alpha = 1; }) } update(){ this.talkalert.alpha = 0 } I feel like there's something obvious that I'm missing in my research and I'm approaching this problem all wrong, I would really appreciate it if someone could help me improve my code.