Transparent part of sprite

BlitzMax Forums/BlitzMax Programming/Transparent part of sprite

something like this ?

Strict

Graphics 800, 600, 0

SetClsColor 166, 166, 166

Type appLightCircle

  Field lightRadius:Int =100
  Field lightCirleImage:TImage
  
  Method CreateCircleLight:Timage(curLightRadius:Int =100)

    lightRadius =curLightRadius

    Local newImage:Timage =CreateImage(lightRadius *2, lightRadius *2, 1, DYNAMICIMAGE)
    Local newPixmap:TPixmap =LockImage(newImage, 0)
    ClearPixels(newPixmap)
    For Local x:Int =0 To newPixmap.width -1
      For Local y:Int =0 To newPixmap.height -1
        Local curDistance:Float =Sqr((lightRadius -y) *(lightRadius -y) +(lightRadius -x) *(lightRadius -x))
        Local curAlpha:Int =255
        If curDistance <lightRadius Then
          curAlpha :*curDistance /lightRadius
        End If
        WritePixel(newPixmap, x, y, (curAlpha Shl 24) +(0 Shl 16) +(0 Shl 8) + 0)
      Next
    Next

    UnlockImage(newImage, 0)

    lightCirleImage =newImage

  End Method

  Method Render(curX:Int, curY:Int, lightR:Int =255, lightG:Int =255, lightB:Int =255)

    SetBlend ALPHABLEND
    SetColor 0, 0, 0
    SetAlpha 1
    SetScale 1, 1 
    SetRotation 0

    DrawRect 0, 0, GraphicsWidth(), curY -lightRadius
    DrawRect 0, curY +lightRadius, GraphicsWidth(), GraphicsHeight() -curY -lightRadius
    DrawRect 0, curY -lightRadius, curX -lightRadius, 2 *lightRadius
    DrawRect curX +lightRadius, curY -lightRadius, GraphicsWidth() -curX -lightRadius, 2 *lightRadius
    SetColor lightR, lightG, lightB
    DrawImage lightCirleImage, curX -lightRadius, curY -lightRadius

  End Method

End Type


Local lightCircle:appLightCircle =New appLightCircle
lightCircle.CreateCircleLight(300)

HideMouse 

'make us some Images for the worlds scene :
'BACKGROUND
Cls
SetBlend SOLIDBLEND
SetColor 0, 0, 0
DrawRect 1, 1, 10, 3
SetColor 255, 0, 0
DrawRect 1, 4, 10, 3
SetColor 255, 255, 0
DrawRect 1, 7, 10, 3
Local backImage:TImage =CreateImage(10, 9, 1, DYNAMICIMAGE)
GrabImage backImage, 1, 1, 0

'FOREGROUND
Type appSprite

  Field x:Float
  Field y:Float
  Field vx:Float 'pixel per second
  Field vy:Float 'pixel per second 
  Field img:TImage
  Field lastUpdatet:Int

  Method CreateSprite(curX:Int =0, curY:Int, curVX:Int, curVY:Int)

    Cls
    SetColor 255, 255, 0
    DrawRect 1, 1, 110, 25
    SetColor 255, 0, 0
    DrawRect 111, 1, 110, 25
    SetColor 0, 0, 255
    DrawRect 1, 26, 110, 25
    SetColor 255, 255, 255
    DrawRect 111, 26, 110, 25
    img =CreateImage(220, 50, 1, DYNAMICIMAGE)
    GrabImage img, 1, 1, 0

    x =curX
    y =curY
    vx =curVX
    vy =curVY

  End Method

  Method Render()

    SetScale 1, 1
    If lastUpdatet =0 Then
      lastUpdatet =MilliSecs()
    Else
      Local deltaX:Float =vx *(MilliSecs() -lastUpdatet) /1000
      Local deltaY:Float =vy *(MilliSecs() -lastUpdatet) /1000
      lastUpdatet =MilliSecs()
      x :+deltaX
      y :+deltaY
      If x >GraphicsWidth() Then 
        x =0
      ElseIf x <0 Then
        x =GraphicsWidth()
      End If
      If y >GraphicsHeight() Then 
         y =0
      ElseIf y <0 Then
         y =GraphicsHeight()
      End If
    End If
    DrawImage(img, x, y)

  End Method

End Type

Local sprites:appSprite[7]
For Local z:Int =0 To 6
  sprites[z] =New appSprite
  sprites[z].CreateSprite(Rand(100, 700), Rand(100, 500), Rand(-100, 100), Rand(-100, 100))
Next

Repeat

 Cls
 'background
 SetScale GraphicsWidth() /backImage.width, GraphicsHeight() /backImage.height
 DrawImage(backImage, 0, 0) 

 'world
 For Local z:Int =0 To 6
   sprites[z].Render()
 Next

 'lights range
 lightCircle.Render(MouseX(), MouseY())

 Flip

Until KeyHit(KEY_ESCAPE)