There is a new version of the forums ready for testing. Please post here if you're willing to help test! We could also use the help of coders!

Author Topic: Changing Main Character Sprite from Room to Room  (Read 526 times)

Hello again!

So I tried to put it in the title as much as possible, but I’ll iterate on it here too…
 
Basically, in my game – dependent on the area the character occupies at a certain time – the position of the sun will be different, meaning shadows will be cast at different angles.  Sometimes it will be to the right, others to the left, and so on.
 
My thought was to just create multiple versions of the main character, baking in the correct shadow angle so that it “casts” correctly.  But that brings the question – is it possible to switch the player-character’s sprite at a certain time?  Going from one series of rooms to the next?  AND ensuring one’s inventory stays the same? For example, the  first 10 would be a shadow cast left, but then a different angle the next, and so on.

Hopefully that’s clear… thank you!!
“Art is an object riddled with sharp edges that can cut you.  You can pound all those edges away and make it smooth and make it safe, but what you’re left with is just a shapeless blob.  It’s safe and it’s smooth, but it’s uninteresting.” Ron Gilbert

Re: Changing Main Character Sprite from Room to Room
« Reply #1 on: 04 May 2022, 20:05 »
For changing the character looks (any character) you may use Character.ChangeView. That assumes that the sprites are prepared beforehand and arranged into several Views. For example, you may have one View per shadow type (angle).

In regards to general question of creating character's looks by combining several elements, there has been a short discussion on this recently:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=59912.0
« Last Edit: 04 May 2022, 20:14 by Crimson Wizard »

Re: Changing Main Character Sprite from Room to Room
« Reply #2 on: 04 May 2022, 21:55 »
For changing the character looks (any character) you may use Character.ChangeView. That assumes that the sprites are prepared beforehand and arranged into several Views. For example, you may have one View per shadow type (angle).

In regards to general question of creating character's looks by combining several elements, there has been a short discussion on this recently:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=59912.0

You’re awesome! Thank you so much!
“Art is an object riddled with sharp edges that can cut you.  You can pound all those edges away and make it smooth and make it safe, but what you’re left with is just a shapeless blob.  It’s safe and it’s smooth, but it’s uninteresting.” Ron Gilbert

Re: Changing Main Character Sprite from Room to Room
« Reply #3 on: 05 May 2022, 08:36 »
Like Crimson said, you can easily change a character's normal view using ChangeView(), and you would do so in room_Load.

As for the shadows, I'd create a 2nd charater just for the shadow and use FollowCharacter to combine it with the player character. The command has specific functionality to accomplish exactly that.

(It might also be a good idea to peruse the Scripting API in the manual once, to get a general idea of the available commands ;))

Re: Changing Main Character Sprite from Room to Room
« Reply #4 on: 05 May 2022, 11:28 »
(It might also be a good idea to peruse the Scripting API in the manual once, to get a general idea of the available commands ;))

Yes that's true, I recommend everyone learning AGS to just open a list of script commands in each category and quickly scan through it to know what it can do. Then you may have an idea what to look for when you need something.

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: Changing Main Character Sprite from Room to Room
« Reply #5 on: 05 May 2022, 11:28 »
I've never used .FollowCharacter() with FOLLOW_EXACTLY, and I'm curious: how does AGS determine which character will be drawn on top? In this case you wouldn't want the shadow to cover the character's legs, probably.

Re: Changing Main Character Sprite from Room to Room
« Reply #6 on: 05 May 2022, 12:56 »
I've never used .FollowCharacter() with FOLLOW_EXACTLY, and I'm curious: how does AGS determine which character will be drawn on top?

It's not defined by FollowCharacter, the sorting rules in AGS are always the same: they are sorted by baseline, and if baselines are equal then it's "undefined" (results depend on random factor).

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: Changing Main Character Sprite from Room to Room
« Reply #7 on: 05 May 2022, 14:01 »
Random behavior does not seem very satisfactory for this purpose.

Re: Changing Main Character Sprite from Room to Room
« Reply #8 on: 05 May 2022, 14:46 »
This is why for best results such things should be adjusted in the script. The FollowCharacter alone may not be perfect, as it aligns by character's origin (middle-bottom point). That already may not be suitable for shadows, which may have to be positioned lower, or centered around character's feet. Personally I would not use FollowCharacter at all, but fine tune this by positioning characters in script (in repeatedly_execute and alike).

If you prefer FollowCharacter, then shadow may have to be shifted using character.z (which is a visual-only vertical offset), but its baseline likely have to be repeatedly set to main character's baseline + YOffset.
« Last Edit: 05 May 2022, 14:48 by Crimson Wizard »

Matti

Re: Changing Main Character Sprite from Room to Room
« Reply #9 on: 05 May 2022, 14:47 »
The manual says this:

"If you use FOLLOW_EXACTLY, then EAGERNESS has another meaning. If you pass 0, CHARID will be drawn in front of CHARTOFOLLOW; if you pass 1, it will be drawn behind"

So it seems there IS a parameter that takes care of the drawing order.
« Last Edit: 05 May 2022, 14:50 by Matti »

Re: Changing Main Character Sprite from Room to Room
« Reply #10 on: 05 May 2022, 14:53 »
"If you use FOLLOW_EXACTLY, then EAGERNESS has another meaning. If you pass 0, CHARID will be drawn in front of CHARTOFOLLOW; if you pass 1, it will be drawn behind"

So it seems there IS a parameter that takes care of the drawing order.

Ah. Well, I did not remember this. It does make sense now.

From the look of the engine code, this flag will automatically set baseline to main character's baseline + 1 or -1. In the end it's all about baselines, but FollowCharacter may do these things automatically.

EDIT: to think more about this, the "shadow"'s offset may also be achieved using LockViewOffset. So combining FollowCharacter with FOLLOW_EXACTLY and LockViewOffset to position second character's sprite in certain way may result in a good behavior.
« Last Edit: 05 May 2022, 14:58 by Crimson Wizard »

Re: Changing Main Character Sprite from Room to Room
« Reply #11 on: 05 May 2022, 19:48 »
Exactly, I wanted to keep things simple and FollowCharacter() supports everything required to do this out of the box.

Anyway, there might be better solutions to this depending on the graphics style and perspective and so on. The shadow character will cover other characters and objects if standing close but further down, and in a lowres game you can usually get away with drawing a roughly elliptical black blob. The advantage of this is that you don't have to create tons of sprites.
If I were to implement this myself I'd probably draw a (possibly dynamically resized) shadow sprite to the room background, using the character's position and time of day to calculate its position.