Fric

Members
  • Content Count

    9
  • Joined

  • Last visited

About Fric

  • Rank
    Newbie

Recent Profile Visitors

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

  1. Hi, i don't really know were is the problem in your code, but maybe i can show you my overlap code that works and you can find something useful. I have 2 sprites in create function: player = this.physics.add.sprite(200, 250, 'goku'); player2 = this.physics.add.sprite(400, 250, 'goku2', 'basic_05'); Then in create function i set bouncing and colliding for them: player.setBounce(-1); player2.setBounce(-1); player.setCollideWorldBounds(true); player2.setCollideWorldBounds(true); And physics collider: this.physics.add.collider(player, player2); Then in update function i make this logic: if(checkOverlap(player, player2)){ if(key_x.isDown || key_z.isDown){ hit_text.visible = true; }else{ hit_text.visible = false; } }else{ hit_text.visible = false; } And i create outside function called checkOverlap: function checkOverlap(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Geom.Intersects.RectangleToRectangle(boundsA, boundsB); } So basically i send two player sprites to that function which gets this two sprites bounds with getBounds function and return the RectangleToRectangle intersects function boolean of if the bounds were Intersected. If that's true, then i check if that overlap was triggered by key_x or key_z (key_x is my sprite punches and key_z is my sprite kicks, so that if goku power up's and overlap the other sprite, it wouldn't count for hit). So maybe you should try Intersects functions, there is RectangleToRectagle and others, look at this link http://labs.phaser.io/index.html?dir=geom/intersects/&q= there is couple of examples of them.
  2. Fric

    resize question

    Because it is in create function. As the function name explains it self, it's creating and that's it. You should place your code in to update function.
  3. I changed pivot point for every smaller sprite like in the biggest sprite and that did the trick. So what i mean is, if i have biggest sprite height of 60px, the pivot point for that sprite is center or in pixels 30px height. Then if i have sprite with height for example 50px, the pivot point height will not be centered, it must be 30px from bottom like in the biggest sprite.
  4. Well i thought there is another way, but ou well, thank you guys!
  5. I think maybe i should add different anchors for different frame? Will that do the trick? About different size frames - well then how am i suppose to make collisions with hits, if my sprite will be the same size? When my sprite making for example kick, it width is more then usual, so the effect of hit collision would be better, don't you agree?
  6. It depends, are you making phaser + cordova game?
  7. Hello, i'm trying to make a fighting game, i created an sprite atlas, which has sprites of different frame size. To make Player sprite collision with other player sprite(like kick or punch) i have to resize the player every time, because the player would have a lot of free sprace around him, because of a biggest frame. So now the problem is, that when i resize the sprite, it's jumps (because of the height difference i think) and the worst thing, when i make the animation of the biggest frames, player just drops through static group platform. I add a mkv file with animation what is happening, can some one help me here? Code: function preload () { this.load.image('bg', 'res/namek.jpg'); this.load.image('ground', 'res/platform.png'); this.load.atlas('goku', 'res/goku.png', 'res/goku.json'); } function create () { this.add.image(320, 180, 'bg'); platforms = this.physics.add.staticGroup(); platforms.create(320, 320, 'ground'); platforms.create(120, 320, 'ground'); platforms.create(520, 320, 'ground'); platforms.create(-20, 180, 'ground'); platforms.create(660, 180, 'ground'); player = this.physics.add.sprite(200, 250, 'goku'); player.setBounce(0); player.setCollideWorldBounds(true); this.anims.create({ key: 'left', frames: [ { key: 'goku', frame: 'basic_09' } ], frameRate: 20 }); this.anims.create({ key: 'turn', frames: [ { key: 'goku', frame: 'basic_05' } ], frameRate: 20 }); this.anims.create({ key: 'right', frames: [ { key: 'goku', frame: 'basic_10' } ], frameRate: 20 }); this.anims.create({ key: 'block', frames: [ { key: 'goku', frame: 'basic_04' } ], frameRate: 20 }); this.anims.create({ key: 'right_punch', frames: [ { key: 'goku', frame: 'basic_08' } ], frameRate: 20 }); this.anims.create({ key: 'right_kick', frames: [ { key: 'goku', frame: 'basic_07' } ], frameRate: 20 }); this.anims.create({ key: 'power_up', frames: this.anims.generateFrameNames('goku', { start: 0, end: 2, zeroPad: 2, prefix: 'basic_' }), frameRate: 10, repeat: -1 }); cursors = this.input.keyboard.createCursorKeys(); key_z = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z); key_x = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.X); this.physics.add.collider(player, platforms); } function update () { if (cursors.left.isDown) { player.setVelocityX(-160); player.anims.play('left', true); player.setSize(29, 43); } else if (cursors.right.isDown) { player.setVelocityX(160); player.anims.play('right', true); player.setSize(32, 41); } else if (cursors.shift.isDown) { player.anims.play('power_up', true); player.setSize(64, 56); } else if (cursors.space.isDown) { player.anims.play('block'); player.setSize(24, 48); } else if (key_z.isDown) { player.anims.play('right_punch'); player.setSize(32, 44); } else if (key_x.isDown) { player.anims.play('right_kick'); player.setSize(40, 45); } else { player.setVelocityX(0); player.anims.play('turn'); player.setSize(30, 46); } if (cursors.up.isDown && player.body.touching.down) { player.setVelocityY(-350); } } dbz-bug.mkv
  8. I have animation this.anims.create({ key: 'left', frames: this.anims.generateFrameNumbers('man', { start: 1, end: 3 }), frameRate: 10, repeat: -1 }); and when i press left key, i play it if (cursors.left.isDown) { player.setVelocityX(-160); player.anims.play('left', true); } I understand that repeat param is responsible for looping animation, but i tried 0, 1, false, -1 and the animation still loops. I didn't find any DOC with all objects and there parameters, so i'm asking here