简体   繁体   中英

How to draw a dashed line?

I need to draw a dashed line(for pong) using SDL. I want to do it in a for loop because making and rendering 10 different rectangles costs too many lines of code. So just for clearness, not this:

SDL_Rect pieceOfLine = {x,y,w,h};
SDL_Rect pieceOfLine1 = {x,y,w,h};
SDL_Rect pieceOfLine2 = {x,y,w,h};

etc.

But sort of this(I tried this but it didn't work):

SDL_Rect line = {x,y,w,h};
for(int i = 0 ; i < 10 ; i++){
    SDL_RenderFillRect(renderer,&line);
    line.y += 30; //So actually a line with holes in it
}

I hope I was clear enough, thanks in advance and sorry for bad English. This is an example of what I actually need(In my program):

|

|

|

|

|

|

您的方法看起来不错,但是您需要使h等于15,否则您将在彼此之上绘制10条线,并稍微偏移。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM