Object up and donw in Main menu

Started by Arcangel, Fri 12/10/2018 17:14:14

Previous topic - Next topic

Arcangel

Code: ags
// room script file


function room_Load()
{

 if (mouse.Mode != eModePointer)

{
        // change cursor to Pointer for menu
   Mouse.UseModeGraphic(eModePointer);
} 
 
object[0].Visible = false;
object[1].Visible = false;
object[2].Visible = false;
}

function oObject0_AnyClick()
{
  Mouse.UseModeGraphic(eModeWalkto); 
  player.ChangeRoom(2);
}

function oObject1_AnyClick()
{
  gPanel.Visible = false;
  //show_restore_game_dialog();
  
  lstRestoreGamesList.FillSaveGameList();
  gRestoreGame.Visible=true;
  //btnRestoreGame_OnClick();
  //RestoreGameDialog();

}

function oObject2_AnyClick()
{
QuitGame(0);
}



function room_RepExec()
{


  
 if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hPlay){
      object[0].Visible = true;
   object[1].Visible = false;
 object[2].Visible = false;}
 //  Display("Mouse on the Play");
 else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hLoads){
      object[0].Visible = false;
   object[1].Visible = true;
 object[2].Visible = false;}
  // Display("Mouse is on Load)!");
 else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hQuit){
      object[0].Visible = false;
   object[1].Visible = false;
 object[2].Visible = true;}
//   Display("Mouse is on Quit");
else {
      object[0].Visible = false;
   object[1].Visible = false;
 object[2].Visible = false;}
 //   Display("Mouse is on nothing");
 
 if (mouse.Mode != eModePointer)
{
   mouse.UseModeGraphic(eModePointer);
}
 
  
}


function room_AfterFadeIn()
{
//SetMusicRepeat(1);
aMusic1.Play(eAudioPriorityNormal);
}


How I put a object that "bouncing" up and down slow only move in Y.
object[3].Move(635, y, 4, eNoBlock);

I know Im rusty in program lot of years no programs I need start little basic. :undecided:

Thx for any help

Monsieur OUXX

#1
So let me get this right :
- so far you have not implemented the bouncing at all
- the bouncing menu entry is an object that appears only when the mouse is over it (otherwise it's ... what? a static image irectly in the room's background?)


I would recommend to use the Tweens module. That's the simplest way to have a nice smooth bouncing without having to worry about variables.
Do you know how to import a  module?
Get it from the module's page : http://www.adventuregamestudio.co.uk/forums/index.php?topic=51820.msg636508546#msg636508546

...then use a simple instruction like :
Code: ags


//in the function:
 ...
 else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hQuit){
      object[0].Visible = false;
      object[1].Visible = false;
      object[2].Visible = true;}

      object[2].TweenY(2.0, object[2].Y - 10,  eEaseLinearTween, eReverseRepeatTween); //the important line


You might need to use this if the mouse is not over the object anymore :
Code: ags

object[2].StopTweenPosition();


Please note that I can never remember if it's considered a bad thing to call .TweenY at every game loop and if the module is clever enough to not pile up a new tweening action every time, or if you have to be careful about that yourself. Then you'd need something like (not actual syntax) : if(object[2].IsTweening) { /*start the tween*/}
 

Arcangel




Only the object[3] in this example "Rock" go up and down.

This is a example menu. NOT my menu but similar.

Menu have 3
object[0] Play
object[1] Settings/Load
object[2] Quit

Arcangel

Need help with code because when use the instruction that Monsieur OUXX giveme the menu put icon pause(CLOCK). Not look good in menu, need to be free mouse pass over Play, Restore, Quit, and the object to the right stay up and down slow like float. But when I put the mouse over any menu hotspot the animation of the object stop. Any help????

Khris

#4
Try this:

Code: ags
float angle;

function room_RepExec() {
  angle += 0.1; // change this number to change the speed
  if (angle > Maths.PI * 2.0) angle -= Maths.PI * 2.0;
  object[3].Y = 260 + FloatToInt(Maths.Sin(angle) * 100.0, eRoundNearest);
}


(if you don't have a room_RepExec() function yet, create it via the room's events section first so it is properly linked!)

Quick aside regarding your chosen resolution of 800x600: imho that's a really bad choice for two reasons:
1) it's 4:3, which means people will have fullscreen borders unless they still have a 15 year old monitor
2) I for instance can only play a game like that in windowed mode, given that scaling it up by 2 would result in a 1600x1200 format, which is taller than my screen resolution.

I'd go with a 16:9 res, and pick one that scales up nicely, like 960x540. This will play nicely in a window on a 1366x768 laptop, and people with Full HD monitors can scale it up by 2 to have borderless fullscreen. It's even compatible with 4k monitors that way.

Arcangel

Thx Khris work great

Code: ags
      
      angle += 0.09; // change this number to change the speed
      if (angle > Maths.Pi * 2.0) angle -= Maths.Pi * 2.0;
      object[3].Y = 460 + FloatToInt(Maths.Sin(angle) * 100.0, eRoundNearest);

SMF spam blocked by CleanTalk