The Dink Network

Re: A Note About Trimming Background Sprites

October 14th 2013, 08:33 PM
goblins.gif
Be wary, if you place a background sprite that has been trimmed on any screen that can call a stop_entire_game() function than a wierd thing will happen. Because leveling up calls the stop_entire_game() function this includes any screen that allows you to gain experience.

Here is what happens:
When the game is resumed after stop_entire_game() is called, all the background sprites will be redrawn, but when they are redrawn they forget that they were trimmed and draw the entire sprite instead of just the trimmed area.

Here's a pretty serious example from my own DMOD (it's using a modified menu script that does stop_entire_game):
Before stop_entire_game()
After stop_entire_game()

The solution is to not trim background sprites. Instead use normal (person/creature) sprites but set depth to -100 or so (so they are behind everything else) if you need to trim the sprite.

Edit: Also be sure to set nohit to true, or it won't really function like a background sprite. (background sprites blocking fireballs and such is really bad design anyways).
October 14th 2013, 08:44 PM
spike.gif
Yeah, it's a pain in the ass. Clipping sprites is so much fun, though, and lends to some really ingenious use of existing graphics. I'd sooner redesign the level-up system, I think... something that doesn't require stop_entire_game.
October 14th 2013, 08:47 PM
goblins.gif
Yes, that would be a good alternative solution. You could put leveling up in the menu and allow the player to allocate their points on demand or something like that. Then stop_entire_game() would never need to be called.

And yeah, sprite trims are fun. You can make some unique looking rooms without ever adding any new graphics to the game.
October 14th 2013, 08:48 PM
wizardg.gif
Setting a negative depth que and checking no_hit() is pretty much the same thing as setting a sprite to background anyways.
October 14th 2013, 08:50 PM
goblins.gif
Setting a negative depth que and checking no_hit() is pretty much the same thing as setting a sprite to background anyways.

Yup, has the same effect and is less buggy.
October 14th 2013, 08:57 PM
spike.gif
Ah, yeah, did you say it ONLY applies to background sprites? In that case, just making them into real sprites totally circumvents the problem quite nicely indeed. Although, I think redesigning level-ups isn't a bad idea for anyone with the DinkC stones to do it anyway; it always bothered me how the blood and corpses just disappear, not to mention times when the level-up chime doesn't play and you end up accidentally spending your level-up points on attack.
October 14th 2013, 09:11 PM
goblins.gif
Ah, yeah, did you say it ONLY applies to background sprites?

That is correct. If you use normal trimmed sprites there is no problem. I really want to use stop_entire_game() in my menu system but now that you mention it yeah... blood will disappear along with any other background sprites that have been added that didn't have an editor number. I doubt there is any way to fix it without getting rid of stop_entire_game. So it seems I have to pick one or the other. dang!

For my Dmod I don't really desire a new level up system... However, you are right, it's too easy to accidentally spend your point on attack since the attack button and confirm button are the same...

I wonder if there is way to circumvent that problem without using a different level up system and without getting in the way. I mean, I could add a "precheck" that doesn't let you pick a point until you select the second option. But that would get annoying too I think.
October 14th 2013, 09:25 PM
wizardg.gif
I'd add a global "skillpoints" then make the lraise.c script basically just go, &level += 1; &skillpoints += 1;

Then I'd edit the escape.c script and add a choice for skillpoints.

if(&skillpoints >= 1)
{
choice_start();
"strength"
"defense"
"magic"
choice_end();

if(&result == 1)
{
&strength += 1;
&skillpoints -= 1;
}

And so on. That'd work right?

Instead of doing something in escape.c, it might be nicer to set something up using keys. so like,
[ - strength
' - defense
/ - magic

Though it might seem a little pointless to set keys for such small tasks. Though it's not like those keys are going to be used anyways.
October 14th 2013, 09:37 PM
custom_coco.gif
cocomonkey
Bard He/Him United States
Please Cindy, say the whole name each time. 
I never set anything at all to "background" for this reason, I just give it a depth dot of -1, or less than that if it has to be behind something that's already been set to a negative number.

Despite this, stop_entire_game still causes weird problems. Not when lraise.c is called, but I tried adding it to escape.c (because it would be nice to have things not attack you when you navigate the menu, right?) and the result was that every time I pressed escape, all the sprites on the lower half of the screen would disappear until I returned to the game.
October 14th 2013, 09:40 PM
goblins.gif
I had to tackle the same problem. The solution (I think) was to add a wait(0) before stop_entire_game(). I'm not entirely sure why it works, but I haven't had any problems after doing that so far.

I'd add a global "skillpoints" then make the levelup.c script basically just go, &level += 1; &skillpoints += 1;

Yes, that could work. However my menu is already getting crowded so I haven't decided if I want to take that route or not.
October 15th 2013, 07:17 AM
slimeg.gif
metatarasal
Bard He/Him Netherlands
I object 
This problem is new for me. I did realize that background sprites had some quirks, but that this undoes the clipping is kinda weird. This really is a nasty problem as in most DMODs the only time this would happen is during a level-up, which would most likely not get caught in testing.

I still use background sprites quite often, but for some cases setting the depth dot to a negative value is a necessary workaround. I wouldn't set it to -1 as it may still appear above sprites that have been screen-matched from the screen above. A value of -200 or so is usually safe. Also, I recommend setting the nohit to 1 to truely get a background-like sprite.
October 15th 2013, 07:27 AM
goblins.gif
I updated my original post to include setting nohit to the sprites you want to use as background sprite replacements, for clarity.
October 15th 2013, 11:33 AM
wizardg.gif
nohit should be on all non-hard non-moving sprites.
October 23rd 2013, 08:25 AM
peasantm.gif
shevek
Peasant They/Them Netherlands
Never be afraid to ask, but don't demand an answer 
something that doesn't require stop_entire_game.

But stop_entire_game is really nice for gameplay. I'd rather redraw the screen and lose all non-editor background sprites. (I think that happens during level-up anyway.)
October 23rd 2013, 04:16 PM
wizardb.gif
Kyle
Peasant He/Him Belgium
 
I love those findings so much