• Content count

  • Joined

  • Last visited

About carson

  • Rank

Recent Profile Visitors

375 profile views
  1. (Edit): Short version: As simple as the title sounds. How can you pause an animation and then resume it from that same frame? Long version: I am completely stumped with something I thought would be very simple. I have an animation that plays. When an event occurs (I don't know when it will happen ahead of time), the animation needs to pause on its current frame. Then, I need to be able to resume the animation from that frame. I have searched all around and can't seem to find a simple solution to this. Here's what I want to do (but this doesn't work): var player = game.add.spritesheet('hero', 'hero.png', 32, 32);player.animations.add('run', [0,1,2,3], 12, true);'run');// pause animation for a momentfunction freeze() { player.animations.currentAnim.pause();, function(){ player.animations.currentAnim.resume(); }, game);}Things I have already tried: Using stop() and play() - this just starts the animation from the beginningSetting currentAnim.paused = true - doesn't seem to have any effectUsing setFrame() and play() together - just plays from the beginning Any help would be greatly appreciated!
  2. carson

    Separate hitboxes for attack animations

    For anyone that comes across this same issue, here is the solution I came up with: (this code is untested and somewhere between pseudo code and my actual implementation) function create() { // make the player player = game.add.sprite(0,0,'mario'); // create a group for all the player's hitboxes hitboxes =; // give all the hitboxes a physics body (I'm using arcade physics btw) hitboxes.enableBody = true; // make the hitboxes children of the player. They will now move with the player player.addChild(hitboxes); // create a "hitbox" (really just an empty sprite with a physics body) var hitbox1 = hitboxes.create(0,0,null); // set the size of the hitbox, and its position relative to the player hitbox1.body.setSize(50, 50, player.width, player.height / 2); // add some properties to the hitbox. These can be accessed later for use in calculations = "punch"; hitbox1.damage = 50; hitbox1.knockbackDirection = 0.5; hitbox1.knockbackAmt = 600;}// activate a hitbox by namefunction enableHitbox(hitboxName) { // search all the hitboxes for(var i = 0; i < hitboxes.children.length; i++){ // if we find the hitbox with the "name" specified if(hitboxes.children[i].name === hitboxName){ // reset it hitboxes.children[i].reset(0,0); } }}// disable all active hitboxesfunction disableAllHitboxes() { hitboxes.forEachExists(function(hitbox) { hitbox.kill(); });}This implementation "deactivates" the hitboxes when they aren't in use by setting their "exists" property to false. (this is done with the hitbox.kill() function). When their "exists" property is false, their physics bodies are not included in the physics update loop, so any collision/overlap with them will not be possible. (This could also be beneficial to performance for 2 reasons: 1) you reuse hitboxes, so you aren't creating and destroying sprites every time you use an attack and 2) your game won't have to move them all and test them for collision/overlap every single frame) I'm not sure if it's efficient or a good solution, but it seems to work.
  3. I am creating a platformer game where the player can attack enemies. I am currently using arcade physics, but would be willing to switch physics engines if need be. I would like to create hitboxes for my attacks that are separate from my player's hitbox (the player's sprite.body). The following gif (taken from Super Smash Bros: Melee) shows what I am trying to achieve. In this image, Jigglypuff is performing an upwards attack. The yellow hitboxes (surrounding Jigglypuff's body), are Jigglypuff's hitbox. If any of these intersect with a hitbox from an enemy's attack, Jigglypuff will be hurt by that enemy's attack. The red oval(s) is the hitbox of Jigglypuff's attack. If it intersects with an enemy's body hitbox, they will be hit by her attack. (note: the yellow hitboxes are always on Jigglypuff's body. The red hitbox only appears briefly during this attack) I have been able to make do so far with a single hitbox that changes during an attack by using: sprite.body.setSize()However, then I have to make the player invincible during attacks (so he doesn't take damage when his attack collides with an enemy). This strategy also causes problems when colliding with terrain. Another important part about creating separate hitboxes would be creating multiple hitboxes for a single attack. Each hitbox could store information like damage dealt, knockback amount, knockback direction, etc. This would allow attacks to perform differently depending on which part connects with an enemy. For example, if a player did a sword swing, one hitbox could be on the sword hilt, and only do small damage and knockback, while another hitbox could be on the sword blade, and have higher damage and knockback. This image shows another character performing an attack with separate hitboxes for the hilt and blade area of his sword as described above: I have seen some similar questions, and the obvious solution (having multiple physics bodies for one sprite) seems out of the question. Having seen a description of what I am trying to achieve, can anyone shed light on a way I could implement this? Create a group of empty sprites and use their bodies as the hitboxes? Thank you in advance.