How to force or fake scaling from somewhere other than default origin

Started by FortressCaulfield, Tue 28/01/2025 23:29:05

Previous topic - Next topic

FortressCaulfield

I keep running into issues animating with tweens or moves when a character needs to scale and move at once, like a char riding a zipline into the distance or a ship flying up from a planet. Is there a way to change this or to fake it somehow with dynamic sprites, to make a char scale from top center or object from the top right, etc
"I can hear you! My ears do more than excrete toxic mucus, you know!"

-Hall of Heroes Docent, Accrual Twist of Fate

Crimson Wizard

In general case you can set their position with offset in script. For characters there's LockViewAligned and LockViewOffset functions. I don't remember what LockViewAligned is suitable for, but LockViewOffset probably is suitable for the described situation.

The offset is calculated by taking current frame/graphic size and multiplying by scale, for example:

Code: ags
int offset_x_align_left = (pic_width / 2) * mycharacter.Scaling / 100
int offset_x_align_right = -(pic_width / 2) * mycharacter.Scaling / 100

Getting current graphic size may be done by combining Game.GetViewFrame and Game.SpriteWidth/Height:

Code: ags
ViewFrame* vf = Game,GetViewFrame(mycharacter.View, mycharacter.Loop, mycharacter.Frame);
int frame_width = Game.SpriteWidth[vf.Graphic];
int frame_height = Game.SpriteHeight[vf.Graphic];

EDIT: I just remembered that since AGS 3.6.1 LockViewOffset is scaled automatically if you have a "Scale Character sprite offsets" option enabled in General Settings. So in that case you don't have to multiply by scale, and provide offset in unscaled units.

FortressCaulfield

I appreciate the answer as always, and the right align will do what I want in a few cases, but what I was really hoping for was being able to change the y align
"I can hear you! My ears do more than excrete toxic mucus, you know!"

-Hall of Heroes Docent, Accrual Twist of Fate

Snarky

Quote from: FortressCaulfield on Mon 10/02/2025 11:38:59what I was really hoping for was being able to change the y align

For Characters you can use Character.z for the Y-offset. The "Scale Character sprite offsets" CW mentions should make it work when you scale it.

For Objects, you have to calculate the scaled offset yourself. That having been done, making it work with Tweens is pretty easy: Instead of TweenPosition you would use a custom Tween for both the X and Y, and each loop you add the offset to the values and set the position to the results. (Though personally I think if you're already doing this manually it's usually easier to just do the movement calculation yourself rather than tweening it.)

Object.Move won't work, but you can pretty easily script your own Move function for moving in straight lines. For moving along walkable area paths I would use a Character rather than an Object.

SMF spam blocked by CleanTalk