Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Help With Menu Transitions

Author
Message
Game Warden
14
Years of Service
User Offline
Joined: 12th May 2010
Location: Union, MO
Posted: 22nd Mar 2012 16:27 Edited at: 22nd Mar 2012 16:34
I was hoping someone here would be able to help me figure out some simple menu transitions. I'm wanting to move a button off the screen slowly when it is clicked. Right now I can only move the button instantly without the effects of animation. I think I'm in the right direction in using a for loop to go about accomplishing this task.

This is how my main menu is set up and I'm wanting to simply move the buttons along the x axis off the screen.

<---------------------[New Game]
<------------------[Load Game]
<---------------[Options]
<------------[Exit]

Thank you for your time and help

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 22nd Mar 2012 16:42 Edited at: 22nd Mar 2012 16:54
One method is moving the sprite indirectly.

When you set up the variables to look after the button, set up a "current" value which is used to position the sprite and a "target" value which is used to set the intended position.

I would suggest a UDT for the button something like


Then each loop, call a function to check if the current value is the same as the target and if not, adjust the current value and move the sprite.



Now if you want to move the button, you put the location you want to move it to into the target fields of the global variable and the button will move (in the example at a rate of 1 pixel per frame).

This is a very, very basic outline but should give you an idea.

It can be enhanced by giving the button a movement speed or perhaps a time.

Often I will also use a field to indicate the positions are the same (by adding an else to the function), which can be checked by the main program to see if the button has arrived.

edit: typo's and spacing
Game Warden
14
Years of Service
User Offline
Joined: 12th May 2010
Location: Union, MO
Posted: 22nd Mar 2012 17:16 Edited at: 22nd Mar 2012 17:21
So in the UDT would I also need a state field and check to see if the button is pressed in the main loop? If the button gets pressed then I would be able to change the state to 1 and then execute the function. Would something like that work?



Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 22nd Mar 2012 17:30
Yes.

The state field would reduce the number of comparisons per loop, and the function could then reset the state once the button has arrived.

This would prevent the function being called when not needed.

In effect it would switch itself off.

The main program can then check the state field to determine if the transition is complete.
Game Warden
14
Years of Service
User Offline
Joined: 12th May 2010
Location: Union, MO
Posted: 22nd Mar 2012 17:31
Awesome just tried it out and it does work how I intended. Thank you for your help

Login to post a reply

Server time is: 2024-11-23 05:09:23
Your offset time is: 2024-11-23 05:09:23