DrawImage onto background problems

Started by Knox, Thu 17/05/2012 00:07:11

Previous topic - Next topic

Knox

Hi,

Ive been trying to draw a sprite onto a scrollable background (larger than game resolution) without success. It seems to work when I draw lines/triangles, etc...but for some reason I cant get it to work with sprites.

What I want to do is I have a button on a gui that when pressed draws a sprite onto the room's background (but saves a copy of the original first). The room's background will stay this way with the sprite drawn onto it until the player presses the same button again...when he does, the background image reverts back to the way it as before.

Here's what I am currenty doing:

Code: ags


//global 
DrawingSurface *dsCurrentMap;
export dsCurrentMap;
DrawingSurface *dsMapBackup;
export dsMapBackup;

void drawLabelsOnCityMap(int iX, int iY, int iMapLabels)
{
  dsCurrentMap = Room.GetDrawingSurfaceForBackground();
  dsMapBackup = dsCurrentMap.CreateCopy();
  
  dsCurrentMap.DrawImage(0, 0, iMapLabels, 0);
  dsCurrentMap.Release();
}

//when button is pressed:
void manageStreetNamesOverlay(int iRoom)
{
  int iOverlayLabelSprite;
  if (iRoom == 299) iOverlayLabelSprite = 3639;
  //else if (iRoom ==) iOverlayLabelSprite =; 
  
  if (bStreetNamesOn && !bStreetActivated) //Show Labels
  {
    Display("Draw labels onto background"); //debug line
    Wait(40);

    drawLabelsOnCityMap(0, 0, iOverlayLabelSprite);

    //SetBackgroundFrame(1); //WITH DUPLICATE ROOM + LABELS PNG
    bStreetActivated = true;  
  }
  else if (!bStreetNamesOn && bStreetActivated) //Hide Labels
  {
    Display("Remove map labels..."); //debug line
    Wait(40);

    //**do "revert to original background image (dsMapBackup) script" and place it here

    //SetBackgroundFrame(0); //WITH DUPLICATE ROOM + LABELS PNG
    bStreetActivated = false;
  }
}



Right now I dont see anything being drawn onto the background. Ive also tried the solution of just using a 2nd frame for my background and showing that, but I plan on having many maps so I dont want to duplicate each room's background just for displaying the street names/locations.
--All that is necessary for evil to triumph is for good men to do nothing.

Gilbert

I haven't found any problems with the codes yet, but have you checked whether the bg and the sprite to use are of the same colour depth as the game? There may be problems with drawing stuff with the components' colour depths do not match.

Khris

Only a shot in the dark but try this:
Code: ags
  dsCurrentMap.DrawImage(0, 0, iMapLabels);

There used to be a bug with the transparency of certain things where setting it to 0 was interpreted as "not being visible at all".

Also, I assume you're indeed calling manageStreetNamesOverlay(299);?

dbuske

#3
You must really be making quite a technical game.  What kind of game are you making?
Edited by Mod: Don't quote the whole post when it's not necessary.
What if your blessings come through raindrops
What if your healing comes through tears...

Knox

Hi guys!

@Iceboty V7000a: The sprite is a 32-bit png sprite with transparency (its quite large since its all the street names of the city, think google maps when you show the labels on the map). The background is a png without transparency, although even if I try to draw a png sprite without transparency I still cant see it :P

@Khris: Hmm, ok Ill try that! Whats weird is after line 14, as a test, I inserted this code block:
Code: ags

  DrawingSurface *surface2 = Room.GetDrawingSurfaceForBackground();
  surface2.DrawingColor = 14;
  surface2.DrawLine(0, 0, 2000, 1750, 5);
  surface2.Release();

and THEN the sprite appears (along with the yellow line)! Obviously I dont want to add those lines, but why would the sprite appear only after I call those lines? Is it like a refresh problem or something cause the room is so large? Its embarassingly large (6464x3712)

Oh, and Im calling "manageStreetNamesOverlay(player.Room);"

@dbuske: Well the part Im fiddling with now is the isometric driving part of the game...and since I dont have mad programming skills the pace is quite slow, hehe! Its a police quest style game and Im trying to get all the technical stuff working as a base before actually making the final art and stuff. :)
--All that is necessary for evil to triumph is for good men to do nothing.

Khris

You could try a Wait(1); after releasing the DrawingSurface, but it shouldn't be necessary at all.
Did you try my suggestion? What happens if you try a smaller sprite?

Knox

#6
Ok, I tried your suggestion of not putting a "0", and it didnt change the results. :(

I then tried this in a different room (1024x768), a small png alpha sprite (54x44) :
Code: ags

//when a hotspot in the room is clicked on (to test):
  dsCurrentMap = Room.GetDrawingSurfaceForBackground();
  dsMapBackup = dsCurrentMap.CreateCopy();
  
  dsCurrentMap.DrawImage(512, 384, 3875);
  dsCurrentMap.Release();
  Wait(1); //all the above doesnt show the sprite
  //however, when I un-comment out the lines below, now the sprite appears (with the yellow line):
  /*
  DrawingSurface *surface2 = Room.GetDrawingSurfaceForBackground();
  surface2.DrawingColor = 14;
  surface2.DrawLine(0, 0, 512, 384, 5);
  surface2.Release();
*/


**EDIT**
I also tried this, and it works like I want to (but Im drawing twice so its a hack):
 
Code: ags

  dsCurrentMap = Room.GetDrawingSurfaceForBackground();
  dsCurrentMap.DrawImage(512, 384, 3648);
  dsMapBackup = dsCurrentMap.CreateCopy();
  dsCurrentMap.DrawSurface(dsMapBackup);
  dsCurrentMap.Release();
  dsMapBackup.Release();
  


**I also tested various transparency values (between 1 and 99), and it doesnt affect the sprite's transparency at all. (32bit game)
--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

Hey knox, I think I still owe you some programming time, so you can feel free to PM me. The code looks fine, but I'd be interested to take a look.

(BTW, thanks to some work I did for Dave Gilbert, I now have a system that can probably actually handle your game haha!)

Sephiroth

Sorry if this is obvious but the coordinates specified are room coords, so you may be drawing on a hidden part of the screen? The line can be seen because it goes all across the screen? (viewport problem)

Knox

@Monkey: Ok, I pm'd you :)

@Sephiroth:

Well at first thats what I thought too, but I then tested it on a smaller room (1024x768) and put it smack dab in the middle...same results. When I draw an overlay it works perfectly fine with the same coordinates...Maybe Ive got confilcting scripts somewhere, I hope not cause  that will be a nightmare debugging that!

Is there a possibility theres like a bug with the drawImage on background function itself?
--All that is necessary for evil to triumph is for good men to do nothing.

Ryan Timothy B

QuoteThe sprite is a 32-bit png sprite with transparency
[..]
I also tested various transparency values (between 1 and 99), and it doesnt affect the sprite's transparency at all. (32bit game)
First off you can't draw a sprite with alpha channels with using the draw image transparency. Only three options to get around this. One is to create multiple sprites at different transparencies. The other is to grab a rectangle portion of the background that is the size of the alpha channeled sprite you're drawing, draw the sprite to that at full transparency, then draw that background portion plus full opacity sprite to the background with a transparency. Or the other is the same as the previous option, just assigning it to an object/GUI and changing the transparency.

The only thing I can see wrong with your code is possibly the Export call. Why is it that you need to export it? Are you using these drawingSurfaces with other functions? That could likely be the possible issue here.

I have personally never kept the drawing surface beyond the function it's in. I've always kept the DynamicSprite discarding the drawing surface. I don't normally work with backgrounds though, so this looks like the optimal method having to simply just use: dsCurrentMap.DrawSurface(dsMapBackup);  instead of using draw image to draw a background copy.

Knox

Hey Ryan,

Nah I tried commenting out the export part without any luck. Right now the only way I can hack my way to make it work is doing the drawing twice...but the thought of keeping backup copies of the map backgrounds (which are really big) until thep player decides to turn off the labels again is making me think maybe Ishould just do like I did in the beginning: making duplicates of the whole maps with labels drawn in photoshop and just switching the room's frames instead. That will double the amount maps I need to import and make the sprite file larger, but I guess its simpler and doesnt require rawdraw/keeping large maps in memory, etc...If I was a better coder or had more knowledge on all the rawdraw stuff maybe this wouldnt "worry me" but for now I think Ill put it aside...eeekk!!

So for now Ill just stick to doing this when the player wants to hide/show the labels:
SetBackgroundFrame(0); //map without labels
//or
SetBackgroundFrame(1); //map with labels
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk