Using a BG drawed as a GUI backgroundgraphic Part 2

Started by JpSoft, Thu 12/06/2008 16:19:23

Previous topic - Next topic

JpSoft

Im sorry if I'm making to many answers... ::)

I finished the random-map generator, which creates a room using pre-defined tiles. The room BG is originally empty (just a big 1280*880 black screen). I used the getdrawingsurfacecreatefrombackground, drawed the tiles using the map generator and then release the surface. It looks fine and the game runs properly.

Now i want take a screenshot of the BG created, resize it and use as BG of the GUI minimap, but when i call create a sprite from background, all i have is a empty one (like the original BG).

Are there any way where i could use the new BG created image?

Thanks in advance...

Jp

GarageGothic

Did you Release() the background's drawingsurface before creating the map sprite?

JpSoft

Quote from: GarageGothic on Thu 12/06/2008 17:08:46
Did you Release() the background's drawingsurface before creating the map sprite?

Yes, the drawings surface is released when the map-generator finish. Also, i tried wthout deleting the sprite until the player leaves the room, but whatever i do i only get a transparent sprite.

Lt. Smash

have you tried using DynamicSprite.CreateFromDrawingSurface and DynamicSprite.CreateFromScreenShot?

DynamicSprite.CreateFromBackground just copies the rooms background image and not your drawings above it.

GarageGothic

#4
Quote from: Lt. Smash on Thu 12/06/2008 19:40:04DynamicSprite.CreateFromBackground just copies the rooms background image and not your drawings above it.

Are you sure? If so, this is changed behaviour, and several of the older modules (HyperText module, lake module, dropdown menu module etc.) that use the background as a buffer for RawDrawing onto DynamicSprites would be broken.

Did you Release() the DrawingSurface it in the same game loop as drawing the background? If so, try putting a Wait(1); in-between the functions and see if it changes anything. It could be that the background isn't updated until the screen refreshes.

JpSoft

I released the drawing surface in the same function that creates the room background(function RandomMap). Inside this function i also try in many ways to find the solution, but i was unable, since looks like the new background is only displayed in the screen but not stored in the engine. (a clarification about this issue would be nice)

I found and alternative solution: i declared a dinamic sprite in the global script and created and exact copy of the room BG at the same time (just drawing 2 different surfaces at same time, 1 for background and another for use as a internal sprite);when finished, i just resized the sprite and assigned it as gui.backgroudngraphic (after release both surfaces). Since the sprite is a global variable, it can be deleted when player leaves room from room script. Of course, its not the ideal alternative, but the game works fine with it.

Example

In global Script=
DynamicSprite *sprite;

Inside function=
DrawingSurface *surface = Room.GetDrawingSurfaceFromBackgrond();
sprite = Create (roomWidth, RoomHeight);
DrawingSurface *secondsurface = sprite;
.
.
.
surface.DrawImage(stuff here);
secondsurface.Drawimage(the same stuff here);
.
.
.
surface.Release();
secondsurface.Release();
sprite.Resize(80,50);
gMinimap.BackGroundGraphich = sprite.Graphic;

In Room script, when player leaves room=
sprite.Delete();

Note that the game speed dont become too slow. Creating a total of 2560 sprites for each surface, randomizing it and matching it looks properly only takes 1.2 seconds in my old CPU (pentium 3 - 600 MHZ- 128 MB RAM) I tested it and is a enough good performance.

Thanks for your answers

Jp

GarageGothic

#6
If you update to the the soon-to-be-final AGS 3.0.2 you could just use DynamicSprite.CreateFromDrawingSurface before releasing the background instead of using CreateFromBackground (or your new method of doing double the work). This should also be quicker as the surface is already in memory.

Edit: I should mention that I tested CreateFromBackground, and it seems to work as it should, at least in the latest beta. There were some problems in earlier versions with GetPixel returning incorrect values for drawn surfaces though, so perhaps your issue is related to that bug.

JpSoft

#7
Quote from: GarageGothic on Thu 12/06/2008 22:52:49
I should mention that I tested CreateFromBackground, and it seems to work as it should, at least in the latest beta. There were some problems in earlier versions with GetPixel returning incorrect values for drawn surfaces though, so perhaps your issue is related to that bug.

You are right; i were confused since the BG changes remain until the players leaves the room (when the BG frame is restored).

Now, adding the funtion to give and eyer-bird perspective, im having a lot of troubles with random-maps. Since the room just have 1 BG frame (where i need redraw every time the player changes the viewport) i need be able to use the original sprite drawed to get the original room aspect. But i dont find the way to use dynamic sprites for BGs andi dont find nothing in the current drawing options.

Using AGS 3.0. I tried to upgrade the game to 3.0.1 but i had too many troubles so i just downgrade again. Of course, i will upgrade for sure if 3.0.x includes something like Room.GetDrawingSurfaceForWalkableArea(int AreaNumber)  ;D

I hope anyone have sugerences, thanks

Jp

JpSoft

After almost 1 week working on this issue, i finally solved this adding a new empty BG frame; so, now, the map is created  on BG(1) and BG(0) is used to show the perspective.

This is not the correct topic, but could be very usefull a way to just use a dynamic aprite as a BG frame.

Thanks

JP

SMF spam blocked by CleanTalk