Hi all,
I am new to AGS. I've been reading the manual and trying to understand all the DrawingSurface and DynamicSprite methods and functions.
Right now I am a bit confused by how to actually access the sprite and iterate over each pixel located on the sprite
for example, I have the following code in AGS.. It seems that I have to grab a copy of some sprite, extract the surface, do operations on that surface and then convert it back to a sprite and then draw that sprites Graphic to the screen? Is this the correct way of doing it?
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(47); //get a sprite first ( this is referring to a specific character object view in the sprite manager)
DrawingSurface* spriteSurface=sprite.GetDrawingSurface(); //get the sprites drawing surface... the drawing surface is technically an array[x,y] of pixels?
spriteSurface.DrawingColor = 25; //this sets some drawing color for a single pixel
spriteSurface.DrawPixel(0, 1); //replace the pixel in the sprite i.e the copy of the character @ pixel (0,1)
//I suppose here i would just loop through from 0,0 to spriteSurface.width and spriteSurface.height using a for or while loop and do my image filtering operations here on the pixels
// using GetPixel(x,y) and DrawPixel(x,y)
DynamicSprite*convertSpritetoSurface =DynamicSprite.CreateFromDrawingSurface(spriteSurface, 0, 0, s.Width, s.Height); //i have to convert the drawing back to a surface so i can release it to the screen?
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground(); //this gets the whole room screen into a drawing surface
surface.DrawImage(100, 80, convertSpritetoSurface .Graphic);
convertSpritetoSurface.Delete(); //free up memory
surface.Release(); //relase the surface to video so ags now draws it to the screen?
sprite.Delete();
I have an idea to implement a very simple blurring/area sampling algorithm as seen below, so ideally i have to access every pixel and create a new sprite surface based on these operations.
I think the ags equivalent here would be something like GetPixel(x+1,y) for SourceMap[x+1,y] ..
ResultMap[x, y] := ( SourceMap[x, y] + SourceMap[x+1, y] + SourceMap[x-1, y] +SourceMap[x, y+1] +SourceMap[x, y-1] ) DIV 5
Also please note: I know that accessing every pixel and changing that can/will be slow. For now that is okay I just need to get my head around how to work with sprites and the graphics array's in AGS. once I have mastered that, then I can look into optimization of my code.
Thanks for whoever takes a look :)
Try it?