Creating Masks... Alpha Value

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
CT_Bolt
Posts: 14
Joined: Sat Mar 04, 2006 3:21 am
Location: Computer Chair

Creating Masks... Alpha Value

Post by CT_Bolt »

Ok so I know how to blit Alpha Images over top of other images but, only in rectangles.

Is there a way to just blit the image to the screen with an Alpha Mask like... it just draws an alpha value over the image only(with transparent parts).

This is so I can make just the player have a different tint instead of the rectangle of the player have the different tint.

Please any help would be much appreciated.
my psprecious
Posts: 24
Joined: Fri Feb 17, 2006 5:08 am

Post by my psprecious »

Why do you need it (well I already founs a use hehe), actually understand what your problem is, you want an image to overlay over and other, or are you trying to make the collision with the alpha of a character, if yes dude don't waste your time with that, rectangle for colision will do the trick.
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

Post by Kameku »

I'm pretty sure this would be rediculously not neccessary lol

Code: Select all

image = Image.load("myimage.png")
grey = Color.new(127,127,127,127)

for y=1,image:width() do
 for x=1,image:height() do
  color = image:pixel(x,y)
  rgb = color:colors()
  if rgb:a() == 0 then
   image:fillRect(x,y,1,1,grey)
  end
 end
end
Not entirely sure that would work, but hey, worth a try.
CT_Bolt
Posts: 14
Joined: Sat Mar 04, 2006 3:21 am
Location: Computer Chair

Well...

Post by CT_Bolt »

With a litle bit of adjustments this actually works pretty well.
Here is the function I wrote with the help of Kameku's code:

Code: Select all

function Image:DrawAlpha(X, Y, MaskColour, BGColour)
  if MaskColour then
    if not X then X = 0 end
    if not Y then Y = 0 end
    imgAlpha = Image.createEmpty(self:width(), self:height())
    for YPos=0,self:width()-1 do
     for XPos=0,self:height()-1 do
      color = self:pixel(XPos,YPos)
      rgb = color:colors()
      if rgb.a == 0 then
        if BGColour then screen:fillRect(XPos,YPos,1,1,BGColour) end
      else
        imgAlpha:fillRect(XPos,YPos,1,1,MaskColour)
      end
     end
    end
    screen:blit(X, Y, imgAlpha)
  end
end
Call it like this:

Code: Select all

imgStar = Image.load("Star.PNG")
imgStar:DrawAlpha(0,0,Color.new(200,0,0,200))
AND... THANK YOU SO MUCH Kameku!!!
With this I can create lots of cool stuff.
Post Reply