how to change text colour

Just starting out? Need help? Post your questions and find answers here.
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

how to change text colour

Post by pfaber11 »

How do I change the background color from black to another color and how do I change the text color. I'm new and need some help. Thanks for reading . I haven't explained myself very well I'm referring to the background color or the text.
firace
Addict
Addict
Posts: 903
Joined: Wed Nov 09, 2011 8:58 am

Re: how to change text colour

Post by firace »

Hi, please post a short code example showing where you are stuck, for people to help.
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

Re: how to change text colour

Post by pfaber11 »

Code: Select all

  StartDrawing(WindowOutput(0))
  DrawText(10,10,"hello world")
  ClearScreen(#Green)
  
 x=x+1
  DisplayTransparentSprite(sprite1,x,y)
  DisplayTransparentSprite(sprite2,x2,y2)
  result = SpriteCollision(sprite1,x,y,sprite2,x2,y2)
  If result = 1 
    DrawText(600,400, "CRASH")
    EndIf
  If x >= 1366
    x= -179 
    EndIf
    StopDrawing()
    FlipBuffers()
  WindowEvent()
  ExamineKeyboard()
  If  KeyboardPushed(#PB_Key_Return)
    End
  EndIf
  If  KeyboardPushed(#PB_Key_W)
    y=y-10
  EndIf
  
   If  KeyboardPushed(#PB_Key_S)
    y=y+10
  EndIf
 Goto loopy
It's the draw text command can't seem to find where you change the text color or the text background color. I'm not new to programming but am new to Pure Basis . on day 4 so far and really like PB so far just gotta get into the syntax.
infratec
Always Here
Always Here
Posts: 6874
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: how to change text colour

Post by infratec »

Have you ever read the help for DrawText() :?:
DrawText(x, y, Text$ [, FrontColor [, BackColor]])
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

Re: how to change text colour

Post by pfaber11 »

Ok thanks for that I'm still finding my feet.
I thought it would be something like settextcolor() was looking for the wrong help. I've come to PB from AGK2 classic. I must say I'm very impressed with PB so far. I'm on day 4 . Thanks again for the help.
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: how to change text colour

Post by Demivec »

@pfaber11: I have a few points about the code you posted that you might like to know.

- The DisplayTransparentSprite() commands should only be used outside of a StarDrawing()/StopDrawing() block.

- You are mixing drawing operations on the WindowOutput() and the ScreenOutput(). It isn't shown but you most likely have a WindowedScreen inside a Window. Just draw to the screen because you don't seem to be drawing on any portion of the window outside of the WindowedScreen() area. The pattern to do this is using ClearScreen(), StartDrawing(ScreenOutput())/StopDrawing(), then FlipBuffers(). If sprites are displayed they would be outside the drawing block as mentioned above but can be either before or after the drawing block or both before and after it.

- If there is a portion of the Window that is outside of the WindowedScreen area that you would like to draw to, consider using an ImageGadget() and draw to an image that is then assigned to it or use a CanvasGadget() and draw to it using StartDrawing(CancasOutput)). By ysing a gadget you won't have to keep redrawing the area within the gadget unless it changes.

- Since you are using a WindowedScreen you need to also check for window events in addition to the ones that are com8ng from the screen (ExamineKeyboard(), ExamineMouse(), etc). The code you showed does check once per each display loop. You should inates be checking for events in a loop until there are no more before continuing on with the displat loop. If this isn't done then it is very easy for three unhandled window events to quickly build up and cause lag in your program's responsiveness or even result in a crash. This is especially true if there is any user interaction with the program.

- One last minor point, the infinite Goto Label loop can easily and effectively be replaced by a Repeat: Until Forever loop.

Happy 4th day of PureBasic! :)

The PureBasic IDE can show you the parameters needed for a function in the status line by placing the cursor within the parenthesis after the funtion's name. You can also display the help file entry for a function by pressing F1 when the cursor is on the function's name in your code.
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Re: how to change text colour

Post by C87 »

pfaber11

Check out the detail from these TOPIC TITLES in the Search feature

Color Themes for PureBasic
Control border color
Change menu and popup menu colours
Color Themes for PureBasic
Procedure HDPI fix
Control border color

:) :wink:
If it's falling over......just remember the computer is never wrong!
Post Reply