How do you deal with multiple assets for different objects?

Started by
2 comments, last by Aressera 9 months, 1 week ago

I'm trying to wrap my head around how you'd deal with multiple sprites for different objects. I'm using an asset pack that includes 4 different characters each character has 6 sprite sheets so one of my goals are to make a player that uses a different character every time they respawn. The solution I had in mind was to be able to choose character and then I'd have access to their sprites so I made a map that kind of does this and overall I don't think it was a bad attempt I think I managed to do what I wanted it's just not very good I'd imagine having a giant map for everything (enemies, coins, other stuff) is going to become rough to manage.

std::map<CharacterType, std::pair<std::map<SpriteState, std::string>,  std::map<SpriteState, int>>> characterConfig = {
	{CharacterType::NINJA_FROG, {
		{
			{SpriteState::IDLE, "source/resources/animations/player/Ninja Frog/Idle (32x32).png"},
			{SpriteState::RUN, "source/resources/animations/player/Ninja Frog/Run (32x32).png"},
			{SpriteState::JUMP, "source/resources/animations/player/Ninja Frog/Jump (32x32).png"},
		},
		{
			{SpriteState::IDLE, 11},
			{SpriteState::RUN, 12},
			{SpriteState::JUMP, 1},
		}
	}},
	// Other characters
};
Entity& createPlayer(Manager& manager, Graphics& graphics, int x, int y, CharacterType characterType) {
	auto& player(manager.addEntity());

	auto& position(player.addComponent<PositionComponent>(x, y));
	auto& velocity(player.addComponent<VelocityComponent>());
	auto& sprite(player.addComponent<AnimatedSpriteComponent>(graphics, characterType));
	auto& physics(player.addComponent<PhysicsComponent>());


	return player;
}

	Entity& player = createPlayer(manager, graphics, 100, 100, CharacterType::NINJA_FROG);
	// OR
		Entity& player = createPlayer(manager, graphics, 100, 100, CharacterType::SOMEONE_ELSE);

Advertisement

Bigger games tend to switch from hard-coded assets to rule-based data driven approaches. You can have any number of data sets in the files, built together by mappings in other data. Often there are people whose entire job is about managing the assets, with character designers and level designers or combat system designers who spend their days experimenting, playing with numbers, balancing, and extending the system to as many varieties that artists and programming can offer. Think like Lego blocks, ten or so basic blocks can be used in many ways to build complex creations.

If you are doing it yourself you need to switch between the various hats. With your programmer hat on, build up trees of behavior / actions, and let them run from adjustable parameters in code. With your artist hat on, build useful parts that can be composed and combined. With your designer hat on, look for everything that can be reused and recombined and customized.

frob said:
Think like Lego blocks, ten or so basic blocks can be used in many ways to build complex creations.

@frob I'd be curious if you could provide some examples of these to help make things more concrete.

This topic is closed to new replies.

Advertisement