A quick question

bkumanchik

  • Full Member
  • ***
    • Posts: 28
    • View Profile
A quick question:

Do the sprites have transparency, it seems like they don't but wanted to check, I am using an inverted sprite (white on black)

Thanks,

Brian



bkumanchik

  • Full Member
  • ***
    • Posts: 28
    • View Profile
Figured it out, just needed a ", 0" at the end of the [thumby.display.blit] call.

Can't wait for the library documentation  ;)


Jason

  • Administrator
  • Hero Member
  • *****
    • Posts: 107
  • TinyCircuits Employee
    • View Profile
You can set a pixel color (either 0 or 1) to be not be drawn/be transparent in the thumby.display.blit() function.

The thumby library wraps the MicroPython framebuffer library, so see this: https://docs.micropython.org/en/latest/library/framebuf.html#framebuf.FrameBuffer.blit

For example, the default editor code with the bobbing Thumby sprite has a 32 x 32 black background (the Thumby is drawn in white). Passing '0' as the last parameter in the blit function means all black or 0 pixels will not be drawn.

Try the below code out and look at the blit functions on lines 26 and 29

Code: [Select]
import time
import thumby
import math

# BITMAP: width: 32, height: 32
bitmap0 = (0,0,0,0,0,0,0,0,248,8,232,40,40,40,40,40,40,40,40,40,40,232,8,248,0,0,0,0,0,0,0,0,
           0,0,0,0,0,0,0,0,255,0,63,32,32,32,32,32,32,32,32,32,32,63,0,255,0,0,0,0,0,0,0,0,
           0,0,0,0,0,0,0,0,255,0,12,12,63,63,12,12,0,0,24,24,3,3,0,255,0,0,0,0,0,0,0,0,
           0,0,0,0,0,0,0,0,31,16,16,16,16,20,18,16,20,18,16,16,16,16,16,31,0,0,0,0,0,0,0,0)

while(1):
    t0 = time.ticks_ms()   # Get time (ms)
    thumby.display.fill(0) # Fill canvas to black

    bobRate = 250 # Set arbitrary bob rate (higher is slower)
    bobRange = 5  # How many pixels to move the sprite up/down (-5px ~ 5px)

    # Calculate number of pixels to offset sprite for bob animation
    bobOffset = math.sin(t0 / bobRate) * bobRange

    # Center the sprite using screen and bitmap dimensions and apply bob offset
    spriteX = int((thumby.DISPLAY_W/2) - (32/2))
    spriteY = int(round((thumby.DISPLAY_H/2) - (32/2) + bobOffset))
   
    # Draw sprite normally (0 & 1 pixels drawn)
    thumby.display.blit(bitmap0, spriteX, spriteY, 32, 32)
   
    # Draw sprite halfway overlapping the last sprite but do not draw 0 or black pixels
    thumby.display.blit(bitmap0, spriteX+8, spriteY, 32, 32, 0)
    thumby.display.update()



 

SMF spam blocked by CleanTalk