Realize background smooth loop in BCB

zhaozj2021-02-08  247

Home:

http://www.maxss.net

Email:

MAXSS.NET@163.com

For some small games or multimedia program applications, you often need to make some loop scrolling background effects. This effect is actually very easy to do, it can be implemented in a confession, but the smooth transition of the two ends of the background diagram in the process of scrolling is needed. Here is to introduce my implementation method.

The first thing to do is a background picture that has been treated, as for the background map how to make, you can refer to another article on this site "

Use photoshop to make both ends of smooth connection background. "

Then the program is encoded, and it is still simply here. Now we have received a specially handled background diagram, while only updating the X (or Y) value in each cycle, and draws it in a fixed length of the start. As shown in Figure 1:

(figure 1)

For a fixed length exceeds the background length from the background head intercepted from the background head, because the background chart has been treated, there will be no obvious "fault" here. as shown in picture 2:

(figure 2)

In order to make the animation not flash, it is recommended to use double buffer technology to carry out background painting. The following is the basic implementation of the algorithm (from the little time I haven't worked for some time):

TRECT SRCRECT, DESTRECT

// fMapy is a member variable defined in .h file, representing the starting position of the painting

INT OFFSET = 0 - FMAPY;

IF (Offset> 0) // Tail Tailboratation

{

// FBMPMAP is a member variable of the graphic :: Tbitmap type defined in .h file

// Used to deposit into background diagram

INT TMPY = fbmpmap-> height - offset

// fbmpbuffer is a member variable of the graphic :: Tbitmap type defined in .h file

// Used to implement a double buffer mechanism

SRCRECT = Rect (FMapx, TMPY, FBMPMPMAP-> Width, FBmpMap-> Height);

DESTRECT = Rect (fMapx, 0, fbmpmap-> width, offset);

FBmpBuffer-> Canvas-> CopyRect (DestRect, fbmpmap-> canvas, srcRect);

INT offsetleAve = ClientHeight - offset

SrcRect = Rect (FMapx, 0, FBmpmap-> width, offsetleave);

DESTRECT = Rect (fMapx, offset, fbmpmap-> width, clientHeight);

FBmpBuffer-> Canvas-> CopyRect (DestRect, fbmpmap-> canvas, srcRect);

IF (Offset == ClientHeight)

FMAPY = fbmpmap-> height - clientheight;

}

ELSE / / Normal Touch

{

SrcRect = Rect (FMapx, Fmapy, ClientWidth, ClientHeight FMapy);

DESTRECT = Rect (FMapx, 0, ClientWidth, ClientHeight);

FBmpBuffer-> Canvas-> CopyRect (DestRect, fbmpmap-> canvas, srcRect);

}

// Draw to buffer

FBmpBuffer-> Canvas-> DRAW (fbmpmap-> width, 0, fbmppanel); // Draw to the window

Canvas-> DRAW (0, 0, FBMPBuffer);

The full source code and program downloads have been provided in my homepage:

http://www.maxss.net

http://www.maxss.net/downloadhttp://www.maxss.net/download/ms/over_fog.rar

转载请注明原文地址:https://www.9cbs.com/read-2161.html

New Post(0)