A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [Resolved] Rainbow island

  1. #1
    Member
    Join Date
    Jul 2002
    Posts
    69
    I have a loop that reads an array from a textfile and places tiles(bitmaps) from the library into an empty movieclip on stage based on that array.

    The problem is that when the tiles are placed on the screen, they are tiled from top to bottom. I need the tiles to be tiled from bottom to top. As the height of the array is taller than the screen height, the tiles are pushed downwards (beneath the stage).

    I need the height of the array to be heigher than the screen, because I am trying to make a platformgame where the character can climb from the bottom to the top.
    See an example here (see how the background is placed to low compared to the "blueprint" in the back): http://www.choke.no/code/rainbow2.html
    (I am aware that the rest of the game does not work yet.)

    If anyone would like to have a go with the codes, here is the fla as well: http://www.choke.no/code/rainbow2.zip (The loop is located on the AS layer in frame 3).

    (I have read and studied the tutorials from Ed Mack and Outside of Society, and the game I am making is very much based on the same codes from Ed Macks Mario game.)

    I am pretty sure the problem is somewhere in these codes:

    screen_width = 570;
    screen_height = 570;

    tile_width = 30;
    tile_height = 30;

    tile_vert = screen_height/tile_height;
    tile_hort = screen_width/tile_width;

    #include "map.as"
    this.attachMovie("empty", "cont", 1);
    for (y=0; y<=tile_vert; y++) {
    for (x=0; x<=tile_hort; x++) {
    var t = "tile"+x+"_"+y;
    cont.attachMovie("tile", t, d++);
    cont[t]._y = y*tile_height;
    cont[t]._x = x*tile_width;
    cont[t].gotoAndStop(map[y][x]);

    }
    }


    Thank you all for your help in advance.

  2. #2
    Hmm... Maybe try something like this:

    for (y=tile_vert; y>=0; y++) {
    }

    The only thing with this solution is you have to change your map file so it lays out the level from bottom to top.

  3. #3
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    are you familliar with tilebased scrolling?

    well instead of scrolling righ and left simply change it for vertical scrolling

    generating it

    Code:
    visibleY=13//number of tiles to be seen on the screen 
    
    for(var y=map.length-visibleY;y<map.length;y++){
    for(var x=0;x<map[0].length;x++){
    // attach tiles
    }
    }
    just a quick soloution, if i have time, i'll look at the .fla later

  4. #4
    Member
    Join Date
    Jul 2002
    Posts
    69
    Originally posted by tornadogames.com
    Hmm... Maybe try something like this:

    for (y=tile_vert; y>=0; y++) {
    }

    The only thing with this solution is you have to change your map file so it lays out the level from bottom to top.
    Thank you for your reply.
    I tried changing the first line of the loop to what you suggest. The result was an endless loop. Here is what I did:

    for (y=tile_vert; y>=0; y++) {
    for (x=0; x<=tile_hort; x++) {
    var t = "tile"+y+"_"+x;
    cont.attachMovie("tile", t, d++);
    cont[t]._y = y*tile_height;
    cont[t]._x = x*tile_width;
    cont[t].gotoAndStop(map[y][x]);

    }
    }

    I also tried to change both outer and inner loop with the same result:
    for (y=tile_vert; y>=0; y++) {
    for (x=tile_hort; x<=0; x++) {
    var t = "tile"+y+"_"+x;
    cont.attachMovie("tile", t, d++);
    cont[t]._y = y*tile_height;
    cont[t]._x = x*tile_width;
    cont[t].gotoAndStop(map[y][x]);

    }
    }

    Note! I didn't change the map file, so that might be the reason it did not work...I am not sure how to change it like you suggest. Could you or anyone else point me in the right direction?

    Thank you in advance!

  5. #5
    Member
    Join Date
    Jul 2002
    Posts
    69
    Originally posted by token 3
    are you familliar with tilebased scrolling?

    well instead of scrolling righ and left simply change it for vertical scrolling

    generating it

    Code:
    visibleY=13//number of tiles to be seen on the screen 
    
    for(var y=map.length-visibleY;y<map.length;y++){
    for(var x=0;x<map[0].length;x++){
    // attach tiles
    }
    }
    just a quick soloution, if i have time, i'll look at the .fla later

    Thank you for your reply.
    I have studied some tilebased scrolling, but I do not quite get it yet. If you know of any good tutorials, please send me some links. I also appreciate tutorials about loops and arrays in general:-)

    I tried using your loop instead of mine, the result is the same as it is now. Perhapps I did something wrong. Here is what I did:

    visibleY=13//number of tiles to be seen on the screen


    #include "map.as"
    this.attachMovie("empty", "cont", 1);
    for(var y=map.length-visibleY;y<map.length;y++){
    for(var x=0;x<map[0].length;x++){
    var t = "tile"+y+"_"+x;
    cont.attachMovie("tile", t, d++);
    cont[t]._y = y*tile_height;
    cont[t]._x = x*tile_width;
    cont[t].gotoAndStop(map[y][x]);

    }
    }


    Perhapps it is posible to set the y-starting point somehow? The same way as you set the visibleY=13? I have tried some experimenting with this, but without any luck so far. I have managed to change the position of the entire stage, and the entire movieclip with everything, but not with just the tiles.

    It would be great if you have time to look at the fla. But any help at all is appreciated:-)

    Thank you in advance!

  6. #6
    Doh! I forgot the most important part

    OK, it will work now...

    for (y=tile_vert; y>=0; y--) {
    }

    If you increment y instead of decrement, the loop will never break out of the loop.

    Sorry about that.

  7. #7
    Member
    Join Date
    Jul 2002
    Posts
    69
    Originally posted by tornadogames.com
    Doh! I forgot the most important part

    OK, it will work now...

    for (y=tile_vert; y>=0; y--) {
    }

    If you increment y instead of decrement, the loop will never break out of the loop.

    Sorry about that.
    That's allright:-)But I am afraid the result is exactly as with the original codes. You said something about changing the array in the text-file. Perhapps that is the solution? I was wondering if you have time to give me a clue how to change it?

    Now the array looks something like this:
    map = [[9,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50, 50,9], [9,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,21, 50,9],
    [9,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,21, 50,9],
    .....and so on, untill the last line: [10,15,15,17,50,15,15,15,15,15,15,15,15,15,50,17,15 ,15,10]];

    Thank you in advance:-)

  8. #8
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    right, i downloaded your files, but haven't had a proper look at them yet, so i quickly made this file up

    http://www.token3.com/test/rainbow.fla
    http://www.token3.com/test/rainbow.swf

    up/down arrow keys to scroll

    it is only scrolling, i didn't add a character as you already have that, the code is mx, so i'm hoping thats what you use, if you need it in flash 5 syntax just shout out and i'll get it done as soon as possible

    mike

  9. #9
    Member
    Join Date
    Jul 2002
    Posts
    69
    Originally posted by token 3
    right, i downloaded your files, but haven't had a proper look at them yet, so i quickly made this file up

    http://www.token3.com/test/rainbow.fla
    http://www.token3.com/test/rainbow.swf

    up/down arrow keys to scroll

    it is only scrolling, i didn't add a character as you already have that, the code is mx, so i'm hoping thats what you use, if you need it in flash 5 syntax just shout out and i'll get it done as soon as possible

    mike
    Thank you for your help, but I have just started to learn about prototypes, so I am afraid this was all very new to me. If you've got the time, it would be great if you wrote the code in a similar fashion to how I have done the looping so that I better can understand it. (If that is posible of course.) By the way, I have the scrolling under control, so don't think about that. It is just the placement of the tiles in the loop that troubles me:-|

    Thanks in advance:-)

  10. #10
    Member
    Join Date
    Jul 2002
    Posts
    69

    Thank you

    I have solved the problem I think. It is sort of an "easy" way out, but it works...

    I juste used this syntax: cont._y = -120;
    This moves the entire movieclip upwards until it is on its right location. When I add more horizontal arrays, I will just increase this number. Also I need to reposition the character (and pickups and enemies) as I increase the number. It is not exactly a smart solution, but it works for me. But please, if anyone have a better solution, do tell:-)

    Thank you all very much for your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center