Exercice en Pawn - Avancй
#12

La fonction :

Code:
/*
    Description : Permet de deplacer un textdraw en fonction de l'angle choisi.

    td : le textdraw
    X, Y : Positions initiales du textdraw
    Angle : Angle de deplacement en degrй
    Vitesse : Vitesse de deplacement
*/

forward MoveTextdrawAngle(Text:td, &Float:X, &Float:Y, Float:Angle, Float:Vitesse);
public MoveTextdrawAngle(Text:td, &Float:X, &Float:Y, Float:Angle, Float:Vitesse)
{
    X += floatcos(Angle, degrees)*Vitesse ;
    Y += floatsin(Angle, degrees)*Vitesse ;

    TextDrawSetPos(td, X, Y);

    return 1;
}

Expliquation :

C'est trйs simple, il faut juste calculer le cosinus et le sinus de l'angle du dйplacement et l'ajouter aux positions du textdraw sans oublier de le multiplier avec la vitesse. Une fois ceci fait, on met au textdraw sa nouvelle position avec TextDrawSetPos disponible dans YSF.

Utilisation :

Voici un script qui permet de dйplacer un textdraw avec le clic droit de la souris :

D'abords les variables et leurs initialisation :

Code:
new Text:SUNAXX;
new Float:SUNAXXPOS[2];

public OnGameModeInit()
{
    SUNAXXPOS[0] = 100.0; SUNAXXPOS[1] = 100.0;

    SUNAXX = TextDrawCreate(SUNAXXPOS[0],SUNAXXPOS[1],"SUNAXX");

    return 1;
}

Puis un timer qui va tester tout les 0.05sec si le joueur clique bien sur 'KEY_FIRE' pour deplacer le textdraw ensuite.


Code:
forward MoveTextdrawUpdate(playerid);
public MoveTextdrawUpdate(playerid)
{
    new Keys,ud,lr;
    GetPlayerKeys(playerid,Keys,ud,lr);

    if(Keys == KEY_FIRE)
    {
        MoveTextdrawAngle(SUNAXX, SUNAXXPOS[0], SUNAXXPOS[1], 60.0, 8.5);
        TextDrawShowForPlayer(playerid, SUNAXX);
    }

    return 1;
}

CMD:ok(playerid, params[])
{
      SetTimerEx("MoveTextdrawUpdate", 50, true, "i", playerid);

      return SendClientMessage(playerid, -1, "Clic droit pour deplacer le textdraw!");
}

Voila !
Reply


Messages In This Thread
Exercice en Pawn - Avancй - by Dutheil - 16.04.2015, 20:40
Re : Exercice en Pawn - Avancй - by Z3N0N - 16.04.2015, 21:03
Re : Exercice en Pawn - Avancй - by Ivory - 17.04.2015, 15:01
Re : Exercice en Pawn - Avancй - by Dutheil - 17.04.2015, 15:16
Re : Exercice en Pawn - Avancй - by Ivory - 17.04.2015, 16:06
Re : Exercice en Pawn - Avancй - by Chipardeur - 17.04.2015, 16:17
Re : Exercice en Pawn - Avancй - by Ivory - 17.04.2015, 16:19
Re : Exercice en Pawn - Avancй - by Dutheil - 17.04.2015, 16:31
Re : Exercice en Pawn - Avancй - by Ivory - 17.04.2015, 18:52
Re : Exercice en Pawn - Avancй - by TheWWorld - 19.04.2015, 11:18
Re : Exercice en Pawn - Avancй - by Vukilore - 19.04.2015, 11:31
Re : Exercice en Pawn - Avancй - by Sunaxx - 22.04.2015, 18:50
Re : Exercice en Pawn - Avancй - by MrAlexisX2 - 24.04.2015, 12:19
Re : Exercice en Pawn - Avancй - by TheWWorld - 27.04.2015, 17:44
Re : Exercice en Pawn - Avancй - by nicolaskettler - 03.05.2015, 22:45
Re : Exercice en Pawn - Avancй - by nicolaskettler - 03.05.2015, 22:47
Re : Exercice en Pawn - Avancй - by S4t3K - 04.05.2015, 09:31
Re: Exercice en Pawn - Avancй - by Noliax8 - 04.05.2015, 09:36
Re : Exercice en Pawn - Avancй - by S4t3K - 04.05.2015, 09:40
Re : Exercice en Pawn - Avancй - by Chipardeur - 04.05.2015, 23:38
Re : Exercice en Pawn - Avancй - by S4t3K - 05.05.2015, 12:42
Re : Exercice en Pawn - Avancй - by Ivory - 05.05.2015, 14:46
Re : Exercice en Pawn - Avancй - by S4t3K - 05.05.2015, 15:08
Re : Exercice en Pawn - Avancй - by Ivory - 05.05.2015, 17:09
Re : Exercice en Pawn - Avancй - by Chipardeur - 06.05.2015, 02:12
Re: Exercice en Pawn - Avancй - by TheArrow - 06.05.2015, 07:34
Re : Exercice en Pawn - Avancй - by Ivory - 06.05.2015, 08:42
Re : Exercice en Pawn - Avancй - by S4t3K - 06.05.2015, 14:18
Re : Exercice en Pawn - Avancй - by Ivory - 06.05.2015, 15:35
Re : Exercice en Pawn - Avancй - by Dutheil - 20.05.2015, 19:25
Re : Exercice en Pawn - Avancй - by S4t3K - 06.11.2015, 10:29
Re : Exercice en Pawn - Avancй - by S4t3K - 08.11.2015, 15:36

Forum Jump:


Users browsing this thread: 1 Guest(s)