Sprite - direct pixel manipulation

Advanced game related topics
fing72
New User
New User
Posts: 3
Joined: Tue May 02, 2023 6:22 pm

Sprite - direct pixel manipulation

Post 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.
benubi
Enthusiast
Enthusiast
Posts: 113
Joined: Tue Mar 29, 2005 4:01 pm

Re: Sprite - direct pixel manipulation

Post 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.
Ampli
User
User
Posts: 50
Joined: Sun Jul 29, 2007 7:05 pm
Location: Sweden

Re: Sprite - direct pixel manipulation

Post by Ampli »

You can do shirts seperate sprites then use
DisplayTransparentSprite(sprite,x,y,255,RGB(?,?,?))

/Micke
User avatar
Caronte3D
Addict
Addict
Posts: 1025
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Sprite - direct pixel manipulation

Post by Caronte3D »

fing72
New User
New User
Posts: 3
Joined: Tue May 02, 2023 6:22 pm

Re: Sprite - direct pixel manipulation

Post 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()
  
fing72
New User
New User
Posts: 3
Joined: Tue May 02, 2023 6:22 pm

Re: Sprite - direct pixel manipulation

Post 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.
Post Reply