Qbasicnews.com

Full Version: I need help with qb animation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey i am makein an RPG and i want to make it so that i can animate the player so it looks like he is walking....is there a tutorial that can teach me how to do that?
i recently started to make a game similar to the original zelda and i feel that most basic RPGs have the same style of movement, a kind of top down look.

Anyway, what i did was create two sprites for every direction. Then when the character is moving up for example, i just alternate displaying the up sprites. If two frames aren't enough for you, you can make more to better suit your needs.

My character has a type set for him and some of the properties are x position, y position, etc. What i did was create another property which stored the animation frame. Then when i move the player, i change the value of the animation property and then when i draw him, i draw the one according to the value in that property. This gives a nice looking smooth movement.

Hope this helps.
hey thanks. i will try to that.
i have my two sprites for each direction and i have deined some variable types for the caracter but i cant figure out how to do alternate the two frames.
i created two different subs, one for moving the player and one for drawing the player. In my move sub, i listen to the keyboard and if a button is hit, i move the player into the correct direction. In the next sub, i draw the player according to the move sub's new position. (Obviously later on you can worry about collision and boundary detection).

These are direction consts i've declared.
Code:
CONST spU = 1: CONST spD = 2: CONST spL = 3: CONST spR = 4
This block checks the direction.

Code:
SELECT CASE char.direction
        CASE KEYUP
            char.y = char.y - char.yv
            char.sprite = spU
        CASE KEYDOWN
            char.y = char.y + char.yv
            char.sprite = spD
        CASE KEYLEFT
            char.x = char.x - char.xv
            char.sprite = spL
        CASE KEYRIGHT
            char.x = char.x + char.xv
            char.sprite = spR
    END SELECT

Simple enough.

This is where i change the frame.
Code:
IF char.x <> char.oldX OR char.y <> char.oldY THEN
            char.oldX = char.x
            char.oldY = char.y
            char.frame = char.frame MOD 10 + 1
        END IF

Basically if the position of the character has changed, i cycle through the animation frame and add 1. This limits only allowing 1-10 in the frame property.

In my draw player sub, i do this.
Code:
IF char.frame <= 5 THEN
        animate = 0
    ELSE
        animate = 4
    END IF

i then figure out which sprite to draw and prepare the offset for the put.

Code:
frameToDraw = (char.sprite + animate) * SPRITEOFFSET - SPRITEOFFSET

    PUT (char.x, char.y), masks(frameToDraw), AND
    PUT (char.x, char.y), sprites(frameToDraw), OR

The array sprites has 12 images loaded into. The first four are all directions. The next four are all directions but their alternates. The last four are the attack version of the direction. The variable frameToDraw gets the correct offset in my sprites array to draw either the first version of the direction or the alternate second. When the button is held down and the character is moving, it alternates nicely and moves the character along the screen. Perhaps there is a better way for all of this but i've had success in this method so i'm leaving it as is. i hope this makes sense.
yea it makes perfect sense! i am suprised that i couldnt figure that out on my own. i had a brain fart the last week or so. but thanks i really appriciate it.