tommohawkaction / YoutubeTileGame

1 stars 0 forks source link

Question about Player animation #2

Closed jarlah closed 8 years ago

jarlah commented 8 years ago

Hi

Nice tuts on youtube. I was entering every piece of code off the videos. And i have made my own public repo with the code that I personally landed at.

A question. I am trying to animate walking. I crop out two pictures for left, two for right, etc etc. I make a "texture pack" which is two buffered images and in the Texture constructor (that takes an array of images) I start a thread that continously changes the currentIndex of the Texture.

As given here : https://github.com/jarlah/Tile-Game/blob/master/src/main/java/gfx/Texture.java

The question is:

How is this done correctly in "real game programming"? How can I best achieve walking animation without spawning a new thread for each texture pack? (which is cached btw). I could use a thread pool and what would happen is that if there are 60 textures with 10 enemies and what not, I could make those trees, enemies or flowers move. Without impacting much on the cpu. But the problem is I am doing something that breaks with how the game loop works. On a slower machine the threads will not be running the same way.

So maybe add this animation logic in a tick method somewhere?

jarlah commented 8 years ago

I found this link:

http://gamedev.stackexchange.com/questions/53705/how-can-i-make-a-sprite-sheet-based-animation-system

So I am closing the issue. If other wonder about this they can click the link above for info :)