NoxBrutalis

Members
  • Content count

    18
  • Joined

  • Last visited

  1. Hey everyone, It seems that sounds are accumulating when the game isn't focused. So when i click to another page for example, the sound of the game mutes, but when i click back to the game all the sounds that happened while it was muted seem to play all at once. Before this I think I was making it worse by not having sounds assigned to variables. So originally I was doing this whenever I needed a sound to play : this.scene.sound.play('sound'); the sound seems to be more consistent now that I also assign the sound to a variable and call play on the variable instead: this.sound_gunshot = this.scene.sound.add('gunshot') // gunshot already this.audio.load -ed this.sound_gunshot.play(); However, the problem still stands regarding sounds not being consumed when the game isn't focused. Any ideas about this? Thanks in advance for your time. EDIT - sorry I dont think this is actually an issue. Either it was just needing to change the way the sound was played, like above, or it was that I was using game.sound.add in one place instead of scene.sound.add. Either way I can't say that the problem is noticeable. Feel free to delete the post (don't think I can myself).
  2. NoxBrutalis

    Problem with the Camera in Phaser 3

    If you can't update to the newer phaser, the way around it is to not use the follow method, but to do this: this.cameras.main.scrollX = this.cameraTargetSprite.x - 400; this.cameras.main.scrollY = this.cameraTargetSprite.y - 300; in your update method. edit - the numbers Im taking away from the sprite position are to centre the camera. Otherwise, it wouldn't be aligned properly. Obviously the numbers would potentially be different for you. This is for a camera of 800/600.
  3. NoxBrutalis

    Animation oncomplete callback

    this.on('animationcomplete', this.animComplete, this); in the above, you register the that you want the event to fire. In my example, this.animComplete is a function that will be called back to. Now, in that function, you have access to the current animation and the frame also, like so: animComplete(animation, frame) { if(animation.key === 'shoot') { this.animKeyStack.pop(); this.currentAnim = this.animKeyStack[this.animKeyStack.length - 1]; this.anims.play(this.currentAnim, true); } } Hope that helps, or makes sense. The point is the event has both the animation it is firing from as well as the frame if you need it. Just specify them as arguments to the function you call.
  4. NoxBrutalis

    L3ft 4 Bread

    This is a game that I made for a jam, over 9 days. As such, it's not polished, nor is it finished. It still suffers from texture bleeding, sound issues and has no end state. Still, it's what I made, so here's a link: https://conedstodinggames.itch.io/l3ft-4-bread
  5. NoxBrutalis

    Dragging Sprite Whenever Screen is Dragged

    couldn't you work out the distance between the sprite and the click event and use that as an offset when dragging? Sorry I don't have any code but that's what I would try to do.
  6. I think you probably want this - it's how i get the in-game position of the mouse despite the scroll of the world etc: let cursor = this.scene.cameras.main.getWorldPoint(pointer.x, pointer.y); Hope that helps.
  7. NoxBrutalis

    Movement and speed

    Yes, you're right and in fact I understand your earlier question more clearly now. The moveTo function actually moves you to a position in a way that would be useful for point and click, but I need to use velocity instead, because Im updating the coordinates for sprites constantly in real time - if that makes sense. So yes, upon further reading the arcade physics class I noticed velocity from rotation. Somthing about it feel kinda off, like the rotation is pointed to the top left corner of the cursor rather than the cursors origin or something. Still , thanks for the help Samme. We can count this as solved.
  8. NoxBrutalis

    Movement and speed

    This simple answer was plain for me to see the whole time. I wasn't sure before where to find the moveTo in the docs because there's a whole moveTo class, and I forgot that physics.moveTo in my case physics is arcade physics. anyway, I looked at arcade physics class in the docs and there is a speed param that I simply didn't know was there. This is how the working function looks: this.move = function(delta) { var x = this.sprite.x; var y = this.sprite.y; var xR = Math.sin(this.sprite.rotation); var yR = -Math.cos(this.sprite.rotation); var pos = {x: (x+xR), y: (y+yR)}; this.scene.physics.moveTo(this.sprite,pos.x, pos.y, this.speed); }
  9. NoxBrutalis

    Movement and speed

    Ideally on it's rotation and speed. Like I say, I was originally using the moveTo method and with that form of movement collision detection works, etc. But when I do it that way, the speed multiplier has no effect. and this is how I get the angle to the target - mouse pointer in this case. Just for completeness: let angle = Phaser.Math.Angle.Between(this.sprite.x, this.sprite.y, target.sprite.x, target.sprite.y);
  10. afaik, there can be many different reasons, but with just the image alone, nothing definitive can be said I think. Why not post the code? That will possibly help determine the issue. Make sure you use the code tags in the comment.
  11. NoxBrutalis

    Movement and speed

    I found a method for doing collision on the fly - I assume? But it's not detecting any collisions still (this is using the setPosition style of movement): this.move = function(delta) { var x = this.sprite.x; var y = this.sprite.y; var xR = Math.sin(this.sprite.rotation) * this.speed; var yR = -Math.cos(this.sprite.rotation) * this.speed; var pos = {x: (x+xR), y: (y+yR)}; this.sprite.setPosition(pos.x, pos.y); if(this.scene.physics.collide(this.sprite, this.scene.layer5)) { console.log('detected collision'); this.sprite.setPosition(x, y); } //this.scene.physics.moveTo(this.sprite,pos.x, pos.y); } ..
  12. NoxBrutalis

    Movement and speed

    hey all, when i I use physics.moveTo method, collidisions work as expected, however I can't control the speed of the movement as such. Here's the code I use to move using moveTo: this.move = function(delta) { let x = this.sprite.x; let y = this.sprite.y; let xR = Math.sin(this.sprite.rotation) * this.speed; let yR = -Math.cos(this.sprite.rotation) * this.speed; let pos = {x: (x+xR), y: (y+yR)}; this.scene.physics.moveTo(this.sprite,pos.x, pos.y); } This works how I want, except that the *speed part seems to have no impact on the movement. Which is undesirable because i want the player to have a different speed to enemies. When I use this code (the same as I implemented it in a different game with SFML): this.move = function(delta) { let x = this.sprite.x; let y = this.sprite.y; let xR = Math.sin(this.sprite.rotation) * this.speed; let yR = -Math.cos(this.sprite.rotation) * this.speed; let pos = {x: (x+xR), y: (y+yR)}; this.sprite.setPosition(pos.x, pos.y); } The speed is taken into account - hurray, except the the collisions no longer work. I'm guessing this is because setPosition doesn't check for collisions. So is there either: a) a way to write the code the first way, using moveTo where the speed variable works as intended?, or b) a way to check if the pos variable collides before applying it to the sprite? Thanks in advance for any help - it's much appreciated
  13. NoxBrutalis

    Tiled objects

    Thanks again, B3L7, really helped. Well, I couldn't make too much out of your code, though thanks for sharing that and maybe ill study it closer in future, but knowing that the object was actually an array - or at least contained an array, led me to console.log my objects and figure out different ways of accessing the data. Which helped a lot, and allowed me to create the player from the tiled info and have the camera etc still work as I wanted. Would it be really cheeky to ask yet another question? Sorry if it is, but I will anyways as you seem super helpful. I set up collision boxes for my wall layer in tiled as seen in the image below. These tiles are part of a tileset that is 32x32 per tile, but because these wall tiles are smaller - made to look thin - i made the Bounding boxes as small as I could, i.e smaller than 32x32. However in Phaser, the collision boxes are still just the size of the tile itself, so 32, 32. I thought the point of drawing your collision box in tiled was to allow for cases like this (smaller box than tile dimensions) yet there doesn't seem to be a way. I tried every collision related method i could find in the docs. The only one that I couldn't get to work was the impact one, but im not keen on using that anyways as I have no idea about impact, and i've only just started learning phaser, let alone another engine and I'm not using slopes( top-down game). And when I say worked, I mean they didn't cause a crash, but all they did was make a 32x32 box anyways. Anyway if you have any insight on this that'd be wicked, thank you. Edit, nevermind. I still think the collision boxes are bigger than they should be, but having looked over your code I see you don't do anything special there to compensate for wrongly sized collision boxes. I found out that my problem was being exacerbated by having set my player's origin to 0, 0, and after commenting that out, and changing the size of the player's body, the map functions not as expected, but in a way that works( character can easily enter doorways and get closer to walls than before etc). Thanks again for all the help today dude.
  14. NoxBrutalis

    Tiled objects

    hey again. I have a problem with tiled objects from a tiled map object layer. The problem is that when I use createFromObjects: player = map.createFromObjects('npcs', 'player', {key: 'playerSheet'}); the player isn't moveable. It doesn't have a body and there doesn't seem to be a way to even move a sprite that doesn't have a body. If I try player.setPosition(), causes runtime error because player doesn't have that function. If I try player.Sprite.setPosition, I pretty much get the same thing. So I tried to create a physics enabled version of the created object like this: player = this.physics.add.sprite(map.createFromObjects('npcs', 'player', {key: 'playerSheet'})); and it still creates the object, but I cannot move the object or if I try to have the camera follow the object i just get a black screen. So the only way I seem to be able to make a moveable - camera followed player, is to : player = this.physics.add.sprite(0, 0, 'playerSheet').setOrigin(0, 0); just manually create the player. Which is fine, except my object layer will in future have enemies and npcs in it, and they will need to be able to move, obviously. So does anyone know how to do this in a way that works. I need my objects to be able to move, to have physics enabled for collisions etc. Thanks for any help or just for reading.
  15. NoxBrutalis

    Phaser 3 animation framerate

    Thank you so much, that was exactly the problem. There seems to be an inconsistent mix of camelCase usage in phaser or am i just tripping? Either way, problem solved and you have my gratitude, dude!