Skocz do zawartości

Rekomendowane odpowiedzi

Opublikowano

Już na początku napisze że pracuje w GM 5.0 bo jak ostatnio zauważyłem to właąnie jest ważne.

 

Pisze np. taki kod:

Kod:

w stepie:

GML
if keyboard_check (vk_left)

{

x-=2

sprite_index=spr_krasnalud_lewo;

image_single=-1;

image_speed=0.02;

ruch=3

}

W release <left>

GML
sprite_index = spr_krasnalud_stoi

image_single =2

 

 

jak łatwo się domyśleć jest to kod na chodzenie i gdy puszcza sie lewa strzalke postac sie zatrzymuje i zmnienia sprita na stojacego. Chodzi mi teraz o to że jak np. ide to chodzi mi animacja i jest ok. Pózniej puszczam i sie zatrzymuje i tez jest super. I jak znowu ide w lewo to kontynułuje poprzednią nieskończoną animacje, zamiast zaczac animowac od poczatku i to mi nie pasuje. Jak temu zaradzić?

Opublikowano

Dlaczego w tym kodzie w stepie dajesz image_single=-1?

 

Co to ma robić w GM5?

Bo gdyby to działało jak image_index z nowszym GM to ci ta animacja się w ogóle nie powinna odtwarzać, bo co chwilę jest klatka na -1 ustawiana.

 

Najlepiej pokaż wycinek z helpa dotyczący image_single.

 

EDIT: I używaj w postach tagów GML. Poprawiłem ci :P

Opublikowano

Nic nie zrozumiałem z tej wypowiedzi.

 

Wklej wycinek z helpa mówiący o image_single.

 

I spróbuj coś takiego:

GML
if keyboard_check (vk_left)

{

x-=2

if(sprite_index!=spr_krasnalud_lewo)

{

sprite_index=spr_krasnalud_lewo;

image_single=0;

image_speed=0.02;

}

ruch=3

}

Opublikowano

Czy ty rozumiesz co ja do ciebie mówię?!

Dajże opis image_single z helpa, bo najwyraźniej działa inaczej niż image_index. Trzeci raz kurde powtarzam :/

Opublikowano

image_index When the image has multiple sub-images the program cycles through them. This variable indicates the currently drawn sub-image (they are numbered starting from 0). You can change the current image by changing this variable. The program will continue cycling, starting at this new index.

 

image_single Sometimes you want a particular sub-image to be visible and don't want the program to cycle through all of them. This can be achieved by setting this variable to the index of the sub-image you want to see (first sub-image has index 0). Give it a value –1 to cycle through the sub-images. This is useful when an object has multiple appearances. For example, assume you have an object that can rotate and you create a sprite that has sub-images for a number of orientations (counter-clockwise). Then, in the step event of the object you can set

 

{

 

image_single = direction * image_number/360;

 

}

 

o to ci chodziło?

Opublikowano

Ach, wiec one zupełnie inaczej działają.

A więc:

image_index ustawia aktualnie wyświetlaną klatkę animacji. A animacja się odtwarza dalej od tej klatki.

 

image_single z tego co zrozumiałem jakby olewa animację i wyświetla wciąż tę jedną klatkę.

 

Olej to image_single i nie używaj. Można się bez tego obyć. Nie jest potrzebne.

 

Zrób tak:

Setp:

GML
if keyboard_check (vk_left)

{

x-=2;

ruch=3;

}

 

W pressed<left>

GML
sprite_index=spr_krasnalud_lewo;

image_index=0;

image_speed=0.02;

 

W release <left>

GML
sprite_index = spr_krasnalud_stoi;

image_index=2;

image_speed=0;

Opublikowano

Zostawmy najlepiej ten kod co dalem w pytaniu, poniewaz dziala dobrze. Chodzi mi o to, gdy ide raz do przodu topokazuje sie animacja, ale juz jak znowu ide do przodu to kontynuuje ta animacje poprzednia zamiast zaczac od nowa.

Opublikowano
Platyna, jak nastawisz image_single na -1 odtwarza ci animację.

No ale na kiego grzyba tego używać jak okazuje się że w GM5 jest zwykłe image_index.

 

kkamil, a próbowałeś ten ostatni kod co ci dałem?

Opublikowano

boom: problem w tym, że jak image_single ma jakąkolwiek inną wartość niż -1, animacja zatrzymuje się.

 

image_single TO NIE image_index

  • Administratorzy
Opublikowano

Napisać w tej kolejności:

GML
image_index=0;

image_index=-1;

 

Ustawisz klatkę na pierwsza, a potem włączysz ponownie animację :) ( tylko nie pamiętam, czy image_index czy image_single, bo to GM5 )

  • Administratorzy
Opublikowano

Guzik prawda. Dokumentacja GM5 jasno mówi:

 

sprite_index This is the index of the current sprite for the instance. You can change it to give the instance a different sprite. As value you can use the names of the different sprites you defined. Changing the sprite does not change the index of the currently visible sub-image.

 

image_index When the image has multiple sub-images the program cycles through them. This variable indicates the currently drawn sub-image (they are numbered starting from 0). You can change the current image by changing this variable. The program will continue cycling, starting at this new index.

 

image_single Sometimes you want a particular sub-image to be visible and don't want the program to cycle through all of them. This can be achieved by setting this variable to the index of the sub-image you want to see (first sub-image has index 0). Give it a value ?1 to cycle through the sub-images. This is useful when an object has multiple appearances. For example, assume you have an object that can rotate and you create a sprite that has sub-images for a number of orientations (counter-clockwise). Then, in the step event of the object you can set

GML
{

image_single = direction * image_number/360;

}

 

image_index - przejdź do klatki, ale nadal animuj całość

image_single - przejdź do klatki i pozostaw ją na stałe (lub ustaw -1 aby wznowić animację).

  • Administratorzy
Opublikowano

Poczekaj 15 minut :) Edytuję tego posta i dodam :)

 

 

Edit: proszę bardzo: https://gmclan.org/up23_3_test_gm5.html

 

Jeszcze prościej jest to zrobić, wycinając te if sprite_index całkowicie, a kod który znajduje się pomiędzy klamerkami dac odpowiednio do key_pressed i key_released w eventach obiektu :)

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...