• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
PhilObyte

Sprite and Animation

6 posts in this topic

Hello,

 

I have an Animation class that has a Sprite-Array, and of course a Sprite class that defines the actual texture.

I want to have my Entity a fixed Sprite or an Animation, when getting the Sprite and an Animation has been set,

returning the current Sprite.

 

How is this easily possible? Thought of an interface "ISprite" that only has a void GetSprite(); but this looks arwful and

it would be better to have in implicit...can one define an implicit operator in an interface?

 

Thank for your help, Phil.

Edited by PhilObyte
0

Share this post


Link to post
Share on other sites

You could make an animator class that updates entity.sprite as needed.

 

Eg.

 

Sprite s;

Entity e(s);

Animator a(s);

 

while (1) do

{

a.updateSprite();

e.draw();

}

 

You would probably store a reference to the sprite in both. You can make a sprite container class and have the enity and animator store an index to the container instead.

1

Share this post


Link to post
Share on other sites

I don't get what you are asking for exactly, but I am asuming that you need to animate a Sprite.

 

From what I understand from your post, you seem to be the kind of programmer that has found OOP and thinks it is the best and most elegant solution for everything.

 

You don't need all those classes to animate a sprite. You just need an array that holds all the animation frames, and you loop over it once per main loop tick, changing the sprite's image with the one that the array index reaches. At the end of the animation just have an image that shows the sprite being idle.

 

for example, have only a Sprite class like this (pseudocode - also encompasses an animation function that goes over the frames in an array once per loop tick):

class Sprite:
    constructor::set(x,y,image,moving,frames,currentFrame,extraTime) // give it some attributes 
    assign_attributes
    {
      x = 100
      y = 100
      image = image1
      moving = False //this is a boolean that changes state when a movement key is pressed
      frames = [image1,image2,image3,image4] // array of animation frames, taken from a spritesheet
      currentFrame = 0
      extraTime = 0
    }
    function AnimateSprite(int secondsPast)
    {
       if moving == true
       {
          extraTime += secondsPast
          timeBetweenFrames = 1.0/30.0
          while (extraTime > timeBetweenFrames)
          {
             extraTime -= timeBetweenFrames
             currentFrame+=1
             if currentFrame > maxNumberOfFrames:
                currentFrame = 0
           }
           image = frames[currentFrame]
        }
        else
           image = image1
     }

           


Edited by Djfix
2

Share this post


Link to post
Share on other sites

The idea to implement animation is to have a list of images that acts as an animation strip. You can also think of it as a flip-note.

 

Have a number counter that reaches a threshold. Each threshold is used for each new image to be drawn. Once the threshold has been reached, draw the image. 

 

Once the counter has reached the threshold of the last frame of animation should be, reset the counter to zero.

 

Put the code in the draw method of your object.

Edited by warnexus
0

Share this post


Link to post
Share on other sites


From what I understand from your post, you seem to be the kind of programmer that has found OOP and thinks it is the best and most elegant solution for everything.

 

No for the animation itself I of course don't need this, and I already made an animation-class that works fine. Sorry for being unspecificially in my first post: I want my entity have a single sprite when unanimated OR an animation when animated. I could do this by giving it 2 properties, one always null. But this seems to be a rather stupid way because I'ld need to check always. Is there no way by doing it through an interface? I only want my entity to have just one property Sprite, being an Animation that returns the current sprite or a single sprite returning just itself. Anyway, thanks for your long answer. Waterlimon's answer comes near to what I want (I think), but I don't understand it quite good :)

 

Phil

0

Share this post


Link to post
Share on other sites

Although not exactly what the OP asks for, but IMHO the better solution would be to separate the existence in the world from appearance determination as follows:

 

There is a list of sprites to render. Here a spite means how to place (means position and orientation) in the world a concrete appearance of an game entity. Currently the list is filled with 2 sprites. There is another list of animations (time dependent, so need to be updated each time step). There is currently 1 animation in the list. In the game loop, call the update method of all listed animations first. This causes the animated sprites to be updated. There is 1 animated sprite in the list of sprites. Hence those is updated, while the other is left as is. Then iterate the sprite list and render each contained sprite.

 

Notice please that the sprites in the said list all show a single appearance. So an animation means to pick an appearance from an animation file and to link it to one of the listed sprites. The update mechanism just sees 1 animation, and the rendering system sees just 2 up-to-date sprites, so each system does as much work as needed without any case distinction.

 

EDIT: Forgotten to mention the key phrase "single responsibility principle" ;)

Edited by haegarr
1

Share this post


Link to post
Share on other sites

Thank you! I solved the problem with a static Animator-class. It has a List with animations.

Animations have a property "ISprite Destination;". ISprite forces a class to have a Sprite.

My Entites implement this interface. I think this is a good and not very complicated way.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0