• 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
jjwooyoung

How are sprite/images used to associate with a character?

5 posts in this topic

I'm trying to create a small game as a learning tool and wasn't really sure how to handle images.. Usually when developing a game (small, large, etc), how are the images associated with a certain character/class?

 

Like for example, a player chooses the hero type1 character and the image associated with that appears. How is this done in coding?

0

Share this post


Link to post
Share on other sites

You can do it however way you want, within the confines of programming, math and your time. No, that doesn't tell you much, but let's just begin by saying that there's alot of ways good and bad, established and novel that could result in an apparent connection between a sprite and a character. Apparent, as in apparent to you, or anyone else playing.

 

You could:

1. Have hero sprites and heroes. Very specific programming, but straightforward too. Heroes can select a specific hero sprite, so that when you render heroes, you select the hero sprite from an index provided by the hero. (index into an array)

2. Have the heroes be able to link directly to a sprite, and the sprite can draw itself. (reference / pointer)

3. Have the heroes be able to draw themselves, creating a draw() member function. (draw() member function)

4. Have the heroes inherit drawing capabilities, which you override and implement, enabling them to draw themselves. (draw() inherited from Drawable class)

5. Same as #4, except you are running a script instead, allowing both you and your colleagues/team to manage many aspects from the outside using a simple text-editor.

and so on smile.png

It's not a complete list, but I tried to cover the most common ways.

 

Number #3 and #4 is very common.

 

Assosciation example:

A hero could have all the information needed both directly and indirectly, forming a decently well-encapsulated class.

The hero class itself contains information needed to identify specifics about the character.

Let's have Hero inherit from Drawable, telling us that this hero can in fact be drawn, on a screen. All it means is that you promise that your hero can be drawn on a screen.

That way we can have a custom hero class, say KnightHero which inherits the draw() call, and write his draw() function which has access to all KnightHeros information.

Now that draw() function needs to be implemented in such a way that the hero is represented on screen. :)

 

In your renderer, you can now add KnightHero to a list of candidates that can be drawn. Loop through that list and simply call draw().

That is the basic OOP ways, I believe.

 

A sprite is just an image, that you can place on screen. It can be super-small, or be the background itself. It could also be an animated character. As such, it is only a concept, and you must implement using programming somehow.

Edited by Kaptein
1

Share this post


Link to post
Share on other sites

The image is stored in the character class, loaded, and printed. The pseudo-code.

class Character(object):

    def __init__(self, image, position):
        self.image = image
        self.position = position

    def render(self):
        # Draw the image on the character's location.
        drawing_function(self.image, self.position)

    def update(self):
        # Do some stuff like updating the character's location, etc.
        some_functions()
        self.render()

# The instantiation.

hero = Character('images/hero_img.png', (29, -36))

# The game loop.
while 1:
    hero.update()

Basically it's how it's done. In the OOP sense, it's said, "Character has an image." The character is updated every game loop, and while updating, it also draws itself on the screen. That said, the hero might be walking, and it has its position changed every second, and it needs to draw itself accordingly.

 

Sometimes the image file is loaded first and then passed to the object so you won't have to re-load the file every game loop, or you can load the file during the instantiation. Whatever, really. The image paths can be stored in database, files, etc, and usually a character has more than one images for various states it has, like idle, dying, attacking, and casting spells. Well, even a state might need more than one image, like when your character is attacking, it needs a series of images to make the attacking animation.

 

The idea is that the character has some images and position, and they're drawn onto the screen according to their position. The image drawn is determined by the character's current state (dying, attacking, etc), so you can set the character class to have an array of images, and a current_image variable.

0

Share this post


Link to post
Share on other sites
Just have ur hero object have a x and y position. When time comes to draw ur image just draw it at the hero's x and y position.
0

Share this post


Link to post
Share on other sites

 

I'm trying to create a small game as a learning tool and wasn't really sure how to handle images.. Usually when developing a game (small, large, etc), how are the images associated with a certain character/class?

 

Like for example, a player chooses the hero type1 character and the image associated with that appears. How is this done in coding?

 

 

The player is an object  with a set of data

 

The icon is a lump of data (also an object) which can be identified with a pointer pointing to it

It is one of a number of icons, which will be associate to a player with a certain type (usually identified as an ordinal value)

 

You can do this statically --  on creation of the player some value/variable will determine the players 'type' and the matching icon will be

looked up from a table of 'player types) and the pointer to the correct icon will be added to the player 'object' for later use

 

When rendered in the game the drawing code will get the player type icon pointer  from the player object and use it for drawing

 

 

A dynamic mechanis may be where some other player attibute  is used to display variations of the player icon  (like being injured, or dead, or with some modal state like being on foot vs being on horseback).  Variables in the players object will determine whjich icon variation should be displayed and it either can be determined every cycle using if-then logic  or only when it is changed (I get off a horse then the code as part of that action changes my icon back to 'on-foot' and sets my current icon pointer)

 

Each of those different states would have their own different icon data, and the list of all player icons would have added organization to contain the pointers to the icon data  representing each of those different looks selectable for the player (elf/dwarf/human/orc)  each with its list of pointers to (on-foot, on-horse,injured,dead,etc...).

If you have 10 different 'base' faces and 10 variations (matching the state/modes for each) then the program would need to have loaded 100 different icons to be able display all those variations.

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