A little background; I’ve made a few simple clones of games to learn basics, first in c++, then in libgdx, when I realized that building an engine from scratch would be far too much effort for a single person.
So, I’ve decided to try and tackle the biggest project yet, a platform game that would be akin to a ninja gaiden (nes). I’ve started by working through the character movement, collisions, actions, before I start working on enemies, etc…
I’m using tiled for the maps.
Now, I’m at the point where most of the character movement and states are working good. I noticed that the sword swing is way too short, and so I was going to add a sword swipe arc, similar to NG3 (nes) where the swing goes far beyond the actual sword in hand. In order to keep the character sprite lined up with the body and the character in other states (walking, idle, etc) I needed to split the character animation from the swipe arc (fade in and out)
The way I was thinking was to add a fixture over the damage zone, where it will get collisions with enemies, potentially dynamic objects later, and then, once the animation is complete that I would delete that one fixture.
Which would mean that I would need to load a second image / sprite over that fixture. Is this possible?
The issue I was having trying to delete the fixture is that, I was clearly doing it wrong, where deleting the one fixture deleted all fixtures (at least in the debug renderer,since it did not hurt the rest of the gameplay)
Would it be better to create a different sprite class to deal with this arc, with its own body alligned with the character sprite?
Alternatively, would it be better to create the fixtures with the character, and only treat the collision while the character is in an attack state?
I have tried searching for this for a while, and either I’m not using the right search term, or this is not a common issue, so any help or guidance, or links to relevant information is appreciated.
public TextureRegion getFrame(float dt){
currentState = getState();
switch (currentState)
{
case ATTACK:
tmpRegion = attack.getKeyFrame(stateTimer, false); //the character animation
if (attack.getKeyFrameIndex(stateTimer)==0 {
//create fixture / sword sensor
CreateSword();
}
if (attack.isAnimationFinished(stateTimer)) {
//delete sword sensor / fixture
deleteSword();
}
//TODO: Draw the sword damage arc
... }
private void CreateSword(){
switch (getAtkLvl()){
case WEAK:
if (direction){ //direction = true when facing right
swordShape.setAsBox(30f / PPM , 40f / PPM,
new Vector2(b2Body.getLocalCenter().x / PPM + 50f/ PPM, b2Body.getLocalCenter().y / PPM + 20f / PPM ),
0f);
}else{
swordShape.setAsBox(30f / PPM , 40f / PPM,
new Vector2(b2Body.getLocalCenter().x / PPM - 50f/ PPM, b2Body.getLocalCenter().y / PPM + 20f / PPM ),
0f);
}
break;
case MEDIUM:
break;
case STRONG:
break;
}
swordDef.shape = swordShape;
swordShape.dispose();
swordDef.isSensor = true;
b2Body.createFixture(swordDef).setUserData("Sword");
}
private void deleteSword(){
//delete the sensor
}
covers the gist of what I’ve tried so far.