Archived

This topic is now archived and is closed to further replies.

trail, SDL help

This topic is 5013 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im doing the cone3d tutorial on loading a bitmap and i tried to load another bitmap on another part of the screen but when the seconed bitmap is moved it leaves a trail. when i made it so the seconed bitmapp get rendered 1st the other bitmap left a trail. So i was wondering if my problem was getting the those two bitmapps to load at the same time and if that was possible? [edited by - wannabe 1337 on March 25, 2004 6:23:19 PM] [edited by - wannabe 1337 on March 25, 2004 6:23:39 PM]

Share this post


Link to post
Share on other sites
here is my function that inittilizes the bitmaps.


void DrawScene()
{
SDL_Flip(screen);
DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);
DrawIMG(otherimage,xpos+200, ypos+200);
DrawIMG(image, xpos, ypos);

SDL_Flip(screen);
}

what do i have to fix it even has SDL_Flip(screen);

[edited by - wannabe 1337 on March 25, 2004 9:03:39 PM]

Share this post


Link to post
Share on other sites
well, the basic idea is to

foreach (sprite you want to draw) {
DrawBackgroundBehindSprite();
DrawSprite();
}


it would appear you are only drawing the background behind the one sprite.

Share this post


Link to post
Share on other sites
quote:
Original post by leiavoia
well, the basic idea is to

foreach (sprite you want to draw) {
DrawBackgroundBehindSprite();
DrawSprite();
}


it would appear you are only drawing the background behind the one sprite.


well i have the idea i just dont know how to implement it. i made the following changes to my code.

void DrawScene()
{
DrawIMG(back, ypos-2, xpos-2, 132, 132, xpos-2, ypos-2);
// right here is the change.
DrawIMG(bgr, xpos+620, ypos+150, 132, 132, xpos+620, ypos+150);
DrawIMG(otherimage,xpos+620, ypos+150);
DrawIMG(image, xpos, ypos);
SDL_Flip(screen);
}

i now have 2 images im using as a background 1 for the left sprite and 1 for the right sprite. however the right sprite still leaves a trail on the right backgound.

Share this post


Link to post
Share on other sites
quote:
Original post by wannabe 1337
to my code.

void DrawScene()
{
DrawIMG(back, ypos-2, xpos-2, 132, 132, xpos-2, ypos-2);
// right here is the change.
DrawIMG(bgr, xpos+620, ypos+150, 132, 132, xpos+620, ypos+150);
DrawIMG(otherimage,xpos+620, ypos+150);
DrawIMG(image, xpos, ypos);
SDL_Flip(screen);
}



why are you using the same variables for 2 seperate images coordinates? you should use 2 seperate variables, ie image1.xpos, image1.ypos, image2.xpos, image2.ypos (make a structure that can hold xpos and ypos)

anyway, after you do that, you need to change the way your blitting. the cone3d way of blitting is bad, bad bad. you should NEVER draw extra background to cover up the image because it moved. instead, draw the background BEFORE you move anything. THEN move stuff, THEN draw the object in its new place. your main game loop should look like this:



while(!gameover)
{

Draw_Backgrounds() //first draw the background over the OLD IMAGES


Take_Input() //take input


Move_Stuff() // move things. these 2 could be combined in a smaller game, but be carefull. you must ALWAYS take input each game loop, i learned this the hard way :p


Draw_Images() //NOW draw all the images in there new spots


}


if you do it like this, you just draw the backgrounds directly on top of the image. no need for extra background


[edited by - graveyard filla on March 26, 2004 1:36:41 AM]

Share this post


Link to post
Share on other sites
graveyard is right. If you have many objects and draw a little extra background on each object, that extra background will overlap other close objects.

If you are making an action game, you are going to have to redraw the entire screen )or major portions thereof) anyway, so do what graveyard said:

while ( game is not done ) {
RedrawEntireBackground();
TakeInputFromUserAndDoStuph();
DrawEachSprite( where they are at );
SDL_Flip();
}


Share this post


Link to post
Share on other sites