BASIC

Author Topic: Is there a way to change the colour of a sprite?  (Read 1625 times)

Offline Bursar

  • Mr. Drawsprite
  • **
  • Posts: 63
    • View Profile
Apologies if this is covered somewhere, but documentation seems to be a bit lacking, and tracking down the commands I'm looking for seems to be a bit of a hit and miss affair.

I was wondering if there's some way of changing the colour or 'tint' of a sprite? For instance I could have a white bullet sprite, but use GLB to tint it different colours based on who fired it.

Would save having to double up on sprites just so I can change the colour.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
I think the command you are looking for is polyvector. You can set a color of each corner of a sprite and it will gradually color the whole sprite in those colors. The downside is that you have to handle rotation yourself since you have to set the location of each corner of the sprite yourself. There should be some examples on the forum for that but searching has a 15 second timer to it so I was too lazy to wait for the next chanse to search...

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
yes. POLYVECTOR or you can try to play around with ALPHAMODE.
However I think it's easier to handle different sprites in this case.

Offline Bursar

  • Mr. Drawsprite
  • **
  • Posts: 63
    • View Profile
Thanks, but I don't think either of those are going to help me. ALPHAMODE is just going to set the blending mode, so a white bullet on a black background isn't likely to become red or blue  :P

Using POLYVECTOR is going to be a pain in the harris.

I presume it's exactly the same for fonts? If you want a red font and a blue font, that's two copies of the image you have to load?

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1542
    • View Profile
For standard types, set the font foreground color to be transparent then draw that on to the chosen color, then set the transparent color to the background font to produce the file output.  ;)
« Last Edit: 2010-Sep-07 by matchy »

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 915
    • View Profile
... ALPHAMODE is just going to set the blending mode, so a white bullet on a black background isn't likely to become red or blue  :P ...

Just as I said: "play around with ALPHAMODE".

e.g.
Code: GLBasic [Select]
LOCAL sprite1%, sprite2%

DRAWRECT 0, 0, 20, 20, RGB(0, 255, 0)
sprite1 = GENSPRITE()
GRABSPRITE sprite1, 0, 0, 20, 20

DRAWRECT 0, 0, 20, 20, RGB(255, 0, 255)
sprite2 = GENSPRITE()
GRABSPRITE sprite2, 0, 0, 20, 20


WHILE TRUE
       
        DRAWSPRITE sprite1, 0, 0
       
        DRAWSPRITE sprite1, 50, 0
        ALPHAMODE -.9
        DRAWSPRITE sprite2, 50, 0
       
        ALPHAMODE 0
        DRAWSPRITE sprite1, 100, 0
        ALPHAMODE .8
        DRAWSPRITE sprite2, 100, 0
       
        SHOWSCREEN
       
WEND
 

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
I think something potentially cool can be done with the new sprite2mem commands.

If you put image data into an array you can manipulate colors like how they did in the console days.

It would also be possible to create a loop that converts the colors to a set hue.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Yes - I still wayt for volunteers to make "hq2x" filters with MEM2SRPITE :D