Author Topic: DrawImage onto background problems  (Read 395 times)  Share 

General_Knox

  • Storm Behind The Badge
DrawImage onto background problems
« on: 17 May 2012, 00:07 »
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: Adventure Game Studio
  1.  
  2. //global
  3. DrawingSurface *dsCurrentMap;
  4. export dsCurrentMap;
  5. DrawingSurface *dsMapBackup;
  6. export dsMapBackup;
  7.  
  8. void drawLabelsOnCityMap(int iX, int iY, int iMapLabels)
  9. {
  10.   dsCurrentMap = Room.GetDrawingSurfaceForBackground();
  11.   dsMapBackup = dsCurrentMap.CreateCopy();
  12.  
  13.   dsCurrentMap.DrawImage(0, 0, iMapLabels, 0);
  14.   dsCurrentMap.Release();
  15. }
  16.  
  17. //when button is pressed:
  18. void manageStreetNamesOverlay(int iRoom)
  19. {
  20.   int iOverlayLabelSprite;
  21.   if (iRoom == 299) iOverlayLabelSprite = 3639;
  22.   //else if (iRoom ==) iOverlayLabelSprite =;
  23.  
  24.   if (bStreetNamesOn && !bStreetActivated) //Show Labels
  25.   {
  26.     Display("Draw labels onto background"); //debug line
  27.     Wait(40);
  28.  
  29.     drawLabelsOnCityMap(0, 0, iOverlayLabelSprite);
  30.  
  31.     //SetBackgroundFrame(1); //WITH DUPLICATE ROOM + LABELS PNG
  32.     bStreetActivated = true;  
  33.   }
  34.   else if (!bStreetNamesOn && bStreetActivated) //Hide Labels
  35.   {
  36.     Display("Remove map labels..."); //debug line
  37.     Wait(40);
  38.  
  39.     //**do "revert to original background image (dsMapBackup) script" and place it here
  40.  
  41.     //SetBackgroundFrame(0); //WITH DUPLICATE ROOM + LABELS PNG
  42.     bStreetActivated = false;
  43.   }
  44. }
  45.  
  46.  

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.

Iceboty V7000a

  • Local Moderator
  • * KILL* * KILL * * KILL *
    • Lifetime Achievement Award Winner
    •  
Re: DrawImage onto background problems
« Reply #1 on: 17 May 2012, 03:31 »
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

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: DrawImage onto background problems
« Reply #2 on: 17 May 2012, 10:45 »
Only a shot in the dark but try this:
Code: Adventure Game Studio
  1.   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);?
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: DrawImage onto background problems
« Reply #3 on: 17 May 2012, 12:06 »
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.
« Last Edit: 17 May 2012, 15:17 by Iceboty V7000a »
What if your blessings come through raindrops
What if your healing comes through tears...

General_Knox

  • Storm Behind The Badge
Re: DrawImage onto background problems
« Reply #4 on: 17 May 2012, 12:32 »
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: Adventure Game Studio
  1.   DrawingSurface *surface2 = Room.GetDrawingSurfaceForBackground();
  2.   surface2.DrawingColor = 14;
  3.   surface2.DrawLine(0, 0, 2000, 1750, 5);
  4.   surface2.Release();
  5.  
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

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: DrawImage onto background problems
« Reply #5 on: 17 May 2012, 13:11 »
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?
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

General_Knox

  • Storm Behind The Badge
Re: DrawImage onto background problems
« Reply #6 on: 17 May 2012, 13:37 »
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: Adventure Game Studio
  1. //when a hotspot in the room is clicked on (to test):
  2.   dsCurrentMap = Room.GetDrawingSurfaceForBackground();
  3.   dsMapBackup = dsCurrentMap.CreateCopy();
  4.  
  5.   dsCurrentMap.DrawImage(512, 384, 3875);
  6.   dsCurrentMap.Release();
  7.   Wait(1); //all the above doesnt show the sprite
  8.   //however, when I un-comment out the lines below, now the sprite appears (with the yellow line):
  9.   /*
  10.   DrawingSurface *surface2 = Room.GetDrawingSurfaceForBackground();
  11.   surface2.DrawingColor = 14;
  12.   surface2.DrawLine(0, 0, 512, 384, 5);
  13.   surface2.Release();
  14. */
  15.  

**EDIT**
I also tried this, and it works like I want to (but Im drawing twice so its a hack):
 
Code: Adventure Game Studio
  1.   dsCurrentMap = Room.GetDrawingSurfaceForBackground();
  2.   dsCurrentMap.DrawImage(512, 384, 3648);
  3.   dsMapBackup = dsCurrentMap.CreateCopy();
  4.   dsCurrentMap.DrawSurface(dsMapBackup);
  5.   dsCurrentMap.Release();
  6.   dsMapBackup.Release();
  7.  

**I also tested various transparency values (between 1 and 99), and it doesnt affect the sprite's transparency at all. (32bit game)
« Last Edit: 17 May 2012, 14:19 by General_Knox »
--All that is necessary for evil to triumph is for good men to do nothing.

monkey_05_06

  • AGS Project Admins
  • #1 Straight Basher
Re: DrawImage onto background problems
« Reply #7 on: 17 May 2012, 17:12 »
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!)
By and large I didn't accomplish what I set out to do, but I did accomplish a fair bit. So, there is that.

Re: DrawImage onto background problems
« Reply #8 on: 17 May 2012, 17:27 »
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)

General_Knox

  • Storm Behind The Badge
Re: DrawImage onto background problems
« Reply #9 on: 17 May 2012, 18:35 »
@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.

Re: DrawImage onto background problems
« Reply #10 on: 17 May 2012, 21:03 »
Quote
The 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.

General_Knox

  • Storm Behind The Badge
Re: DrawImage onto background problems
« Reply #11 on: 18 May 2012, 20:42 »
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.