sendmenas

Members
  • Content Count

    6
  • Joined

  • Last visited

  1. Is this very hard or very stupid question?
  2. Hi, I have created a Tiled map with object layer in it. this.objectLayer = this.map.createFromObjects('Object Layer 1', 1, {key: 'brick'} ); This creates an array of sprites, as expected. But when I check these sprites, I see that body is null. I want to add collider for the objects and I believe due to the reason that they have no body, this does not work. What I aim to do is to create walls, that after hit will shrink by 25% based on bullet direction. I successfully managed to do it on one brick without using Tiled map: // Created brick this.bricks = this.physics.add.staticGroup(); this.bricks.create(400, 300, 'brick'); // Added callback on hit this.physics.add.overlap(this.bricks, this.bullet, this.bulletBrickHit, null, this); // Changing brick size on hit bulletBrickHit(bullet, brick) { switch(bullet.direction) { case 'left': brick.setCrop(0, 0, brick.body.width - 25, brick.body.height); brick.setSize(brick.body.width - 25, brick.body.height); break; } } But I was thinking of using Tiled for map creation as it would be much faster to do it using it. So my questions are: Can I use Tiled objects for this? Or should I add all bricks manually, as Tiled is not for that? Maybe there is some other way how to do it "right"? Or maybe I am just missing something? I would really appreciate your help.
  3. sendmenas

    How to resize wall on hit

    After a few days of trial and error I came up with this solution, maybe it will help someone in the future. bulletBrickHit(bullet, brick) { switch(bullet.direction) { case 'up': brick.setCrop(0, 0, brick.body.width, brick.body.height - 25); brick.setSize(brick.body.width, brick.body.height - 25); break; case 'down': brick.setCrop(0, 0, brick.body.width, brick.body.height - 25); brick.setSize(brick.body.width, brick.body.height - 25); brick.y += 25; brick.body.y += 25; break; case 'left': brick.setCrop(0, 0, brick.body.width - 25, brick.body.height); brick.setSize(brick.body.width - 25, brick.body.height); break; case 'right': brick.setCrop(0, 0, brick.body.width - 25, brick.body.height); brick.setSize(brick.body.width - 25, brick.body.height); brick.x += 25; brick.body.x += 25; break; } if (brick.body.width == 0 || brick.body.height == 0) { brick.disableBody(true, true); } }
  4. sendmenas

    How to resize wall on hit

    Thank you for the help. Still, would be great to have other opinions from other developers as well, it feels like I might need other ways to do the similar things it the future.
  5. sendmenas

    How to resize wall on hit

    This is one of the options, but as the wall will have ~9 possible stages, I was wondering if there is a possibility to manage it in another way than defining separate pic for it. I was playing around with the sprite length and height, but it does not change when I try to set it (I tried to make the update of an item after that, with no luck).
  6. sendmenas

    How to resize wall on hit

    Hello, I am working on a "NES Battle City" clone with Phaser3 and I can not figure out how should I resize a wall on bullet hit. What I want to achieve is that on bullet hit part of the wall is destroyed. I tried to find something similar in tutorials but I couldn't. The closest thing I came up with was to use "setCrop()", but it only changes the size of the image, and the wall object size stays the same, so this does not work. Can anyone point me in the right direction how should I do it? My code is here - https://github.com/sendmenas/Tanks/blob/master/script.js Demo - https://sendmenas.github.io/Tanks/index.html Who is not familiar with this game, you can check it here - http://emulator.online/nes/battle-city/