23.03.2012, 14:57
(
Последний раз редактировалось clavador; 27.03.2012 в 15:03.
)
TEXTDRAW ANIMATIONS 1.1
With this include you can add a little more life to your textdraws:
Click here for a quick preview!
The effects include:
- Showing textdraws in a progressive way.
- Showing textdraws growing from 0 to x.
- Showing textdraws with a pulsating effect.
So, let's see how it's done...
First, you need to copy the .inc file to your includes folder and put inside your filterscript or gamemode:
pawn Код:
#include <TextDrawAnimations>
pawn Код:
#define MAX_BUFFER 100
pawn Код:
#define MAX_BUFFER 100
#include <a_samp>
#include <TextDrawAnimations>
Once you've done that, you need to create the textdraws wich you want to apply an effect to.
You can just set the buffer to 200 and create them all at once, or you can create them dinamically and have a smaller T_Buffer array size ( later i'll show you how you can call different T_Buffer values to show certain textdraws ).
pawn Код:
#define TEXTDRAWS_ANIMATION_0 0
#define TEXTDRAWS_ANIMATION_1 1
CreateDynamicTextdraws( index )
{
switch( index )
{
case TEXTDRAWS_ANIMATION_0:
{
T_Buffer[0] = TextDrawCreate(320.000000, 130.000000, "You");
TextDrawAlignment(T_Buffer[0], 2);
TextDrawBackgroundColor(T_Buffer[0], 255);
TextDrawFont(T_Buffer[0], 1);
TextDrawLetterSize(T_Buffer[0], 1.300000, 4.000000);
TextDrawColor(T_Buffer[0], -16776961);
TextDrawSetOutline(T_Buffer[0], 0);
TextDrawSetProportional(T_Buffer[0], 1);
TextDrawSetShadow(T_Buffer[0], 1);
T_Buffer[1] = TextDrawCreate(320.000000, 160.000000, "Can");
TextDrawAlignment(T_Buffer[1], 2);
TextDrawBackgroundColor(T_Buffer[1], 255);
TextDrawFont(T_Buffer[1], 1);
TextDrawLetterSize(T_Buffer[1], 1.300000, 4.000000);
TextDrawColor(T_Buffer[1], -16776961);
TextDrawSetOutline(T_Buffer[1], 0);
TextDrawSetProportional(T_Buffer[1], 1);
TextDrawSetShadow(T_Buffer[1], 1);
T_Buffer[2] = TextDrawCreate(320.000000, 190.000000, "Animate");
TextDrawAlignment(T_Buffer[2], 2);
TextDrawBackgroundColor(T_Buffer[2], 255);
TextDrawFont(T_Buffer[2], 1);
TextDrawLetterSize(T_Buffer[2], 1.300000, 4.000000);
TextDrawColor(T_Buffer[2], -16776961);
TextDrawSetOutline(T_Buffer[2], 0);
TextDrawSetProportional(T_Buffer[2], 1);
TextDrawSetShadow(T_Buffer[2], 1);
T_Buffer[3] = TextDrawCreate(320.000000, 220.000000, "this text!");
TextDrawAlignment(T_Buffer[3], 2);
TextDrawBackgroundColor(T_Buffer[3], 255);
TextDrawFont(T_Buffer[3], 1);
TextDrawLetterSize(T_Buffer[3], 1.300000, 4.000000);
TextDrawColor(T_Buffer[3], -16776961);
TextDrawSetOutline(T_Buffer[3], 0);
TextDrawSetProportional(T_Buffer[3], 1);
TextDrawSetShadow(T_Buffer[3], 1);
T_Buffer[4] = TextDrawCreate(340.000000, 280.000000, "Or make it grow!!!");
TextDrawAlignment(T_Buffer[4], 2);
TextDrawBackgroundColor(T_Buffer[4], 255);
TextDrawFont(T_Buffer[4], 1);
TextDrawLetterSize(T_Buffer[4], 1.300000, 4.000000);
TextDrawColor(T_Buffer[4], -16711681);
TextDrawSetOutline(T_Buffer[4], 0);
TextDrawSetProportional(T_Buffer[4], 1);
TextDrawSetShadow(T_Buffer[4], 1);
}
case TEXTDRAWS_ANIMATION_1:
{
T_Buffer[0] = TextDrawCreate(340.000000, 280.000000, "Another text with effect");
TextDrawAlignment(T_Buffer[0], 2);
TextDrawBackgroundColor(T_Buffer[0], 255);
TextDrawFont(T_Buffer[0], 1);
TextDrawLetterSize(T_Buffer[0], 1.300000, 4.000000);
TextDrawColor(T_Buffer[0], -16711681);
TextDrawSetOutline(T_Buffer[0], 0);
TextDrawSetProportional(T_Buffer[0], 1);
TextDrawSetShadow(T_Buffer[0], 1);
}
}
return 1;
}
So, suppose you want to make the effects you saw on the video.
You create the textdraws first as explained, and then you use the Callback "OnAnimFinish" to control what happens after an effect ends:
pawn Код:
public OnAnimFinish( playerid, index )
{
switch( index )
{
case TEXTDRAWS_ANIMATION_0:
{
TextDraw_Grow(playerid,TEXTDRAWS_ANIMATION_1,100,2500, 0, 4, 1.3, 4.0);
}
case TEXTDRAWS_ANIMATION_1:
{
TextDraw_Pulsate(playerid,TEXTDRAWS_ANIMATION_FINISH,10,100,0,4 );
}
case TEXTDRAWS_ANIMATION_FINISH:
{
TextDraw_Hide( playerid, 0, -1 );
}
}
return 1;
}
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/anm", cmdtext, true, 10) == 0)
{
CreateDynamicTextdraws( TEXTDRAWS_ANIMATION_0 );
TextDraw_FadeIn( playerid, TEXTDRAWS_ANIMATION_0, 100, 2000, 0, 4 );
return 1;
}
return 0;
}
Now let's see each function to know what they do:
TextDraw_Grow( playerid, index, anim_speed, duration, T_Buffer_min, T_Buffer_max, Float:max_x, Float:max_y );
This one makes the text grow from 0 to X
- playerid: the player you want to show the textdraw to
- index: this is the "index" which OnAnimFinish is gonna call after the animations finishes.
- anim_speed: this is how fast the text should grow in milliseconds (the progressive size is calculated automatically).
- duration: how much time before calling OnAnimFinish should pass after the animation finishes.
- T_Buffer_min & max: this is to show certain textdraws. If you created 100 textdraws and only want to show from 17 to 25, then you need to put those numbers in there.
- float:max_x & max_y: this is how far the textdraw will grow.
This one makes textdraw appear one after another.
- playerid, index, duration, T_buffer_min & max: same as before
- speed: the speed at wich the textdraws will show in milliseconds. 1000
means 1 textdraw every one second.
This one creates a pulsating effect.
- playerid, index, speed, T_Buffer_min, T_Buffer_max: same as before:
- repetitions: how many times the text is gonna pulsate. Keep in mind that if you put "10" repetitions and the speed at "1000", that means the textdraw will show 5 times and hide 5 times.
This function hides the textdraws from min to max. Set the max parameter to -1 and it will hide every textdraw inside T_Buffer.
StopTextDrawAnimations( playerid );
You can call this one to stop any animation or timer currently running.
And that's it!
Download from PASTEBIN:
- TextDrawAnimations.inc v1.1.
- Testit.pwn ( an example showing the basic stuff ).
Bugs fixed:
- Some variables where changed after they were used and could cause unwanted behaviour.
Other:
- I'll try to add more effects later.
- I added another define: PLY_MX wich equals to MAX_PLAYERS if not defined. This is to calculate the array size of the array called T_Stuff wich handles some player data.
- Don't try to use more than one effect at a time or it will mess up, because it only uses one timer. I'll do an update soon so you can use many effects at once.