[actionscript] zapisywanie mapki


#1

witam,

mam pytanie. robię sobie edytor mapek do jednej gry (tzn. układanie z obrazków mapy po której w grze można chodzić :slight_smile: ). No i teraz kiedy skończyłem wszystko przydałoby się to zapisać.

musi być to w takiej postaci:

var MojaMapa:Array = new Array(

	   new Array("2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2"),

       new Array("2","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","2"),

       new Array("2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2"),

       new Array("2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2"),

       new Array("2","0","0","0","0","0","0","0","0","2","2","2","2","2","2","0","0","2"),

       new Array("2","0","0","0","0","0","0","0","4","0","0","0","0","0","2","6","0","2"),

       new Array("2","0","0","0","0","0","0","0","3","0","0","0","0","0","2","0","0","2"),

	   new Array("2","0","0","0","0","0","0","0","0","1","1","1","1","1","2","0","0","2"),

       new Array("5","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2"),

       new Array("2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2"),

       new Array("2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2"),

       new Array("2","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","2"),

	   new Array("2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2","2")

    );

//inne współrzędne obiektów

no i myślę żeby to zmieścić do zmiennej (raczej nie do pliku txt bo umieszczę to na stronie WWW) tyle że jak? Trzeba wziąć pod uwagę to, iż potem kod w tej zmiennej potem będę wykorzystywał i musi być to w postaci tablicy i zmiennych.

Wie ktoś jak zapisać linijka po linijce całość do zmienej?


(Damgora) #2

jeśli chodzi Ci o zapisanie tego do dwuwymiarowej tablicy to można to zrobić tak:

w dwóch zagnieżdżonych pętlach for

var MojaMapa:Array;

for (var i=0; i
    for (var j=0; j
        MojaMapa[i][j]=dane;

albo na siłę w jednej (nie jestem pewny czy zadziała w AS)

var MojaMapa:Array;

for (var i=0, j=0; i
    MojaMapa[i][j]=dane;

a jeżeli masz na myśli przepisanie takiej tablicy do pojedynczej zmiennej np. stringa to możesz użyć metody join

var mapa:String = "";

for (var i=0; i
    mapa += MojaMapa[i].join(".")+",";

mapa = mapa.slice(0, -1);

potem można to rozdzielić metodą split


#3

ok, udało mi się zapisać to do zmiennej.

Istnieje tylko jeden problem :roll: Jak kod z tej zmiennej wykonać. Czyli chciałbym wszystkie tablice i funkcje w zmiennej użyć (w moim przypadku "testuj poziom")


#4

potrex , proszę zapoznaj się z tą stroną oraz tym tematem, a następnie popraw tytuł tematu, używając przycisku ac7a4cd89050aa6e.gif


(flaszer) #5

Dlaczego odrzuciłeś pomysł zapisu mapy do pliku tekstowego? IMHO sposób ten jest dobry i sprawdzony, miejsca na FTP przecież Ci nie ubędzie :wink:


#6

flaszer , czyli mówisz że nie będzie to jakoś sprawiało problemu?

Mam kilka pytań na których odpowiedź nie znalazłem albo były nie o tym co chciałem:

Jak (jaką komendą) zapisuje się tekst do pliku tekstowego? Dajcie mi chociaż nazwę funkcji to sobie w helpie poszukam.

Jak już zapiszę to w pliku tekstowym to jak tego potem użyć (u mnie przetestować poziom)?

Z góry dzieki za odpowiedź O:)

EDIT: jeszcze jedno ^^

czy jak robię te wszystkie pliki .txt, .as. itp. to one wszystki będą zawarte w jednym pliku swf gry, czy będę musiał za każdym razem kopiować wszystkie te pliki?