Author Topic: Animated Sprites  (Read 3552 times)

0 Members and 1 Guest are viewing this topic.

Offline Axe Programmer

  • LV2 Member (Next: 40)
  • **
  • Posts: 32
  • Rating: +0/-0
    • View Profile
Animated Sprites
« on: September 19, 2013, 11:21:39 am »
Hey guys, can anybody show me how to make animated sprites? For example like a person walking that is not just dragging his legs actually walking? or a rolling ball? is there a way to do this other than making a bunch of animated sprites and display them individually?
please include a code thanx ;D

Offline Vijfhoek

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 120
  • Rating: +13/-1
    • View Profile
Re: Animated Sprites
« Reply #1 on: September 19, 2013, 11:31:56 am »
I always display a bunch of separate sprites, I'm pretty sure that's how you're supposed to do it. For example, a waving horizontal line:

Code: [Select]
.WAVYNESS
[FF00000000000000]->Pic1
[00FF000000000000]
[0000FF0000000000]
[000000FF00000000]
[0000FF0000000000]
[00FF000000000000]

.F = frame
0->F

Repeat getKey(15)
 DispGraphClrDraw
 F++
 If F>5
  0->F
 End

 Pt-On(0,0,Pic1+(F*8))
End
« Last Edit: September 19, 2013, 11:35:02 am by Vijfhoek »

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Animated Sprites
« Reply #2 on: September 19, 2013, 11:32:38 am »
For instance, you have many sprites:
Code: [Select]
[aa]->Pic1
[bb]
[cc]
WHen you are moving, edit a little variable which acts a pointer offset to access differents sprites
Code: [Select]
[aa]->Pic1 :. Not actual sprites
[bb]
[cc]
0->X
0->C :.Counter
ClrDraw
Repeat GetKey(15)
.Updating position
X++
.Updating Sprite counter
C+1^3->C :. ^ Is modulo, and gives the rest of the euclidian division. Go test this lil' thing, this could help a lot
Pt-On(X,0,C*8+Pic):.Drawing sprite. The C offsets th Pic1 pointer to give others sprites)
DispGraphClrDraw
Pause 50
End


AWW, ninja'd!
« Last Edit: September 19, 2013, 11:32:57 am by Eiyeron »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Animated Sprites
« Reply #3 on: September 19, 2013, 11:33:17 am »
is there a way to do this other than making a bunch of animated sprites and display them individually?
The answer to this can be "yes", "no" or "it depends".

"it depends" on your animation.
If the thing you want to animate is a line, mabe you could do with a Line.

Otherwise, "no".
You don't have the choice, you have to do a bunch of sprites.

But the "yes" comes to say "no" to "individually". Don't do individual sprites with a call for each of them. Basically do a bunch of sprites, all of them right after the other in your data, then display them in a smart way so that each time you refresh the screen the frame is different. Exemple:

.AA
[]→°Sprites
[FF00000000000000]
[00FF000000000000]
[0000FF0000000000]
[000000FF00000000]
.four frames of a dumb animation

ClrDraw
0→F
While 1
 Pt-Off(0,,F+1^4→F*8+°Sprites)
 Pause 200
 DispGraph
End If getKey(15)


edit double ninja'd lol
« Last Edit: September 19, 2013, 11:34:01 am by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Axe Programmer

  • LV2 Member (Next: 40)
  • **
  • Posts: 32
  • Rating: +0/-0
    • View Profile
Re: Animated Sprites
« Reply #4 on: September 25, 2013, 11:23:57 am »
Thanks for the codes guys. But what are the blank hex after the first pic?? And how does the the pt-on(0,0,Pic1+(F*8)  work?
I have no clue what the adding or multiplying does when displaying the pic or why there are blank hex after the first hex that is stored to a pic.
please...EXPLAIN

P.S. i am knew at this..

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Animated Sprites
« Reply #5 on: September 25, 2013, 04:15:49 pm »
Axe is quite low-level. It doesn't have a picture/sprite type, the pic variables you work with are just 16-bit numbers that indicate where a sprite is located in the RAM memory of the calculator. And because they are numbers, you can do math with them. And if you store your sprites one after the other, adding 8 to it (8*8 sprites are 8 bytes large) makes it point to the 2nd sprite (starting from where you defined the variable you're working with). Adding 16 to it would give you a pointer to the 3rd sprite, and so on.
To use this in an annimation, you use a variable that starts at 0 and increases every frame. When this 'counter' variable reaches the number of frames you have, set it to 0 again BEFORE you start to work with it. Now you should have a variable that will always be between 0 and the number of frames in the annimation MINUS ONE. It is very important to count in this way in programs.
Where you display the sprite, instaed of just using the pointer (pic variable), you use for example Counter*8+Pic1. This is all there is to it. It should work now.

Extra explanation:
You might wonder now why you have to start the counter at 0, and why you have to count to one less than the number of frames. Well, this is because the pointer, Pic1 (or whatever variable you have shosen), points to the 1st frame. Adding a counter of 0, multiplied by 8 (which is still 0) to it, it still points to the 1st frame.
If your counter increases to one, counter*8+Pic1 will point to a location in RAM 8 bytes further than the first frame of the annimation, and that is exactely where the 2nd frame begins. So a counter of 1 gives you the 2nd frame. And if your pointer is 7 and you have 8 frames, than it will show you the 8th and last frame. This is why the counter is always one less than someone with no programming experience would expect.
And if you've ever worked with arrays and wondered why they started coounting from 0, it's because they work the same. The sprites stored one after the other is basically just an array of sprites.
If you don't know what arrays are, you don't have to care about them, since in axe, you don't have pre-made arrays.

I hope it's more clear to you now. If there's still something you don't understand, feel free to ask, because if you don't know exactely how code that people give to you works, you might be able to use it, but you won't be able to modify, extend and optimize it to fully suit your needs.
« Last Edit: September 25, 2013, 04:26:00 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated