2d Animations

Previous topic - Next topic

david

I followed the tutorial for the ninja/shuriken game and saw how to make animations with the person moving. How do I make more than 1 animation? It shows how to flip from sprite 0 to 1, but how do I switch from sprite 5 to 1, or 5 to 4 to 3 to 1?

(I have demo version)

Please help me.

Thanks

Kitty Hello

ani = MOD(GETTIMERALL()/100, number_of_frames)
DRAWSPRITE first_animation_id + ani, x,y

bigsofty

Simple example... just add sprites! ;)

Code (glbasic) Select
ALLOWESCAPE TRUE

WHILE 1=1

IF KEY(203) // Change animation on left or right key pressed or idle if none
DIMDATA ani[], 1, 2, 3 // Run left frames (Forwards example)
ELSEIF KEY(205)
DIMDATA ani[], 6, 5, 4 // Run Right frames (Backwards example)
ELSE
  DIMDATA ani[], 10 // Idle
ENDIF


frame_index=INTEGER(GETTIMERALL()/1000) // lower the 1000 for faster animation...
current_frame=ani[MOD(frame_index,LEN(ani[]))] // Get the frame from ani[] array

PRINT "Current_index="+current_frame,100, 100 // drawsprite current_frame, 100,100

SHOWSCREEN

WEND
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Schranz0r

hey bigsofty that's handy :D
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

bigsofty

Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

david

Sorry Bigsofty, I'm not very good at glbasic, where do you add on the sprites?

Kitty Hello

uhm... LOADSPRITE? ...maybe?

david

Code (glbasic) Select
LOADSPRITE "ninjathrow1.bmp", 4
LOADSPRITE "ninjathrow2.bmp", 5
LOADSPRITE "ninjathrow3.bmp", 6
LOADBMP "shrine.bmp"




ALLOWESCAPE TRUE

WHILE 1=1

IF KEY(203)    // Change animation on left or right key pressed or idle if none
    DIMDATA ani[], 1, 2, 3 // Run left frames (Forwards example)
ELSEIF KEY(205)
    DIMDATA ani[], 6, 5, 4 // Run Right frames (Backwards example)
ELSE
      DIMDATA ani[], 10 // Idle
ENDIF


frame_index=INTEGER(GETTIMERALL()/1000) // lower the 1000 for faster animation...
current_frame=ani[MOD(frame_index,LEN(ani[]))] // Get the frame from ani[] array

PRINT "Current_index="+current_frame,100, 100 // drawsprite current_frame, 100,100


SHOWSCREEN

WEND
But it doesn't work. What am I doing wrong?

Kitty Hello

Make sure you have the images for 1,2,3 and for 10 loaded as well? The rest seems pretty good to me.

bigsofty

And change this...
Code (glbasic) Select
PRINT "Current_index="+current_frame,100, 100 // drawsprite current_frame, 100,100to this...
Code (glbasic) Select
PRINT "DRAWSPRITE current_frame, 100,100Load frame images, select a direction key, select a frame of animation, display frame... thats all the code does.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

david

Thank you so much it worked!!!

bigsofty

Your welcome, remember programming is all about building blocks... this is your reference 'sprite animation' example. Keep the URL in a list and use it for reference when starting a new program.

This list could consist of, for example ...

KeyBoard/Mouse handling
Highscore tables
Modular programming
Animation
Start Game Menu
Character movement
Tilemaps
Collision Detection
Sound and Music
Files


Tick each one off, write a little program to test it, keep a reference of how you got it working. Eventually you will have the skills to put it all together in a larger game... overall keep it fun and ask a question if you get stuck! ;)
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)