BASIC

Author Topic: 2d Animations  (Read 3788 times)

david

  • Guest
2d Animations
« on: 2007-Nov-24 »
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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
2d Animations
« Reply #1 on: 2007-Nov-24 »
ani = MOD(GETTIMERALL()/100, number_of_frames)
DRAWSPRITE first_animation_id + ani, x,y

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2632
    • View Profile
2d Animations
« Reply #2 on: 2007-Nov-25 »
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)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5024
  • O Rly?
    • View Profile
2d Animations
« Reply #3 on: 2007-Nov-25 »
hey bigsofty that's handy :D
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2632
    • View Profile
2d Animations
« Reply #4 on: 2007-Nov-25 »
ty :)
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

  • Guest
2d Animations
« Reply #5 on: 2007-Nov-27 »
Sorry Bigsofty, I'm not very good at glbasic, where do you add on the sprites?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
2d Animations
« Reply #6 on: 2007-Nov-27 »
uhm... LOADSPRITE? ...maybe?

david

  • Guest
2d Animations
« Reply #7 on: 2007-Nov-27 »
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?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
2d Animations
« Reply #8 on: 2007-Nov-27 »
Make sure you have the images for 1,2,3 and for 10 loaded as well? The rest seems pretty good to me.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2632
    • View Profile
2d Animations
« Reply #9 on: 2007-Nov-27 »
And change this...
Code: GLBasic [Select]
PRINT "Current_index="+current_frame,100, 100 // drawsprite current_frame, 100,100
to this...
Code: GLBasic [Select]
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.
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

  • Guest
2d Animations
« Reply #10 on: 2007-Nov-28 »
Thank you so much it worked!!!

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2632
    • View Profile
2d Animations
« Reply #11 on: 2007-Nov-28 »
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)