This site requires JavaScript, please enable it in your browser!
Greenfoot back
shloid
shloid wrote ...

2016/9/22

Help with animating this boney guy.

shloid shloid

2016/9/22

#
Hello I'm trying to create a boss for my game. Unlike most bosses I've ever made, I'm trying to animate the boss by using different subclasses in one class known as "Boss" (see image below for a depiction of the boss class). But I noticed the inconsistency of my animation for both of the arms. On the left arm, LA2 and LAH seem to be alright (despite it being a little bit choppy), while RAH and RA2 seem to not be in synced at all. It feels so choppy and disgusting when I tried running the scenario with the animation scripts. I'm wondering if anyone knows how to make it where LAH can move in motion with LA2 in a less choppier way. Here's the line of code inside LA2. That's where the animation is taking place. I apologize in advance for my messy and unorganized coding.
public class LA2 extends LeftArm
{
    int rot = 225;
    int delay = 0;
    // scrapped variables
    int slowdelay = 1;
    int waitlel = 5;
    boolean isDown = false;
    String rotMode = "up";
    LAH lefthand;
    
    public LA2 (LAH lah) {
        //super();
        GreenfootImage image = getImage();
        image.scale(521,100);
        setImage(image);
        lefthand = lah;
        setRotation(225);
    }
    
    public void act() 
    {
        if (isAttacking == false && delay == 0 && isDown == false) {
            if (rot <= 235 && rotMode == "down") {
               setRotation(rot + 1);
               lefthand.setRotation(-rot - 1);
               lefthand.setLocation(lefthand.getX()-2,lefthand.getY()+2);
               //setLocation(getX()-1,getY()+2);
               rot = rot + 1;
               if (rot == 235) {
                   // for (int lel = 0;lel<=10;lel++) {
                       // rot--;
                   // }
                   rotMode = "up";
                   slowdelay = 1;
                   waitlel = 5;
                   isDown = true;
               }
               delay = 1;
               if (slowdelay != 2 && waitlel <= 0) {
                   slowdelay++;
               } else {
                   waitlel--;
               }
            } else if (rot >= 215 && rotMode == "up") {
               setRotation(rot - 1);
               lefthand.setRotation(-rot + 1);
               lefthand.setLocation(lefthand.getX()+2,lefthand.getY()-2);
               rot--;
               //setLocation(getX()+1,getY()-2);
               if (rot == 215) {
                   // for (int lel = 0;lel<=10;lel++) {
                       // rot++;
                   // }
                   rotMode = "down";
                   slowdelay = 1;
                   waitlel = 5;
                   isDown = true;
               }
               delay = 1;
               if (slowdelay != 2 && waitlel <= 0) {
                   slowdelay++;
               } else {
                   waitlel--;
               }
            }
        } else if (delay != 0) {
            delay--;
        } else if (isDown == true) {
            delay = 1;
            isDown = false;
        }
    }    
}
Also if you wanna know what the boss looks like, here he is.
danpost danpost

2016/9/22

#
To control all the parts together, you need a class that will control all parts at once. My Animated Character scenario is an example of how to accomplish this. Just download and open in the greenfoot application to look over the code to see how.
shloid shloid

2016/9/23

#
Do you have a possible download link to this scenario?
danpost danpost

2016/9/23

#
shloid wrote...
Do you have a possible download link to this scenario?
Yes. Just go to the scenario and click on the big green 'Open in Greenfoot' button to the right and above the scenario window. Save it and then you can open it within your greenfoot application. BTW, your Boss class would be the likely candidate to control all the parts because there is only one skull object and you only want one act method to control all the parts.
shloid shloid

2016/9/23

#
Oops I apologize I did not see the link on "Animated Character" hahaha. But thank you in advance.
danpost danpost

2016/9/24

#
shloid wrote...
Oops I apologize I did not see the link on "Animated Character" hahaha. But thank you in advance.
I was looking over the code of the Animated Character scenario. It may be a bit complicated to understand. However, the main thing is that the parts be controlled together from one set of code. They should not be controlled independently. This means the code should be located in a class where only one instance is created. Unfortunately, that would exclude your Boss class as all objects of its subclasses are also considered Boss objects. Actually, it was incorrect for you to have any of your Boss subclasses be Boss subclasses. For example, a LeftArm object is NOT a Boss object; therefore, LeftArm should not extend Boss. It only a part of what makes up your boss. Even a Boss object is not really a Boss object as far as terminology is concerned with respect to the image rendered for it. It would be more appropriately named Head, Skull, BossHead or BossSkull. Do not worry, once you make the suggested fixes, it will truly be a Boss class. At any rate, if you looked at my Animated Character code, you will see that the Body class contains an inner class (at the end of the code) called Part. You will see that a Body object, when created, will create its appendages (Part objects) and add them into any world that it is added into (see the 'addedToWorld' method). Then, its act method will control the parts by rotational and positional adjustments. An inner class in greenfoot cannot be given a default image; therefore, having only one inner class is reasonable, with the Boss object setting the images of its parts, provided that the Boss object keeps track of its individual parts (I used an array to keep references on the parts). Hope this helped.
You need to login to post a reply.