if(LanderX > ddsd.dwWidth)
{
LanderX = 0;
}
if((LanderX) < 0)
{
LanderX = ddsd.dwWidth;
}
so, if you run off the Right side (if #1) then it goes back to zero.
if you try to run off the left side, however, it just stops on the side of the screen. any ideas?
Also, i''d like the bitmap to be able to run fully off the screen before it loops around.
why doesn''t this work?
Wrap arounds?
Hi..
I''m messing around with a code fragment to wrap a bitmap around a surface. here''s the code:
ddsd is the Back buffer surface Desc.
LanderX is the Left of the bitmap thing.
Programmers of the world, UNTIE!
Not sure whats going on here exactly, but definitly try using an else if.
-SniperBoB-
What if The Matrix was recursive?
-SniperBoB-
What if The Matrix was recursive?
Brandon Bloomhttp://brandonbloom.name
quote:
What if The Matrix was recursive?
PLEASE tell me your talking about the movie, and not some transformation i have to do...
ok, the second statement is now an "else if" it still doesn''t work.
Programmers of the world, UNTIE!
November 22, 2002 02:14 PM
quote: Original post by MattS423
Hi..
I''m messing around with a code fragment to wrap a bitmap around a surface. here''s the code:
ddsd is the Back buffer surface Desc.
LanderX is the Left of the bitmap thing.if(LanderX > ddsd.dwWidth){ LanderX = 0;}if((LanderX) < 0){ LanderX = ddsd.dwWidth;}
so, if you run off the Right side (if #1) then it goes back to zero.
if you try to run off the left side, however, it just stops on the side of the screen. any ideas?
Also, i''d like the bitmap to be able to run fully off the screen before it loops around.
why doesn''t this work?
Ok First things first, add a clipper to your primary surface. This will allow you to move your sprite off the screen with out having crap come up on your screen.
Now that this is completed lets get into this:
|--|
| | <- this is my sprite it is 10 pixels high by 10 wide.
|--|
Our screen resolution is 640x480.
Now if you want to move this sprite off the screen to the left you would place the sprites x,y at 0,0 then you would slowly move it left until the sprites x position is equil to it''s negative width. In our case it would be -10. This would mean the sprite is fully off screen. Now that it is fully off screen you can move the x,y of the sprite to 650,0. This will place the sprite off screen to the far right of the screen. You can again subtract from this position until the sprite moves onto the screen.
Now as I stated this all requires a clipper being setup.
If your using a bitmap & dx blt functions. The blt/fast functions will not render a bitmap if its outside the dimensions of the buffer. So when you set it to 0 the lost most part is on 0 and the right most part is on the screen so its on the buffer. But when you make equal ddsd.dwWidth the left most part the screen width but the right of the bitmap is off the screen buffer.
hoped this helped
WizHarD
hoped this helped
WizHarD
who is it that keeps on nicking WizHarD name !! :P
the clipper has been there.
It still doesn''t work...so i''ll give you more code....
this bit is called every frame.
KeyDown is a Macro that says weather a specific key is down.
Abort() is a error-message function.
lpDDSLanderBitmap is the sprite.
lpDDSBackBuffer is the back buffer. (i''m trying to draw to this)
It still doesn''t work...so i''ll give you more code....
this bit is called every frame.
KeyDown is a Macro that says weather a specific key is down.
Abort() is a error-message function.
lpDDSLanderBitmap is the sprite.
lpDDSBackBuffer is the back buffer. (i''m trying to draw to this)
if(KEYDOWN(VK_ESCAPE)) { DestroyWindow(g_hWnd); return 0; } if(KEYDOWN(VK_F6)) { return 0; } static int LanderX = 0; static int LanderY = 0; static int LanderVX = 0; static int LanderVY = 0;// So i can do something intelligent when it messes up... if(KEYDOWN(VK_F5)) { LanderX = 20; LanderY = 20; LanderVX = 0; LanderVY = 0; } //Arrow key stuff if(KEYDOWN(VK_UP)) { LanderVY--; } if(KEYDOWN(VK_DOWN)) { LanderVY++; } if(KEYDOWN(VK_LEFT)) { LanderVX--; } if(KEYDOWN(VK_RIGHT)) { LanderVX++; } //Speed Cap--very useful if(LanderVX >= 10) LanderVX = 10; if(LanderVY >= 10) LanderVY = 10; if(LanderVY < -10) LanderVY = -10; if(LanderVX < -10) LanderVX = -10; LanderX += LanderVX; LanderY += LanderVY; DDSURFACEDESC2 LanderDesc; LanderDesc.dwSize = sizeof(LanderDesc); if(FAILED(lpDDSLanderBitmap->GetSurfaceDesc(&LanderDesc))) { Abort("LanderDesc error"); return 1; } if(FAILED(lpDDSBackBuffer->GetSurfaceDesc(&ddsd))) { Abort("BackBufferDesc error"); return 1; } //Make it wrap if(LanderX > (ddsd.dwWidth )) { LanderX = 0; } else if((LanderX) < 0 - LanderDesc.dwWidth ) { LanderX = ddsd.dwWidth; } //Make the destination rect RECT DestRect; DestRect.left = LanderX; DestRect.top = LanderY; DestRect.right = LanderX + LanderDesc.dwWidth-1; DestRect.bottom = LanderY + LanderDesc.dwHeight-1;//Code now goes on to blt the bitmap to the backbuffer and flip
Programmers of the world, UNTIE!
Your clipper is wrong it should be:
if((LanderX+LanderDesc.dwWidth) > ddsd.dwWidth )
{
LanderX = 0;
}
else if(LanderX < 0 - LanderDesc.dwWidth )
{
LanderX = ddsd.dwWidth - LanderDesc.dwWidth;
}
that will just make the lander switch screens if just one pixel is off the buffer you could use a much smoother algorithm so that it doesn''t switch sides till the whole bmp has gone over
if((LanderX+LanderDesc.dwWidth) > ddsd.dwWidth )
{
LanderX = 0;
}
else if(LanderX < 0 - LanderDesc.dwWidth )
{
LanderX = ddsd.dwWidth - LanderDesc.dwWidth;
}
that will just make the lander switch screens if just one pixel is off the buffer you could use a much smoother algorithm so that it doesn''t switch sides till the whole bmp has gone over
who is it that keeps on nicking WizHarD name !! :P
wtf I didn''t type that, this forum has a mind of its own the else if statment shoud be:
else if( LanderX < 0 )
{
LanderX=ddsd.dwWidth-LanderDesc.dwWidth;
}
I hope that helped
else if( LanderX < 0 )
{
LanderX=ddsd.dwWidth-LanderDesc.dwWidth;
}
I hope that helped
who is it that keeps on nicking WizHarD name !! :P
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement