This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
es:orx:tutorials:anim [2012/02/29 09:12 (13 years ago)] – [Detalles] zera | es:orx:tutorials:anim [2020/08/19 21:12 (5 years ago)] (current) – Old content sausage | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Tutorial de Animaciones ====== | ||
- | |||
- | ===== Resumen ===== | ||
- | |||
- | Veasé los anteriores [[main# | ||
- | |||
- | Este tutorial solo cubre un uso muy básico de las animaciones en orx. | ||
- | |||
- | Todas las animaciones son guardadas en [[http:// | ||
- | Este gráfico define todas las posibles transisiones entre animaciones. Una animación es referenciada usando un único caracter de cadena. Todas las transiciones y animaciones son creadas via ficheros de configuración. | ||
- | |||
- | Cuando se solicita una animación, el motor evaluará la cadena que lo traerá a esta animación desde la actual.\\ | ||
- | Si esa cadena existe, a continuación se procesará automáticamente. El usuario será notificado cuando se inician las animaciones, | ||
- | Si no especificamos ninguna animación como objetivo, el motor va a seguir los enlaces naturalmente, | ||
- | También hay una manera de saltarse este procedimiento de encadenamiento y forzar una animación inmediatamente. | ||
- | |||
- | El Código-sabio de este sistema es muy fácil de usar con dos funciones principales para manejar todo. La mayoría del trabajo se realiza no en el código, sino en los archivos de configuración cuando se definen las animaciones y enlaces. | ||
- | ((Un gráfico de animación muy básica será utilizada para este tutorial: lo hicimos a fin de mantener limitada la cantidad de datos de configuración necesarios.)) | ||
- | |||
- | ===== Detalles ===== | ||
- | |||
- | Como de costumbre, comenzamos por la carga de nuestro archivo de configuración, | ||
- | Por favor, consulte los [[Main# | ||
- | |||
- | Ahora comencemos con el codigo, veamos como organizar los datos hasta el final de esta página.\\ | ||
- | En nuestra función '' | ||
- | Cuando ninguna entrada está activa, simplemente removemos el objetivo de animación y dejamos que el gráfico sea evaluado normalmente((en nuestro caso, va a reproducir la animación de inactividad correspondiente, | ||
- | |||
- | <code c> | ||
- | { | ||
- | orxObject_SetTargetAnim(pstSoldier, | ||
- | } | ||
- | else if(orxInput_IsActive(" | ||
- | { | ||
- | orxObject_SetTargetAnim(pstSoldier, | ||
- | } | ||
- | else | ||
- | { | ||
- | orxObject_SetTargetAnim(pstSoldier, | ||
- | }</ | ||
- | |||
- | ¡Así es! Cómo se llega desde cualquier animación actual al objetivo que será evaluado usando el gráfico. Si las transiciones son necesarias se van a reproducir automáticamente ((recordar que en nuestro caso nos fuimos por el camino más recto, sin animaciones de giro, por ejemplo; pero eso no iba a cambiar nuestro código en absoluto!)). | ||
- | |||
- | //PD: Si hubiéramos querido ir inmediatamente a otra animación sin respetar las transiciones definidas por datos (en el caso de las animaciones de golpe o muerte, por ejemplo), podríamos haber hecho esto.// | ||
- | |||
- | <code c> | ||
- | |||
- | //PD: Hay mas funciones para el control avanzado de animaciones (como pausando, cambiando frecuencia, ...), pero el 99% del tiempo, esas dos funciones ('' | ||
- | |||
- | Veamos ahora como podemos estar informados de que sucede con nuestras animaciones (como sincronizar sonidos, por ejemplo).\\ | ||
- | Primero, necesitamos registrar nuestra devolución de llamada(callback) '' | ||
- | |||
- | <code c> | ||
- | |||
- | Hecho! Veamos que podemos hacer con esto ahora.\\ | ||
- | |||
- | Digamos que desea imprimir que animaciones son reproducidas, | ||
- | |||
- | <code c> | ||
- | { | ||
- | orxANIM_EVENT_PAYLOAD *pstPayload; | ||
- | |||
- | pstPayload = (orxANIM_EVENT_PAYLOAD *)_pstEvent-> | ||
- | |||
- | switch(_pstEvent-> | ||
- | { | ||
- | case orxANIM_EVENT_START: | ||
- | orxLOG(" | ||
- | break; | ||
- | |||
- | case orxANIM_EVENT_STOP: | ||
- | orxLOG(" | ||
- | break; | ||
- | |||
- | case orxANIM_EVENT_CUT: | ||
- | orxLOG(" | ||
- | break; | ||
- | |||
- | case orxANIM_EVENT_LOOP: | ||
- | orxLOG(" | ||
- | break; | ||
- | } | ||
- | |||
- | return orxSTATUS_SUCCESS; | ||
- | }</ | ||
- | |||
- | We first get the payload of our event. As we know we only handling animation events here, we can safely cast the payload to the '' | ||
- | |||
- | If we were using the same callback for different even types, we first would need to see if we were receiving an anim event. This can be done with the following code. | ||
- | |||
- | <code c> | ||
- | |||
- | Finally, our event recipient ('' | ||
- | |||
- | Let's now have a peek a the data side. | ||
- | |||
- | First, we need to define an animation set that will contain the whole graph for our specific object' | ||
- | The animation set won't ever be duplicated in memory and will contain all the animations and links for the corresponding graph.\\ | ||
- | In our case we have 4 animations and 10 possible links for all the transitions. | ||
- | |||
- | <code ini> | ||
- | AnimationList = IdleRight# | ||
- | |||
- | LinkList = IdleRightLoop# | ||
- | |||
- | Now let's define our animations! =) | ||
- | |||
- | Previous to that, so as to reduce the amount of text we need to write, we'll use orx's config system inheritance.\\ | ||
- | We'll begin to define a section for the position of our pivot ((also called '' | ||
- | As you may have seen in the [[object|object tutorial]] config file, the pivot is which position will match the world coordinate of your object in the world space. If it's not specified, the top left corner will be used by default.\\ | ||
- | The pivot can be defined literally using keywords such as '' | ||
- | |||
- | <code ini> | ||
- | Pivot = (15.0, 31.0, 0.0)</ | ||
- | |||
- | Now we'll define our graphic object that will inherit from this pivot. In our case it's a bitmap that contains all the frames for our object.\\ | ||
- | The common properties are thus the name of the bitmap file and the size of one frame ((we don't have to keep it constant, but usually it's easier for artists and it's event a constraint for some other engines/ | ||
- | |||
- | <code ini> | ||
- | Texture | ||
- | TextureSize = (32, 32, 0)</ | ||
- | |||
- | Ok, everything is setup for creating all the frames.\\ | ||
- | Let's define all our frames for both right-oriented animations: we have 6 of them. | ||
- | |||
- | <code ini> | ||
- | TextureCorner = (0, 0, 0) | ||
- | |||
- | [AnimRight2@FullGraphic] | ||
- | TextureCorner = (0, 32, 0) | ||
- | |||
- | [AnimRight3@FullGraphic] | ||
- | TextureCorner = (0, 64, 0) | ||
- | |||
- | [AnimRight4@FullGraphic] | ||
- | TextureCorner = (32, 0, 0) | ||
- | |||
- | [AnimRight5@FullGraphic] | ||
- | TextureCorner = (32, 32, 0) | ||
- | |||
- | [AnimRight6@FullGraphic] | ||
- | TextureCorner = (32, 64, 0)</ | ||
- | |||
- | As you can see, they all inherit from '' | ||
- | |||
- | Ok, now we have defined all those graphic objects (they' | ||
- | Let's begin with the '' | ||
- | |||
- | <code ini> | ||
- | KeyData1 | ||
- | KeyDuration1 | ||
- | |||
- | Easy enough, let's try the second one: '' | ||
- | |||
- | <code ini> | ||
- | DefaultKeyDuration | ||
- | KeyData1 | ||
- | KeyData2 | ||
- | KeyData3 | ||
- | KeyData4 | ||
- | KeyData5 | ||
- | KeyData6 | ||
- | |||
- | Not really harder as we define the same time for all the frames using the '' | ||
- | We can override it for any frame by specifying a key duration like we did for the '' | ||
- | |||
- | We'll do the exact same thing for the left-oriented animations. Actually as we're using flipped graphic objects, we could just have flipped the object at runtime in the code.\\ | ||
- | But that wouldn' | ||
- | |||
- | There are only the links missing now and we're done!\\ | ||
- | The basic link structure is easy: we specify the source and the destination animation. | ||
- | |||
- | <code ini> | ||
- | Source | ||
- | Destination = IdleRight</ | ||
- | |||
- | This link goes from '' | ||
- | So basically, when we are in the '' | ||
- | Also, if no target is defined when we are there, this link will keep us looping as there isn't any higher priority link starting from '' | ||
- | |||
- | Let's see now how we go from '' | ||
- | |||
- | <code ini> | ||
- | Source | ||
- | Destination = WalkRight | ||
- | Property | ||
- | |||
- | Here we have the same basic info as before but we also have the '' | ||
- | This means that when we are in '' | ||
- | |||
- | As we've seen in the code, we don't explicitely ask for the idle animation when we are already walking. How do this work then??\\ | ||
- | Let's see the link that goes from '' | ||
- | |||
- | <code ini> | ||
- | Source | ||
- | Destination = IdleRight | ||
- | Property | ||
- | Priority | ||
- | |||
- | When we are in '' | ||
- | By default a link '' | ||
- | It will bring us back to '' | ||
- | We also have added the '' | ||
- | |||
- | //NB: This is a very basic graph that shows only basic transitions, | ||
- | Let's say you want to begin walking from a sitting pause without transition.\\ | ||
- | But, later in the game development, | ||
- | You'll only have to add this extra step (with the associated links) in the config file! Your code will remain unchanged:// | ||
- | |||
- | <code c> | ||
- | ===== Recursos ===== | ||
- | |||