Changing Main Character Sprite from Room to Room

Started by EnnarGames, Wed 04/05/2022 20:02:44

Previous topic - Next topic

EnnarGames

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

Crimson Wizard

#1
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

EnnarGames

Quote from: Crimson Wizard on Wed 04/05/2022 20:05:11
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

Khris

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 ;))

Crimson Wizard

Quote from: Khris on Thu 05/05/2022 08:36:18
(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

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.

Crimson Wizard

Quote from: Snarky on Thu 05/05/2022 11:28:58
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

Random behavior does not seem very satisfactory for this purpose.

Crimson Wizard

#8
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.

Matti

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.

Crimson Wizard

#10
Quote from: Matti on Thu 05/05/2022 14:47:37
"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.

Khris

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.

SMF spam blocked by CleanTalk