Why is my image wrapping?
First time posting to Gamedev.net, so...
Anyway, my problem is that my image is wrapping around to the
other side of the screen, and I don''t know why this is happening.
I have a double-buffer that I draw to, then copy to my primary
surface. The buffer has (640*480) bytes allocated to it (the
game is palettized, 640*480. I''m using DirectX 6.1 because it''s
all I have access to right now). I haven''t done anything as far
as clipping goes; no bounds-checking to see if the image will
be drawn beyond my double buffer, or anything like that.
Currently, I have a simple, temporary statement that moves my
character. All it does it increment his xPosition by 2 pixels.
The thing is, when I move my character past the edge of the
screen, he wraps around to the other side. I have no clue as
to why this is happening. His xPosition could be 700, and he''ll
be drawn as if it was at 40...
The double buffer is declared as...
unsingned char* doublebuffer = NULL;
doublebuffer = new unsigned char[(640*480)];
Then I just copy that to the primary surface. I''m sooo
confused...
Most probably the image is not 100% wrapping, but it''s shifted one line down. Why? if you do not perform a bounds check on the coordinates of the points to be drawn, they will "come back" on the other side of the screen due to the linear structure of the buffer. In human words: if you draw a pixel at (x,y)=(700,10), it will appear at (60,11) (note the y coord got increased) on the screen.
I know nothing about directx but I presume there should be a blit function that clips the coordinates so the "wrapping" doesn''t occur. Basically, using directx blit functions would be faster than writing your own blitters and copying everything to the framebuffer.
If the problem is not the one I described, ignore my explanation.
Click NOW!
I know nothing about directx but I presume there should be a blit function that clips the coordinates so the "wrapping" doesn''t occur. Basically, using directx blit functions would be faster than writing your own blitters and copying everything to the framebuffer.
If the problem is not the one I described, ignore my explanation.
Click NOW!
Try this code: (I assume you''re using DDraw)
Assume x and y are the position of the sprite, m_Surface is pointer to your surface and src is the rectangle which defines your sprite
Hopefully that should work, an example of how to do clipping in DDraw anyway
Assume x and y are the position of the sprite, m_Surface is pointer to your surface and src is the rectangle which defines your sprite
RECT ClipRect = { 0, 0, SCREENHEIGHT, SCREENWIDTH };if((src.right - src.left) + x >= ClipRect.left && (src.bottom - src.top) + y >= ClipRect.top && x <= ClipRect.right && y <= ClipRect.bottom){ //PostQuitMessage(0); if(((src.right - src.left) + x) > ClipRect.right) { src.right = src.left + ClipRect.right - x; } if((src.bottom - src.top) + y > ClipRect.bottom) { src.bottom = src.top + ClipRect.bottom - y; } if(x < ClipRect.left) { src.left += ClipRect.left - x; x += ClipRect.left - x; //src.left = 1; } if(y < ClipRect.top) { src.top += ClipRect.top - y; y += ClipRect.top - y; //src.top = 1; } return m_Surface->BltFast(x, y, Dest, src, Flags);}
Hopefully that should work, an example of how to do clipping in DDraw anyway
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement