Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Digital Mosaic Games on Fri 05/02/2010 12:51:00

Title: BookPage Turning-Function?
Post by: Digital Mosaic Games on Fri 05/02/2010 12:51:00
I want to make a close-up view from a book where the player should be able to turn over pages.

My first idea to realize this function was that the player could move his mouse near to the border of a page and make the natural page-turning-move like when you turn a page with your hand only in this case with the mouse.
If anyone has an idea how to make this please tell me. I would respect this very much because I think AGS isn´t made for such difficult actions. :-\

My second(and easier) idea, because I think it´s really difficult for a scripter to realize opportunity 1, is that the mouse changes his Graphic/Mode into arrows when it is over the border and of the page. In my case every page is an object in the room. If the pages would be hotspots I would use the "mouse moves over hotspot-Function" but I don´t know how to make it with objects.
I thought of using something like that:

if(mouse.x==oPage1 && mouse.y==oPage1)  {
mouse.ChangeMode(eModeArrowLeft);}

And I don´t know in wich function I should put it.

Title: Re: BookPage Turning-Function?
Post by: Matti on Fri 05/02/2010 13:33:12
A better way would be to make the book (or whatever it is) a GUI. Then you could just change the background image of the GUI depending on the page that is open. You could make the corner of the GUI/page a button to click on and make the page turn animation via changing the image.
Title: Re: BookPage Turning-Function?
Post by: GarageGothic on Fri 05/02/2010 13:40:13
Go with the easy idea. Trust me, I implemented Flash-like page turning in my game and it takes a lot of trigonometry as well as DrawingSurface functions running every game loop (due to AGS not supporting the same kind of masking as Flash). Probably I'll release a module once I untangle it from the rest of my code, but it won't be anytime in the near future.

I'd really say that what implementation would suit you depends a lot on how often this is used in-game as well as how many pages the books are supposed to have. If it's only one book and a handful of pages, and only readable in one room of the game, go with Objects. You can always code a more generic solution once you're more confident with scripting. (An alternative easy solution for a limited number of pages would be to use a room background for the book and use the frames of the background animation for the pages).

The function you're looking for is: Object.GetAtScreen(int x, int y)

So you would do:

if (Object.GetAtScreen(mouse.x, mouse.y) == oPage1) {
 Mouse.Mode = eModeArrowLeft; //though probably you would rather want to keep the same mouse mode and use Mouse.ChangeModeGraphic instead
 }


Edit: Wrote this before seeing Mr. Matti's post. GUIs are the best allround solution. I was trying to minimize the amount of scripting with my suggestions, but seeing as the interaction editor is no more, that's kind of pointless.
Title: Re: BookPage Turning-Function?
Post by: Digital Mosaic Games on Fri 05/02/2010 18:10:31
Quote from: GarageGothic on Fri 05/02/2010 13:40:13
The function you're looking for is: Object.GetAtScreen(int x, int y)

So you would do:

if (Object.GetAtScreen(mouse.x, mouse.y) == oPage1) {
  Mouse.Mode = eModeArrowLeft; //though probably you would rather want to keep the same mouse mode and use Mouse.ChangeModeGraphic instead
  }


In wich function would you put that code? There isn´t a function like "mouse moves over object".
Title: Re: BookPage Turning-Function?
Post by: GarageGothic on Fri 05/02/2010 18:37:14
In the repeatedly_execute() function.
Title: Re: BookPage Turning-Function?
Post by: Digital Mosaic Games on Fri 05/02/2010 20:24:03
Okay, now I have this code in repeadly execute() in my room.
if (Object.GetAtScreenXY(mouse.x, mouse.y) == oPage1) {
  aDoorClose.Play();
  }

For a test there should be my "close-door-sound" if the mouse is over "Page1".
But there happens nothing. :-\
That´s strange...
Title: Re: BookPage Turning-Function?
Post by: Calin Leafshade on Fri 05/02/2010 20:26:04
have you set the rep ex function to be the rep ex function for that room?

You have to assign the function.

its in the same place as "enter room after fade in" and stuff like that.
Title: Re: BookPage Turning-Function?
Post by: Digital Mosaic Games on Fri 05/02/2010 21:16:36
Yes, I have as you can see here:

function repeatedly_execute() {

if (Object.GetAtScreenXY(mouse.x, mouse.y) == oPage1) {
  aDoorClose.Play();
  }
}
 

I know without writing this the game wouldn´t start. My game is working.
It´s only that than, when I move my mouse over "oPage1" nothing happens.
But there should be the sound.
Title: Re: BookPage Turning-Function?
Post by: monkey0506 on Fri 05/02/2010 21:35:25
Quote from: NEON-GAMES on Fri 05/02/2010 21:16:36I know without writing this the game wouldn´t start.

Wait, what??

...anyway...

The repeatedly execute function for rooms is different from every other script. You must open the room, click on the Events icon (the lightning bolt in the Properties pane) and then either a) type the name of a function, or b) click on the ellipses (...) button to create the function. The default name for the function is like room_RepExec() not repeatedly_execute. You can name it repeatedly_execute if you like, but unless it's the function listed in the Events for the room it will not be called.
Title: Re: BookPage Turning-Function?
Post by: Calin Leafshade on Fri 05/02/2010 22:08:38
The exception to this is repeatedly_execute_always() which just needs to be named.. I dunno why theres an inconsistency there.
Title: Re: BookPage Turning-Function?
Post by: monkey0506 on Sat 06/02/2010 00:17:42
The inconsistency is because "repeatedly execute" was formerly implemented as part of the Interaction Editor (pre-3.0) whereas "repeatedly execute always" was never available outside of the script. ;)

(http://www.martingordon.org/blog/wp-content/uploads/2007/01/the_more_you_know.jpg)
Title: Re: BookPage Turning-Function?
Post by: Digital Mosaic Games on Fri 12/02/2010 20:21:04
Hi,

Now I´ve used the repeadly_execute function and it works :)
But when I click on the first page(object which is called "oPage1") there should should be an event but nothing happens. ???
Maybe this don´t work because I use Verbcoin-Control in my game.
Title: Re: BookPage Turning-Function?
Post by: Digital Mosaic Games on Sat 13/02/2010 12:49:52
It´s okay.
I´ve figured out my mistake.