[SOLVED] libtcod - set background color for one character

This is the place for queries that don't fit in any of the other categories.

[SOLVED] libtcod - set background color for one character

Postby jeremyflexer » Sun Jan 19, 2014 3:29 am

Hello, my goal is to make it so I can set the background color of a character put on screen in a similar way as I do the foreground.

To do it to the foreground and make the character that color I use:
Code: Select all
self.color = self.object_colors[self.grid_final[(self.counter_one, self.counter_two)]]
self.window_main.console_set_default_foreground(0, self.color)
self.window_main.console_put_char(0, self.counter_two, self.counter_one,
'{}'.format(self.grid_final[(self.counter_one, self.counter_two)]), libtcod.BKGND_NONE)

the console_put_char() sets the foreground for the character with the console_set_default_foreground() okay.
Altough that is not the full code you should get the idea, and it works; For the foreground.

I did something similar except used
Code: Select all
self.window_main.console_set_default_background(0, self.color)

It didn't throw any errors, but didn't change any background colors at all. I am not sure how to do this without changing the entire background of the window to self.color, please help. If you need any more information feel free to ask, althought I am not the best at what you call 'elaboration'?
Last edited by jeremyflexer on Thu Jan 23, 2014 12:04 am, edited 1 time in total.
User avatar
jeremyflexer
 
Posts: 23
Joined: Fri Jan 17, 2014 6:36 pm

Re: libtcod - set background color for one character

Postby stranac » Sun Jan 19, 2014 12:45 pm

From the Background effect flags docs, it looks like the flag you're passing(libtcod.BKGND_NONE) makes it so that the cell's background color is not modified.
You probably need to pass libtcod.BKGND_SET.

Also, if you just want to do this for one character, you probably shouldn't be modifying the defaults at all, but use console_put_char_ex().
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: libtcod - set background color for one character

Postby jeremyflexer » Sun Jan 19, 2014 3:21 pm

stranac wrote:From the Background effect flags docs, it looks like the flag you're passing(libtcod.BKGND_NONE) makes it so that the cell's background color is not modified.
You probably need to pass libtcod.BKGND_SET.

Also, if you just want to do this for one character, you probably shouldn't be modifying the defaults at all, but use console_put_char_ex().


Okay, I will try console_put_char_ex().
Okay I tried console_put_char_ex(), I should have searched better and used that from the beginning ha. Thanks, everything works fine; Better actually.
User avatar
jeremyflexer
 
Posts: 23
Joined: Fri Jan 17, 2014 6:36 pm


Return to General Coding Help

Who is online

Users browsing this forum: Baldyr, Google [Bot] and 4 guests