Ejemplo n.º 1
0
	void Timeline::Render()
	{
		//Entity::Render();

		if (currentAnimation)
		{
			Graphics::PushMatrix();
			float lineHalfWidth = Graphics::GetVirtualWidth() * 0.9f * 0.5f;
			float y = Graphics::GetVirtualHeight() * 0.5f - 50;
			float p = currentAnimation->GetCurrentTime() / currentAnimation->GetDuration();
			Vector2 start = Graphics::GetScreenCenter() + Vector2(-lineHalfWidth, y);
			Vector2 end = Graphics::GetScreenCenter() + Vector2(lineHalfWidth, y);
			Graphics::BindTexture(NULL);
			Graphics::SetColor(Color::blue);
			Graphics::RenderLine(start, end);
			Vector2 playHead;
			float playHeadHalfHeight = 16;

			if (Debug::selectedEntity)
			{
				Graphics::SetColor(Color::orange);
				Part *part = dynamic_cast<Part*>(Debug::selectedEntity);
				if (part)
				{
					PartKeyFrames *partKeyFrames = currentAnimation->GetPartKeyFrames(part);
					if (partKeyFrames)
					{

						const std::list<KeyFrame> *keyFrames = partKeyFrames->GetKeyFrames();
						for (std::list<KeyFrame>::const_iterator i = keyFrames->begin(); i != keyFrames->end(); ++i)
						{
							playHead = (end-start) * ((*i).GetTime()/currentAnimation->GetDuration()) + start;
							Graphics::RenderLine(playHead + Vector2::up * playHeadHalfHeight, playHead + Vector2::down * playHeadHalfHeight);
						}
					}
				}
			}

			playHead = (end - start) * p + start;

			Graphics::SetColor(Color::blue);
			Graphics::RenderLine(playHead + Vector2::up * playHeadHalfHeight * 0.5f, playHead + Vector2::down * playHeadHalfHeight * 0.5f);

			Graphics::PopMatrix();
		}
	}
Ejemplo n.º 2
0
	void Puppet::Save(Entity *entity)
	{
		// save to filename
		TiXmlDocument xmlDoc;

		/// TextureAtlas
		if (textureAtlas)
		{
			textureAtlas->Save(&xmlDoc);
		}

		/// Parts
		//TiXmlElement *xmlParts = xmlDoc.FirstChildElement("Parts");
		TiXmlElement xmlParts("Parts");
		SaveParts(&xmlParts, entity);
		xmlDoc.InsertEndChild(xmlParts);


		/// Animations
		TiXmlElement xmlAnimations("Animations");
		{
			/// Animation
			for (std::list<Animation>::iterator i = animations.begin(); i != animations.end(); ++i)
			{
				TiXmlElement xmlAnimation("Animation");

				Animation *animation = &(*i);
                
                XMLFileNode xmlFileNodeKeyFrameAnim(&xmlAnimation);
				animation->Save(&xmlFileNodeKeyFrameAnim);

				/// PartKeyFrames
				for (std::list<Part*>::iterator j = parts.begin(); j != parts.end(); ++j)
				{
					PartKeyFrames *partKeyFrames = animation->GetPartKeyFrames(*j);
					if (partKeyFrames)
					{
						TiXmlElement xmlPartKeyFrames("PartKeyFrames");
						XMLFileNode xmlFileNodePartKeyFrames(&xmlPartKeyFrames);

						partKeyFrames->Save(&xmlFileNodePartKeyFrames);

						/// KeyFrame
					
						std::list<KeyFrame> *keyFrames = partKeyFrames->GetKeyFrames();
						for (std::list<KeyFrame>::iterator i = keyFrames->begin(); i != keyFrames->end(); ++i)
						{
							KeyFrame *keyFrame = &(*i);

							TiXmlElement xmlKeyFrame("KeyFrame");
							XMLFileNode xmlFileNodeKeyFrame(&xmlKeyFrame);

							keyFrame->Save(&xmlFileNodeKeyFrame);

							xmlPartKeyFrames.InsertEndChild(xmlKeyFrame);
						}

						xmlAnimation.InsertEndChild(xmlPartKeyFrames);
					}
				}

				xmlAnimations.InsertEndChild(xmlAnimation);
			}
		}
		xmlDoc.InsertEndChild(xmlAnimations);

		xmlDoc.SaveFile(Assets::GetContentPath() + filename);
	}