• View unanswered postsView active topics

  • [tutorial] Not another Animated Sprites tutorial!

    Discuss Wolf3D and Wolf3D modding/ports

    Postby Tricob1974 07 Nov 2011, 07:30

    Until the DHWs forum is up and running again, here's the tutorial I was planning to post on it.

    This code has bits and pieces from just about everyone, including WSJ, BrotherTank, DarkOne ... the list goes on.

    So what makes this tutorial different? Well, to change or expand the data for your animated sprites, you *don't* have to go into the middle of WL_DRAW.CPP to change things. Just go into an H file instead, and Rebuild the code.

    So, let's get started. Go into WL_DRAW.CPP, and do a search for "static objects". You should see this code:

    Code: Select all
    //
    // place static objects
    //

    Insert this code just above it:
    Code: Select all
    // Animated Objects code
        frameon+=tics;
        frameon%=2520;
        /* remember 70 tics/second, so this will support total cycle time of 2 seconds tops.  Just increase the 140 if you want*/
    // End Animated Objects code

    Now do a search for "visable". Yes, I know it's misspelled. I'm just telling you the way it's put it in the code. :) Anyway, you should see this:
    Code: Select all
            if (!*statptr->visspot)
                continue;                                               // not visable

    Now, insert this code just below it:
    Code: Select all
    struct
    {
        short      picnum;
        int        animtics, animframes;
    } animsprinfo[] =
    {
    #include "_animatedstaticobjects.h"
        {-1}                                    // terminator
    };

        for (int animstat = 0; animsprinfo[animstat].picnum != -1 ; animstat++)
        {
    // Animated objects
        if (visptr->shapenum == animsprinfo[animstat].picnum)
                                visptr->shapenum += int((frameon/(animsprinfo[animstat].animtics))
                                %animsprinfo[animstat].animframes);
           }

    What this code does is take all the Animated Sprites and puts them in an array, then goes through that array until it hits the "-1" end-marker. Does doing the code this way lower the framerate? Slightly, maybe. But it'll be easier to work with.

    Now, create a text file called "_animatedstaticobjects.h". Note the "_" I put in the filename. This ensures that the file always appears at the top of your Project list.

    In this example, I'm giving the file this content:
    Code: Select all
    // Format: SprName, T, F
    //
    // If the sprite has the name of SprName, animate it using F frames total, and change the frame
    // every T tics.  For example, if the object is called SPR_STAT_0, then the data
    // "SPR_STAT_0, 6, 4" will have it uses 4 frames of animation, and the frame will change every 6
    // tics.  70 "tics" is equal to one second.

        SPR_STAT_0,  6,  4,
        SPR_STAT_4, 12, 8,

    Now save the file, and Add it to your project in the compiler. Now Rebuild your code, and run the EXE. The water puddle is animated with four frames of animation, and the frame is changed every 6 tics. The chandelier should use eight frames of animation, and the frame changes every 12 tics.

    I think that should do it. Hope my tutorial proves useful. :)
    Tricob1974
    Team RayCast member
    Team RayCast member
     
    Posts: 1384
    Location: Huntsville, Alabama

        

    Postby DoomJedi 07 Nov 2011, 10:26

    Thanks :)

    DHW is down alot lately.
    This forum can become a new DHW, heh :D

    It's easy to repost from here to DHW when it's up as well.

    If you need more of DHW areas duplicated here - just ask
    DoomJedi
    User avatar
    Administrator
    Administrator
     
    Posts: 14228
    Location: Israel

        


    Return to General Wolf3D/modding Discussion and tutorials


    Who is online

    Users browsing this forum: No registered users and 5 guests

    cron