S
S
Span4ev2022-03-11 12:38:08
pygame
Span4ev, 2022-03-11 12:38:08

How can I assign one color to the fill of a Rect and another color to its border?

I didn't find any mention of border color for Rect and I'm not sure if it's possible in paygame, but maybe you know something?

pg.draw.rect(self.screen, self.new_color, self.rect, width=5)


There is no way to specify a separate color for the border?

Do you really have to make two passes through the loop (if you need to draw a couple of dozen blocks) and first make blocks, say, 100px, then draw smaller blocks on top of them, say, if you need a frame of 10px, then draw 90px blocks and place them on top of the lower ones, positioning them in the center of the lower ones, and only then print the text on the upper blocks? Quite inconvenient... Knowing CSS, the idea that this is not implemented in the paygame is alien to me.

In some examples I see the use of Surface, in some Rect. Is it just me, or is using Surface some older way?
Is there a fundamental difference between Surface and Rect? And if I have to use the method with two rectangles, one on top of the other, to create a frame, which is better to use: Surface or Rect?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
YariKartoshe4ka, 2022-03-11
@YariKartoshe4ka

There is no way to specify a separate color for the border?

Not
Do you really have to do two passes through the loop?

What's so terrible about that?
first make blocks, say 100px, then draw smaller blocks on top of them, let's say if the frame needs 10px, then draw 90px blocks and place them on top of the bottom

It can be much easier - first draw a 100px rectangle, and then also 100px, but with width=10px
Surface or Rect?

For a start it is worth looking in the documentation what it means. Surface - the surface (screen, window) on which you draw. Rect - a rectangle object (in other words, a hitbox) with its own coordinates and various geometric methods. I don’t understand how these concepts can be compared if they are completely different

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question