Icetray: Your reply.

This piece-of-shit messageboard only allows 10 replies per thread.



Anyway, the easy way to scroll your tile system pixel-per-pixel is to simply change the offset you blit each tile to. So if you're moving one pixel over from the "normal" tile position, you simply add 1 to the X location you blit your tile to.



Remember to reset the offset back to zero and shift which tiles you reference one over once you've returned to the offset that is equal to the width of your tiles.



I could probably provide an example (Allegro) if needed (I haven't programmed one, but I can do it real quick).



-Xotor-


Comments

  • Hmm, Im a tiny bit confused, lemme kind of map out how my tile system works and then maybe you can explain through that.



    First off I create a structure in my main.h

    typedef struct IMAGE

    {

    Point location;

    short width;

    short height;

    short imageID[3];

    }IMAGE;

    This defines all of the tile info.

    Next I have a sequence to load in each of my tiles:

    dpSetWindow(OFFSCREEN);

    String BFname = "Data/World1.txt";



    bg.location = dpMakePoint(x, y);

    bg.width = 32;

    bg.height = 32;

    bg.imageID[1] = dpLoadImage(1, BFname);

    bg.imageID[2] = dpLoadImage(2, BFname);

    bg.imageID[3] = dpLoadImage(3, BFname);



    /*Destination bounds */

    bgDest = dpMakeRect(bg.location.h,

    bg.location.v,

    bg.location.h + bg.width,

    bg.location.v + bg.height);

    Once I loaded in each of the bitmaps with a number (1,2,3) I made a world[15][30] array for the tile locations.



    then my loop looked a little bit like this.



    while(!Done2)

    {

    //when the array is done end the loop

    if ((width == y1-1) && (height== x1-1))

    Done2 = true;

    worlds();

    //loop to set up the tiles



    //stops program from placing tiles past the array's limit

    if ((bgDest.right>widthofscreen) && (bgDest.bottom<480))<br>
    {

    bgDest.top +=sizeoftiles;

    bgDest.bottom +=sizeoftiles;

    bgDest.left =0;

    bgDest.right =32;

    }



    //stops the array from going past it's limit

    if ((width==y1) && (height
    {

    width = 0;

    height++;

    }



    drawbackground();



    //increments by tiles_size

    width++;

    bgDest.left +=tiles_size;

    bgDest.right +=tiles_size;



    //Wait(30);

    }





    This may not make any sense since you have probably not used the library, but I tried, and hopefully you have seen something similar. If not that is allright, I can probably figure out your answer through comparin Allegro to my library file.



    Thanx again Xotor, and yeah this messageboard really sucks.




  • Oh wait I think I understand what you mean. I wasn't reading carefully enough, I think i will give it a try. So just to set it straight say I begin the tiles all at point x, whenever my character moves 1 pixel right Ill place the tile a x-1 there original placement.


  • Here is some pseudocode:



    typedef struct Tile_t

    {

    int nImageIndex; // Points to whatever image you're using.

    }

    Tile_t



    main loop:



    //Let's assume that you want to scroll one pixel to the right and want your tiles to move one pixel to the right instead of a whole tile.



    X_Offset = 1; // Because you want to move one pixel more.



    Y_Offset = 0; // The Y doesn't change in this instance.



    for each tile:



    // Blit (dest, source, X, Y, Width, Height);



    blit ( Screen, image[Tile[x,y].nImageIndex], Tile[x,y].X + X_Offset, Tile[x,y].Y + Y_Offset, image[Tile[x,y].nImageIndex].width, image[Tile[x,y].nImageIndex].height);







    Now you will have to account for setting the offset back to 0 and setting the full tile offset over by one once you've moved an entire tile-width over so you don't run up a huge offset number.



    -Xotor-



    : Hmm, Im a tiny bit confused, lemme kind of map out how my tile system works and then maybe you can explain through that.

    :

    : First off I create a structure in my main.h

    : typedef struct IMAGE

    : {

    : Point location;

    : short width;

    : short height;

    : short imageID[3];

    : }IMAGE;

    : This defines all of the tile info.

    : Next I have a sequence to load in each of my tiles:

    : dpSetWindow(OFFSCREEN);

    : String BFname = "Data/World1.txt";

    :

    : bg.location = dpMakePoint(x, y);

    : bg.width = 32;

    : bg.height = 32;

    : bg.imageID[1] = dpLoadImage(1, BFname);

    : bg.imageID[2] = dpLoadImage(2, BFname);

    : bg.imageID[3] = dpLoadImage(3, BFname);

    :

    : /*Destination bounds */

    : bgDest = dpMakeRect(bg.location.h,

    : bg.location.v,

    : bg.location.h + bg.width,

    : bg.location.v + bg.height);

    : Once I loaded in each of the bitmaps with a number (1,2,3) I made a world[15][30] array for the tile locations.

    :

    : then my loop looked a little bit like this.

    :

    : while(!Done2)

    : {

    : //when the array is done end the loop

    : if ((width == y1-1) && (height== x1-1))

    : Done2 = true;

    : worlds();

    : //loop to set up the tiles

    :

    : //stops program from placing tiles past the array's limit

    : if ((bgDest.right>widthofscreen) && (bgDest.bottom<480))<br>
    : {

    : bgDest.top +=sizeoftiles;

    : bgDest.bottom +=sizeoftiles;

    : bgDest.left =0;

    : bgDest.right =32;

    : }

    :

    : //stops the array from going past it's limit

    : if ((width==y1) && (height
    : {

    : width = 0;

    : height++;

    : }

    :

    : drawbackground();

    :

    : //increments by tiles_size

    : width++;

    : bgDest.left +=tiles_size;

    : bgDest.right +=tiles_size;

    :

    : //Wait(30);

    : }

    :

    :

    : This may not make any sense since you have probably not used the library, but I tried, and hopefully you have seen something similar. If not that is allright, I can probably figure out your answer through comparin Allegro to my library file.

    :

    : Thanx again Xotor, and yeah this messageboard really sucks.

    :

    :






  • Cool, I think I understand heh, I will give it a try. One thing. I have an int leftins that starts out at 0 and I made a function for when a key is pressed it is supposed to do leftins--, but for some reason when I subract 1, the number of leftins becomes something like -101239, usually this happens when a number goes past its limits, but I am pretty sure an integer can handle a-lot.


  • : Cool, I think I understand heh, I will give it a try. One thing. I have an int leftins that starts out at 0 and I made a function for when a key is pressed it is supposed to do leftins--, but for some reason when I subract 1, the number of leftins becomes something like -101239, usually this happens when a number goes past its limits, but I am pretty sure an integer can handle a-lot.



    Maybe you're changing the pointer's location value rather than the actual value. If it was overlapping (which is wouldn't) you'd get a value like -2 billion or something not that number.



    -Xotor-


  • umm this isnt a pointer it is just a regular old integer.


  • : umm this isnt a pointer it is just a regular old integer.



    Still, you may check it, since you are modifying it within a function you may have gotten it mixed up. I've done it before.



    -Xotor-






  • Hmm, well I fixed it, Im not quite sure why it was fixed but it is working. And the beginning of my scrolling routine is going pretty well though it is a bit slow.


  • : Hmm, well I fixed it, Im not quite sure why it was fixed but it is working. And the beginning of my scrolling routine is going pretty well though it is a bit slow.



    If you are using Allegro, or something like that, you can draw textured polygons using textures. That way you can draw a polygon as your background instead of individual tiles.



    Just a thought...



    Oh yeah, you can use OpenGL or other accelerators to speed up such programs. Think of the screen as two triangles forming a square. There you go.



    -Xotor-


  • Well What I did was put in a huge background and then I placed the tiles on top. I will attempt to speed it up with open GL if possible, but for now I am going to get the scrolling proces as complete as possible.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories