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
ani = MOD(GETTIMERALL()/100, number_of_frames)
DRAWSPRITE first_animation_id + ani, x,y
Simple example... just add sprites! ;)
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
hey bigsofty that's handy :D
ty :)
Sorry Bigsofty, I'm not very good at glbasic, where do you add on the sprites?
uhm... LOADSPRITE? ...maybe?
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?
Make sure you have the images for 1,2,3 and for 10 loaded as well? The rest seems pretty good to me.
And change this...
PRINT "Current_index="+current_frame,100, 100 // drawsprite current_frame, 100,100
to this...
PRINT "DRAWSPRITE current_frame, 100,100
Load frame images, select a direction key, select a frame of animation, display frame... thats all the code does.
Thank you so much it worked!!!
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! ;)