Author Topic: A question~  (Read 2297 times)

Halca

  • Kawaii Bastard
A question~
« on: October 25, 2009, 02:40:16 PM »
Well I gave up on Danmakufu for awhile, but now I'm back into it and want to get it right this time.

I'm understanding things alot better but one thing I don't get is how to animate players and enemies.  Help?

Helepolis

  • Charisma!
  • *
  • O-ojousama!?
Re: A question~
« Reply #1 on: October 25, 2009, 03:01:23 PM »
Well I gave up on Danmakufu for awhile, but now I'm back into it and want to get it right this time.

I'm understanding things alot better but one thing I don't get is how to animate players and enemies.  Help?

You know we have a general Q&A thread for this. A shame you didn't first post your question in there.

Anyway. To awnser your question: Animating players/enemies is simply using different SetGraphicRect functions to change the coordinates. like if(frame<10){showthisgraphicrect}  if(frame>=10 && <20){showthisrect} etc etc.

Iryan

  • Ph?nglui mglw?nafh
  • Cat R?lyeh wgah?nagl fhtagn.
Re: A question~
« Reply #2 on: October 25, 2009, 03:14:37 PM »
I'll try to explain using the standard Rumia scripts in danmakufu as an example.
At first you need to have a sprite sheet for your boss that contains all images required for the animation as one single image file.

Second, you create a variable in your script_enemy_main with which you can refer to the image:
Code: [Select]
    let BossImage = "script\img\ExRumia.png";Then you load the image in the @Initialize.
Code: [Select]
        LoadGraphic(BossImage);In the @Draw part, you pick it as the image which you want to draw, than you select the part of the spritesheet that contains the one sprite you want. As the last part, you draw it.
Code: [Select]
        SetTexture(BossImage);
        SetGraphicRect(64, 0, 128, 64);

        DrawGraphic(GetX, GetY);

The values are, in order, the left, top, right and lower border of the part of the sprite sheet you want to draw. In this sprite sheet, every sprite is 64x64 pixels large.

That's the basics. For a real animation, you need to include conditional statements into your DrawLoop that decide which part of the sprite sheet shall be drawn. With the regular Rumia sheet, you have 4 sprites: Rumia firing, Rumia spreading arms, Rumia flying left and Rumia flying right. Thus, the conditional statements could look like this:

Code: [Select]
        if(GetSpeedX==0){ SetGraphicRect(64, 0, 128, 64); }
        if(GetSpeedX>0){ SetGraphicRect(196, 0, 256, 64); }
        if(GetSpeedX<0){ SetGraphicRect(128, 0, 196, 64); }

If you want a truly animated sprite, things get more complicated. The easiest way would be to create a variable that is increased during the main loop. Then you add an additional condition depending on the value of the variable.

For example, assume the Rumia sprite sheet had an additional set of sprites that were below the actual ones and that were almost the same but changed slightly so that altering between them looks like wind blowing through her clothings.
First you define a variable, lets call it "anim", then put "anim+=50;" into you main loop. Then modify the part in the @DrawLoop like this:

Code: [Select]
        if(GetSpeedX==0){
               if(sin(anim)<0){ SetGraphicRect(64, 0, 128, 64); }
               else{ SetGraphicRect(64, 64, 128, 128); }
        }
        if(GetSpeedX<0){
               if(sin(anim)<0){  SetGraphicRect(196, 0, 256, 64); }
               else{  SetGraphicRect(196, 64, 256, 128); }
        }
        if(GetSpeedX>0){
               if(sin(anim)<0){ SetGraphicRect(128, 0, 196, 64); }
               else{ SetGraphicRect(128, 64, 196, 128); }
        }
The sprite will change alternate every couple of frames between the two possibilities due to the periodic nature of the sinus function.


...I hope that helped.


Edit: Dang, lunardial'd again.
Old Danmakufu stuff can be found here!

"As the size of an explosion increases, the numbers of social situations it is incapable of solving approaches zero."