• ### Popular Now

• 13
• 16
• 19
• 27
• 9

#### Archived

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

# Why is my image wrapping?

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

## Recommended Posts

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...

##### Share on other sites
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!

##### Share on other sites
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

  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

##### Share on other sites
quote:
Original post by SwSh
Most probably the image is not 100% wrapping, but it''s shifted one line down...

Thanks a lot! You''re exactly right. That possibility didn''t even
enter my mind. Somewhere back there I knew that the memory is
linear, I just couldn''t put 2 & 2 together.