Next / Back buttons on a Fullscreen renderer?

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Next / Back buttons on a Fullscreen renderer?

Post by Gambit37 »

I want to display a series of full screen images within a fullscreen renderer, that can be viewed using a next/back button, sort of like a slideshow. I looked at Ian_scho's events manager to get ideas but didn't really understand it.

Here's my basic calling code:

Code: Select all

dsb_fullscreen(gfx.myfullscreenbackground, pagerfunction, nil,true,true)
Then I'd have a "pagerfunction" for handling the back/next to display different images. What I don't understand is how, in that function, I can draw a bitmap over the full screen background, and then replace it with a different one when the user clicks next/back? I mean, I understand how I could use a counter or something to track the next/back clicks and select the right bitmap, but I don't understand the right commands to actually draw the "current page" bitmap and remove the existing one...? I tried adapting stuff in the test_dungeon, but DSB complains that "bmp" does not exist or something...

I don't think I really understand this notion of having to draw a bitmap into another one, or under what circumstances the "bmp" bitmap is available?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Next / Back buttons on a Fullscreen renderer?

Post by Sophia »

The issue is that you're passing your full screen background to dsb_fullscreen directly, so that's all it ever draws.
If you want to do something fancier, you have to write your own function and then pass that to dsb_fullscreen.

For example, this code will do the same thing as your current code:

Code: Select all

function backgroundfunction(bmp, mx, my)
   dsb_bitmap_draw(gfx.myfullscreenbackground, bmp, 0, 0, false)
end

dsb_fullscreen(backgroundfunction, pagerfunction, nil, true, true)
However, now you have your own function where you can control what goes on during the background drawing-- and bmp, the drawing target, is now defined.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Next / Back buttons on a Fullscreen renderer?

Post by Gambit37 »

But I tried it that way too, and instead did some drawing code in the pager function (to draw each page of content), and DSB complained about "bmp" not existing...?

I guess I don't understand how the drawing function and the click function inter-connect? Where should I create the click-checking code that displays my pages? In the drawing function, or the clicking function?

And how do I hide a bitmap I previously displayed to then show a new one in it's place?

Am sooooooo confused.....!
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Next / Back buttons on a Fullscreen renderer?

Post by Sophia »

It's a bit more low-level than you were envisioning, it seems. Like the example says, the drawing function is executed every frame. This means that to "hide" a bitmap, all you have to do is not draw it, because the drawing function is executed every frame, so anything you're not explicitly drawing in your code is not drawn.

You can't put drawing code in the pagerfunction because that's just what happens when there is a mouse click. All drawing code has to go in the backgroundfunction. However, you should check for clicks in the click function, i.e., pagerfunction. If this still seems confusing, it would help to define a table to store information to transfer between the two of them, in particular, so most of your logic can be handled wherever it is most suitable.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Next / Back buttons on a Fullscreen renderer?

Post by Gambit37 »

Sophia wrote:it would help to define a table to store information to transfer between the two of them, in particular, so most of your logic can be handled wherever it is most suitable.
Aha! Right, I think this makes more sense... that's the bit I wasn't getting (how to share data between the two functions; thought they were self contained) so the click function could update a counter, and I could use the counter to point to an index in a table that stores a list of bitmaps.... Then the draw function reads that counter value to get the right index and display the right bitmap? Is that a clean way of doing it? I worry sometimes that I'm too much of a hacker, and would like to use elegant code -- but at the end of the day, I just want something that works ;-)

Did you say all Lua variables are global unless you define otherwise?
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Next / Back buttons on a Fullscreen renderer?

Post by Gambit37 »

OK, I'm stuck. I have this table and counter variable set:

Code: Select all

champions = {}
champions[1] = { name="Carla ", imgfull="gfx.champion_full_carla" }
champions[2] = { name="Cassie ", imgfull="gfx.champion_full_cassie" }
champions[3] = { name="Chloe ", imgfull="gfx.champion_full_chloe" }
champion_counter = 1
In the draw function of my full screen renderer, I have this line:

Code: Select all

dsb_bitmap_draw(champions[champion_counter]["imgfull"], bmp, 0, 0, false)
DSB errors out with: "FATAL LUA ERROR: Lua Function fullscreen_draw: ...ra Prime\_dsb50\test_dungeon_me/select-champions.lua:36: dsb_bitmap_draw requires Bitmap in param 1"

However, if I output champions[champion_counter]["imgfull"] to the log, it does list the correct first bitmap for counter=1 ("gfx.champion_full_carla").

I don't get what's wrong?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Next / Back buttons on a Fullscreen renderer?

Post by Sophia »

You're passing it a string containing the text "gfx.champion_full_carla", which is not a bitmap. You're on the right track, but you just have to set up the string so that it is an array index, like you did before.

Code: Select all

champions = {}
champions[1] = { name="Carla ", imgfull="champion_full_carla" }
champions[2] = { name="Cassie ", imgfull="champion_full_cassie" }
champions[3] = { name="Chloe ", imgfull="champion_full_chloe" }
champion_counter = 1

dsb_bitmap_draw(gfx[champions[champion_counter].imgfull], bmp, 0, 0, false)
See, now it's taking imgfull as an index in the gfx array, which is what DSB needs there.

As a side note, you were also correct when you had ["imgfull"]. The expressions array.element and array["element"] are identical in Lua.
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Next / Back buttons on a Fullscreen renderer?

Post by Gambit37 »

Doh! Another learning point finally absorbed. I wasn't thinking clearly that "gfx" is a massive array already.....! Thank you for your patience, I'm sure basic enquiries like this must drive you nuts :P
User avatar
Gambit37
Should eat more pies
Posts: 13715
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Next / Back buttons on a Fullscreen renderer?

Post by Gambit37 »

Question: Is there a way of fading in a bitmap over time (ie, change it's alpha from fully trans to fully opaque). I know the fullscreen renderer can fade, but it would be cool if bitmaps drawn on other bitmaps can also fade, with a user specified duration. Is that currently possible?
Post Reply