Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Knox

#521
Wow, a big thanks to you guys...combining Calin's plugin with Khris' module (ASB) permits the resizing of images with a nice bilinear filter on a 32 bit alpha sprite, with a nice blur on the alpha edges:

Resized 50% with...


        1) AGS        2) ASB (alpha-swap, bilinear)           3)  Photoshop CS3


Thanks guys!
#522
If its not too much to ask, is it possible to add something like this as a function to your plugin? (quicker and more compact then doing it old school, I think) :

greyValue = GetRGB(alphaSprite.Graphic, x, y);
PutAlpha(inv_curs.Graphic, x, y, greyValue);

We can then get gray values from an opaque black and white sprite and convert it into transparency with your PutAlpha :D

(unless of course Im retarded and this exists already) **but not GetColorFromRGB**
#523
Just to debug, I drew the black and white alpha pixels directly to the cursor, to see how it works:
Code: ags

    cg = player.ActiveInventory.Graphic;
    inv_curs = DynamicSprite.CreateFromExistingSprite(cg, true);       
  
    alphaSprite = DynamicSprite.CreateFromExistingSprite(cg, true);
    //get alpha "color" for each pixel of the 120x120 image 
    int x, y, alpha;
    while (y < alphaSprite.Height)
    {
      while (x < alphaSprite.Width)
      {
        //code referencing x and y here
        alpha = GetAlpha(cg, x, y);        
        DrawingSurface *ds = inv_curs.GetDrawingSurface();
        ds.DrawingColor = Game.GetColorFromRGB(alpha,alpha,alpha); //this is grey
        ds.DrawPixel(x,y);
        x++;
      }
      y++;
      x = 0;
    }


...it seems (unless I did something wrong) that it draws the alpha rotated 90 degrees clockwise, then flipped:





Besides that, in theory, the resized alpha image below will be WAY better with Khris' bilinear filter:


#524
Hi guys,

Im pretty sure I get most of what you suggested (from this thread and the other one: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=41664.20)

Quote
Yea, although I looked through khris' module and I'm not 100% sure how it works... I are not as clever as Khris.

But!

As a very poor work around you could make a copy of the sprite using the GetAlpha and then run khris resize on that and then once it has been resized, plug the values back into the sprite.. so something like this.

Make a copy of your sprite at full size
iterate through each pixel of the original using GetAlpha to get its value.
Draw on the copy a grey value representing the alpha.
like:

Code:
alpha = GetAlpha(orig.Graphic, x, y);
ds.DrawingColor = Game.GetColorFromRGB(alpha,alpha,alpha); //this is grey
ds.DrawPixel(x,y);


then resize both your original and copy(which contains the alphas)

then iterate through the pixels again putting the alpha back into the original in accordance with the grey values stored in the copy.

This method might not be as inefficient as it seems since I dont think you can keep the drawingsurface open whilst running GetAlpha or PutAlpha so this way you only have to get/release the drawing surfaces a handful of times.

...to copy the alpha pixel by pixel from a sprite and paste it into a dynamic sprite...resize with Khris' module (bilinear) and then getting the gray values of the bilinear resized "alpha sprite" and recopying that into the final cursor image with Calin's plugin (PutAlpha)...

...the only thing I dont know how to do is how to write the code part for running/iterating through each pixel (Im guessing some sort of matrix thing, like (0,0), then (0,1), then (0,2)...etc...for a 120x120 sprite.

Ive got the base here:
Code: ags

    cg = player.ActiveInventory.Graphic;
    inv_curs = DynamicSprite.CreateFromExistingSprite(cg, true);   // create sprite
    
    alphaSprite = DynamicSprite.CreateFromExistingSprite(cg, true);

    //get alpha "color" for each pixel of the 120x120 image 
    int x = 0;
    int y = 0;
    while (x <= some code here to process each pixel in a 120x120 image)
   {
      alpha = GetAlpha(cg.Graphic, x, y);
      DrawingSurface *ds = alphaSprite.GetDrawingSurface();
      ds.DrawingColor = Game.GetColorFromRGB(alpha,alpha,alpha); //this is grey
      ds.DrawPixel(x,y);
    }

    //resize both the cursor sprite and the "alpha sprite" with Bilinear
    alphaSprite.ResizeFilter(alphaSprite.Width/2, alphaSprite.Height/2, eFilterBilinear);
    inv_curs.ResizeFilter(inv_curs.Width/2, inv_curs.Height/2, eFilterBilinear);

    //copy the alpha values of the "alpha sprite" into the cursor sprite for each pixel
    int x = 0;
    int y = 0;
    while x <= (some code here to process each pixel in a 120x120 image)
   {
      alpha = GetAlpha(alphaSprite.Graphic, x, y);
      PutAlpha((inv_curs.Graphic, x, y, alpha);
    }


Im not too sure how to run through each pixel so its nice + efficiently written...Do I use a "while" command with the x and y position of each pixel?  :)
#525
Quoteyea the way you describe is essentially the only way to do it. The GetAlpha() and PutAlpha() functions can do for the alpha what khris' module does for the RGB

holy crap so you're telling me I can use those funtions in conjunction with khris' module and it will work (well once you update it tomorrow)?

if so, ahhhhhhhhh YEAH!
#526
I dont know if this sounds stupid (I really dont know how it all works, really!) but is it somehow possible to "extract" the alpha channel from the png and convert it onto a dynamic sprite that is only a b/w (black+white) opaque image...apply Khris's resizeFilter to that opaque image, and  then reconvert/reapply that newly resized+ filtered b/w image to the png's alpha channel (?)

Again, I really dont know how it all works :-X

I can help test out the blendmodes + post various results if you wish
#527
A "ResizeFilter" (with bilinear) for alpha channel would be great with AGSBlend  ;D  ;D
#528
I was going to post an error I got for a GUI that is larger than the screen resolution but found this thread  ;D

Ive got a gui twice as large as my game res and I wanted to move it around on the screen...I  get the "error":

Code: ags
GUI gBloodSplatter is larger than the screen size and may cause errors in the game.


WHat kind of errors can it cause? Should I wait until this is fixed in a new release, or can I "safely" ignore it for now and continue using my larger GUI?
#529
Hi,

Ive got a mouse mode that permits the player to discard items from the inventory. When you click on an item to discard, the screen fades 75% black in 1 second, and then the confirm box GUI opens up over the darkened screen...when the confirm box GUI finally gets closed, everything goes back to its normal lightness, in 1 second.

Right now what Im doing is I have a gui called "gBlack" 1024x768 (the full size of my screen) and I tween its transparency (with the Tween module) on top of everything at 75%, in 1 second...and then I open my confirm box GUI over it (z orders are set so everything is in the right order)...when its time to return everything to normal, I just tween the gBlack GUI back to fully transparent (and then set its visibility to false).

The thing is, it seems kind of slow since Im tweening the GUI "gBlack" (which is a full-screen GUI) over other gui's that have tweened animations running in "eRepeatTween"...I heard somewhere that tweening GUI's can be slow(?)

My question is, is there a better, faster/simpler way of doing this?

I tried "TintScreen" but I can't get it to only tint the screen behind the confirm box GUI...it tints everything :P

ps: Ive got animation going on in the background so Im not sure if saving a darkened version with a dynamic sprite is what Im looking for...I still would like to see the animation going on while everything that is behind the confirm box GUI is 75% darkened.


--the confirm box isnt darkened...what's behind it, is
#530
Ah ok I see then!

Well, is there a way to intergrate Khris' resize module with Calin's plugin  :-X

:=
#531
sweet.... ;D
#532
Hey Khris,

Cool module man, where's your paypal info!? :P

Ok, I did some tests on a 32 bit png image with transparency (a watch with a semi-transparent shadow under it, and full transparency around the watch:



(Original image, 120x120, png with transparency)

...Since there's no magic pink color I commented out line 185:
Code: ags

//if (c == -1) c = magic_pink;

and removed "magic_pink" in line 200
Code: ags

do.Clear();

to have my resized sprite keep its transparency.

Here are the results:



It seems to me "Bilinear" is the closest to Photoshop's resize (mostly inside the watch), however is there a way to have the semi-transparent shadow get slightly better results, and it's contour? If the contour of the watch and the shadow of the watch was slightly more blurred to match the quality you succeeded in getting for the "inside" of the watch sprite, it would be absolutely PERFECT... ;D...

Is there any way to get that?



#533
Nice Khris! Man oh man this will save so much work :P

You should also post your paypal information so people can forward you some $$$... ;D
#534
Hi,

Im currently resizing dynamic sprites with the resize function but I feel the quality seems a bit "choppy" compared to if I did it in photoshop. I know I can just save an additional sprite with the resized one from photoshop, but Id rather save memory by redrawing + resizing than save a 2nd load of sprites, resized.

Is  there a way in AGS to somehow "mimic" the resizing of images in photoshop where it seems its much smoother/blurry than the AGS resize?




**EDIT**
Does this have something to do with this thread?
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=41551.0
#535
Hey Blue,

This is how Im planning it so far:

1) Have an idea/vision for a good story
2) Think/Plan of main character/main supporting characters/location, objects, etc...
3) Think/Plan of main gameplay elements
4) Think/Plan the whole structure of "mechanics" of the game (menu's, keyboard shortcuts, inventory functions, etc)
5) Start placeholder art + scripting the base structure of the game (custom functions, menus interaction, gameplay elements, etc)
6) Debugging the whole "base" structure and make sure its bug free

Once the whole "base" structure is finally solid, Ill start writing the puzzles, the dialog, etc...aand integrating them one at a time...and then when all that is done and "set in stone", Ill do the final "polished" art/animations.

Pretty much the "plan", but who knows if thats a good way...Ive never finished a game yet :P
#536
Well Holy CRAP, this works SUPER nicely...now the newly drawn cursors have perfect alpha blending!

This will save me from having to draw many cursor sprites individually...like close to a hundred, serious :P

You made my day,

Thanks Khris!!
#537
Ok, if I use the first solution for "void clearThisSprite":
Code: ags
 (DrawAlpha(Buffer.CursorGraphic, 1827, 0, 0, 0);)
I get 99% of what I want, except of course the opaque background of sprite 1827.

Now, if on the other hand I use the other solution for "void clearThisSprite":
Code: ags

  clearSprite = DynamicSprite.CreateFromExistingSprite(Buffer.Graphic);
  DrawingSurface *surface = clearSprite.GetDrawingSurface();
  surface.Clear();
  Buffer.Graphic = clearSprite.Graphic;
  surface.Release(); 


...this is where I get errors...First of all, the pointer's cursor becomes the arrow image over an invisible background (doesnt show the arrow over the item's cursor, just the arrow)...and secondly, when I go back into the inventory window with that "only the arrow" cursor, and I try clicking on another item, I get an error like this:
Code: ags

Error: DynamicSprite.CreateFromExistingSprite: sprite 1834 does not exist


**EDIT**
ps: The error pop-up box didnt give me any lines, its one of those internal errors (not the kind that gives an error message in the ouput window).

**EDIT**
Ok, well I got it to work finally, the way I wanted...the only thing is, the result of the blended sprites is much nicer if instead of clearing the sprite to be drawn on, I put an opaque sprite and then draw my alpha arrow over it...if the sprite being drawn to is fully transparent, the result of the combination with DrawAlpha seems to be a bit "blocky"....as in, the gradient shadows arent smooth, but just black, and blotchy/blocky.

Here is what I did:

Code: ags

void clearThisSprite(InventoryItem *Buffer)
{
  //DrawAlpha(Buffer.CursorGraphic, 1827, 0, 0, 0);

  clearSprite = DynamicSprite.CreateFromExistingSprite(Buffer.CursorGraphic);
  DrawingSurface *surface = clearSprite.GetDrawingSurface();
  surface.Clear();
  Buffer.CursorGraphic = clearSprite.Graphic;
  surface.Release(); 
}
  
void drawResumeItemCursor()
{
  clearThisSprite(iBufferItem132);
  DrawAlpha(iBufferItem132.CursorGraphic, player.ActiveInventory.CursorGraphic, 0, 0, 0); 

  //draw Resume Arrow over the item's cursor into sprite iBufferItem132.CursorGraphic
  DrawAlpha(iBufferItem132.CursorGraphic, 1826, 0, 0, 0);
  mouse.ChangeModeGraphic(eModePointer, iBufferItem132.CursorGraphic);
  mouse.ChangeModeHotspot(eModePointer, 65, 34);
}  



Arrow drawn onto a transparent sprite (with the "clear" function):



Arrow drawn on an opaque sprite:




All that is left to figure out is why is the combined sprite nicer when the background is opaque...and then trying to fix that!
#538
Hey Calin,

Im testing this out and it awesome! I was wondering if you were planning on making some sort of "clear to alpha" function for this plugin? As in, you write something like:

int ClearToAlpha(int sprite);


This would just wipe the sprite clean and make it all transparent so when you want to redraw on it, you know the base is totally "clean"/transparent.

(If this is stupid let me know :P)


**EDIT**

Check out this thread: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=41597.0

Im guessing when you clear a surface (surface.Clear), that surface is no longer a 32 bit sprite or something and would explain why when you draw on top of it the gradient alpha is blocky/choppy?


**Never mind!! :)
**Great plugin :)
#539
Ok, well I went another route since I think it has the potental of being easier...although I ran into a problem and Ive tried for quite a while now to fix it:

1) What I decided to do is when I select an item, its cursor graphic gets drawn into temp sprite 132:
Code: ags

  if (mouse.Mode == eModeSelectInv || mouse.Mode == eModeUseinv) //save the "Resume with Item" cursor graphic to a variable
  {
    //clear sprite 132 so it can be drawn to
    clearThisSprite(iBufferItem132);
    
    //draw default cursor onto empty sprite 132, save it temporarily   
    DrawAlpha(iBufferItem132.Graphic, overItem.CursorGraphic, 0, 0, 0);
    bDrawn = false;
  }


2) In rep exec, if the mouse is over my "resume" button in the inv menu, drawResumeItemCursor gets called:
Code: ags

void clearThisSprite(InventoryItem *Buffer)
{
  DrawAlpha(Buffer.Graphic, 1827, 0, 0, 0);
  
  //clearSprite = DynamicSprite.CreateFromExistingSprite(Buffer.Graphic);
  //DrawingSurface *surface = clearSprite.GetDrawingSurface();
  //surface.Clear();
  //Buffer.Graphic = clearSprite.Graphic;
  //surface.Release();  
}
  
void drawResumeItemCursor()
{
  clearThisSprite(iBufferItem133);

  //draw 132 default item image onto empty sprite 133
  DrawAlpha(iBufferItem133.Graphic, 132, 0, 0, 0);  
 
  //draw Resume Arrow over the item's cursor into sprite 133
  DrawAlpha(iBufferItem133.Graphic, 1826, 0, 0, 0);

  mouse.ChangeModeGraphic(eModePointer, iBufferItem133.Graphic);
  mouse.ChangeModeHotspot(eModePointer, 65, 34);
}  


Anyways, it works fine if the sprite image in "clearThisSprite" is opaque (1827)...Of course I dont want that...If I make sprite 1827 a fully transparent png, it wont really "replace" the other sprite with itself, it just draws "nothing" over it...

How can I "clear" a sprite to nothing?

ps: I checked the "clear" command in the manual and tried it but it doesnt seem to work in this case(dynamic sprites not existing):

Code: ags

void clearThisSprite(InventoryItem *Buffer)
{
  //DrawAlpha(Buffer.Graphic, 1827, 0, 0, 0);
  
  clearSprite = DynamicSprite.CreateFromExistingSprite(Buffer.Graphic);
  DrawingSurface *surface = clearSprite.GetDrawingSurface();
  surface.Clear();
  Buffer.Graphic = clearSprite.Graphic;
  surface.Release();  
}


Im really not sure how to proceed here!
#540
Hey Khris!

Ok, Ill try that out sometime today and let you know what happens!
SMF spam blocked by CleanTalk