Page 1 of 1

Sprite - direct pixel manipulation

Posted: Tue May 02, 2023 6:43 pm
by fing72
Hi all.
I'm trying to make a simple game.
I created an image that contains all the sequences of sprites that I would like to display in the game.
What I need is to modify a color knowing the codes of the palettes used in my image. I would like to do this after loading the image (loadsprite), i.e. before issuing the command (displaysprite) which must display the image with the already modified colors. The sprites are soccer players and must have the colors of the shirts chosen in the game menu, therefore I would like to avoid creating many images to upload for each shirt color.
I'm trying to find a way to modify the image directly in memory (after the loadsprite command) and NOT by displaying the sprites on the screen and then modifying the pixels.
Please, does anyone have any examples or suggestions to show me?
Thank you. Greetings.

Re: Sprite - direct pixel manipulation

Posted: Wed May 03, 2023 12:40 am
by benubi
That doesn't work anymore, palette support has been removed many PB versions ago.

You could copy the sprite and then use StartDrawing() and SpriteOutput() to replace the colors inside the copies.

Re: Sprite - direct pixel manipulation

Posted: Wed May 03, 2023 11:12 am
by Ampli
You can do shirts seperate sprites then use
DisplayTransparentSprite(sprite,x,y,255,RGB(?,?,?))

/Micke

Re: Sprite - direct pixel manipulation

Posted: Wed May 03, 2023 11:25 am
by Caronte3D

Re: Sprite - direct pixel manipulation

Posted: Wed May 03, 2023 9:13 pm
by fing72
benubi wrote: Wed May 03, 2023 12:40 am That doesn't work anymore, palette support has been removed many PB versions ago.

You could copy the sprite and then use StartDrawing() and SpriteOutput() to replace the colors inside the copies.

Thank you,
I used your suggestion
I had some problems with the pointers but finally I was able to change the shirts of the players.

If it may be useful, I attach an extract of my working procedure:

Code: Select all

StartDrawing(SpriteOutput(myimage_temp_P1))
 
  *Buffer       = DrawingBuffer()             ; Get the start address of the screen buffer
  Pitch         = DrawingBufferPitch()        ; Get the length (in byte) took by one horizontal line
    
  For y = 0 To height - 1
    *Pixel =  *Buffer + Pitch * y
   
    For x = 0 To width - 1
          
      If *Pixel\_Red = 255 And *Pixel\_Green = 255 And *pixel\_Blue = 255 
         
        *pixel\_Red   = col_player(colore_player_a,3)
        *pixel\_Green = col_player(colore_player_a,2)
        *pixel\_Blue  = col_player(colore_player_a,1)
        *pixel\_Alfa  = 255
      EndIf
      
      *pixel +4
    Next
  Next    
    
  StopDrawing()
  

Re: Sprite - direct pixel manipulation

Posted: Wed May 03, 2023 9:18 pm
by fing72
Caronte3D wrote: Wed May 03, 2023 11:25 am Take a look to:
viewtopic.php?p=590989&hilit=retro#p590989
Thank you,
I'll have to test it.