useinventory animtion/sprite and camera moves [SOLVED]

Started by lafouine88, Fri 08/05/2020 18:56:29

Previous topic - Next topic

lafouine88

Hi guys

I'm a bit stuck on two (basic I guess) issues. Maybe you could help.

1) I know this question occurs often but so far I haven't found any accurate answer and it would suprise me if it weren't possible. I would like my "useinventory" cursor to change its sprite or to animate on hotspots, the way other cursors can. Is there a generic code that we can use somewhere? The idea is to make the interaction more visible. I suppose it would be a matter of changing the sprite to another one(say n+1) so you would have to create two icons for each item. But is there a way to make that work ?

2)second question is I think quite a classical too. But since many things have changed with 3.5, it's still hard for me to understand it. CAMERAS.
My game goes under the resolution 320*200. I'm glad with the way the camera follows the character.

But I want to make a little move of the camera in a cinematic cutscene. I would like the camera to move up for a short while, and then go down and back to normal. Just picture the character is in front of a skyscaper. The camera climbs to show how big it is and then you re back to the ground.
The "camera.setat" function does move the cam, but it does it automatically, in one frame. I would like it to really make the movement of climbing up.
Secondly, I guess I would have to make a background image of 320*600 (for instance). But then I would like it to NOT scroll up as the character moves, to stay to a 320*200 config. The top extension to 600 is just designed for the cinematic but then I dont want to be able to see it anymore. Do you see a solution for that ?

Thanks a lot in advance and sorry for my english. If I'm unclear I'll develop :)

Crimson Wizard

Regarding camera, basic things like room scrolling stayed about the same way as they were before 3.5.0, but use different functions.
The topic "Upgrading to AGS 3.5" explains general idea about cameras and viewports in 3.5.0: https://github.com/adventuregamestudio/ags-manual/wiki/UpgradeTo35#new-viewportcamera-system

Moving camera gradually is similar to moving any object gradually: you increase X or Y coordinate by a smaller number of pixels (like, 1) each time until it reaches the goal. First question here is whether this movement should be blocking or non blocking.

For blocking movement, it may be as simple as:
Code: ags

while (Game.Camera.Y > 0) {
    Game.Camera.Y -= 1;
    Wait(1);
}
Wait(60);
while (Game.Camera.Y < 400) {
    Game.Camera.Y += 1;
    Wait(1);
}


The "Wait(1)" call in the loop is necessary to let engine update and redraw the screen between the steps. You may adjust this value, and value that is added to camera coordinate to change movement speed.


Quote from: lafouine88 on Fri 08/05/2020 18:56:29
Secondly, I guess I would have to make a background image of 320*600 (for instance). But then I would like it to NOT scroll up as the character moves, to stay to a 320*200 config. The top extension to 600 is just designed for the cinematic but then I dont want to be able to see it anymore. Do you see a solution for that ?

You would have to disable standard player-following mode and control camera movement by yourself. For simple example, in room's rep-exec event, do:
Code: ags

    Game.Camera.X = player.x;
    Game.Camera.Y = player.y;
    if (Game.Camera.Y < 400)
        Game.Camera.Y = 400;



lafouine88

Hi crimson and thanks for your quick reply.

The camera moves nicely with your script. Perfect !
Though then there is still a problem with getting back to the normal cam. The x coordinate doesn't follow. But I guess that's a detail, I can find that myself :)

Many thanks again.

Crimson Wizard

Quote from: lafouine88 on Fri 08/05/2020 20:00:00
Though then there is still a problem with getting back to the normal cam. The x coordinate doesn't follow.

Oh right, you need to do "Camera.AutoTracking = true;" afterwards.
Whenever you change position manually AutoTracking is set to false.

lafouine88

QuoteOh right, you need to do "Camera.AutoTracking = true;" afterwards.

Yes, that puts the cam back to normal. But I think it's the second script that doesn't quite work. The camera doesn't follow my character, event when I turn off the event.

I just copied the code, changing the value in "repetedly execute" :

Code: ags
    Game.Camera.X = player.x;
    Game.Camera.Y = player.y;
    if (Game.Camera.Y < 200)
        Game.Camera.Y = 200;


but the camera stays stuck, in a place that isn' even centered on my character's initial position^^it goes a bit lower and to the right^^
I tried changing the code to :
Code: ags
    Game.Camera.X = 400;
    Game.Camera.Y = 165;
    if (Game.Camera.Y < 200)
        Game.Camera.Y = 200;

where 400,165 are the actual coordinates of my character, but it keeps the misplacement, the camera still goes down and right. It doesn't get centered on my character.
Like you said in a previous reply, whe are talking room coordinates with the camera, not screen coords ? Maybe that would be the reason ?

Cassiebsg

#5
For question 1 the short answer is yes. The annoying answer is: you have to code the behavior your self.

I did something like that for GUIs, so that my cursor also highlighted when over a button or label that could be clicked on, I'm guessing using it on inventory will be somewhat the same way. I'll go look at the code I used and be back in a short while.

Edit: Seems like my code did include inventory...

Code: ags

function HighlightCursorOnGUI() // Highlights the mouse when over GUI controls.
{
  GUI *aGui = GUI.GetAtScreenXY(mouse.x, mouse.y);
  if (aGui != null )
  {
    GUIControl *aControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    if (aControl!=null && mouse.Mode!=eModeUseinv && player.ActiveInventory==null)
    {
      mouse.Mode=eModeGuiCursor;
     }
    else if (mouse.Mode==eModeUseinv || player.ActiveInventory!=null) return;
    else (mouse.Mode==eModeGuiCursor) mouse.Mode=eModeWalkto; // Returns the mouse mode to normal.
  }
  else if ( mouse.Mode==eModeUseinv || player.ActiveInventory!=null) return;
  else (mouse.Mode==eModeGuiCursor) mouse.Mode=eModeWalkto; // Returns the mouse mode to normal.
}


Then place HighlightCursorOnGUI(); on repeatedly_execute or repeatedly_execute_always or  late_repeatedly_execute_always.

Also, you need to create a new Mouse Cursor. I suggest you call it GuiCursor, so it fits with my code. But feel free to call it anything else (just remember to change the name in the code as well). In this cursor mode you use the "highlighted cursor" sprite of your choice.

Edit 2: Also note that I'm returning the mouse to "walk mode", since that's the normal default in my game. If your's is somethhing else, change it appropriately. Or find the previous mode and restore it to it. Change the code so it fits your needs. ;)
There are those who believe that life here began out there...

Crimson Wizard

Quote from: lafouine88 on Fri 08/05/2020 20:30:04
but the camera stays stuck, in a place that isn' even centered on my character's initial position^^it goes a bit lower and to the right^^

Right, sorry, I forgot to center camera on player. Camera.X/Y are coordinates of its left-top corner, while player's x/y are coordinates of its bottom-center.

So you need to adjust above, like:
Code: ags

Game.Camera.X = player.x - Game.Camera.Width / 2;
Game.Camera.Y = player.y - Game.Camera.Height / 2 - VERTICAL_OFFSET;

where VERTICAL_OFFSET value depends on player's sprite height.

lafouine88

QuoteRight, sorry, I forgot to center camera on player. Camera.X/Y are coordinates of its left-top corner, while player's x/y are coordinates of its bottom-center.
Oh yeah that's why... Thanks a lot for this :)

QuoteAlso, you need to create a new Mouse Cursor. I suggest you call it GuiCursor, so it fits with my code. But feel free to call it anything else (just remember to change the name in the code as well). In this cursor mode you use the "highlighted cursor" sprite of your choice.
Hey cassiebsg and thanks for your help. I'll try to decypher and adapt your code tomorrow. But it seems yours changes the cursor to another one. Lets say cursor1 to cursor 2. My idea would be to change the cursor for every inventory item. Like in Sam and Max, there is the icon sprite, and when it's over a hotspot it sets to a second sprite (the same, but circled in red basically). I'll try again tomorrow(I'm newb) but I think I understand your code just points to the same icon everytime.

Do you know if it is possible for a hotspot to trigger a change of sprite when the mouse goes over it, something like "useinventory.sprite = n+1 ;" Where n would be the number of the sprite(defined before) and the n+1 sprite would be the one with the red dots.
By the way, I realise how ridiculous my fictional code is, it's just to give you the main idea^^

Thanks again

Khris

The cursor highlighting is mostly about tracking whether the cursor is above an interactive area or not:

Put this in the global script, above repeatedly_execute:
Code: ags
bool wasHovering = false;

function HandleCursorHighlight() {
  bool isHovering = GetLocationType(mouse.x, mouse.y) != eLocationNothing;

  if (isHovering && !wasHovering) {
    // cursor entered interactive area
    if (player.ActiveInventory) mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.Graphic + 1);    
  }
  else if (!isHovering && wasHovering) {
    // cursor left interactive area
    if (player.ActiveInventory) mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.Graphic);
  }

  wasHovering = isHovering;
}


Now add this line inside repeatedly_execute:
Code: ags
  HandleCursorHighlight();

lafouine88

This is perfect Khris ! Well done and many many thanks :) !

SMF spam blocked by CleanTalk