[Solved] Changing SpriteOffset of projectile at spawn

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
peewee_RotA
Posts: 407
Joined: Fri Feb 07, 2014 6:45 am

[Solved] Changing SpriteOffset of projectile at spawn

Post by peewee_RotA »

How do you change a sprite offset in decorate default properties?

You probably can't. GZDoom source code doesn't have a decorate property exposed from the source. But A_SpriteOffset IS available. So you can call this in your frames.

The problem is that it is difficult to run this action before State frame #1 renders. But it is really easy to run this action in one of the provided virtual functions that happen before the first frame ever renders.

In this case, I'm reusing an actor sprite from Hexen that I don't want to copy and manually redo all of the offsets. The actual change happens in PostBeginPlay(). I'm using a pretty extreme 50, but you could work this however you want.

Code: Select all

class MageWandSunMissile : Actor
{
    Default
    {
        Speed 10;
        Radius 12;
        Height 8;
        Damage 10;
        Projectile;
        +CANNOTPUSH +NODAMAGETHRUST
        +SPAWNSOUNDSOURCE
        Obituary "$OB_MPMWEAPWAND";
        Scale 2.0;
        DamageType "Fire";
        SeeSound "TreeExplode";
    }
    States
    {
    Spawn:
        FDMB B 4 Bright Light("YellowSunSmall");
        Loop;
    Death:
        FDMB B 6 Bright Light("YellowSunBig") A_SunExplode;
        FDMB C 3 Bright Light("YellowSunBigFade1");
        FDMB C 3 Bright Light("YellowSunBigFade2");
        FDMB D 3 Bright Light("YellowSunBigFade3");
        FDMB D 3 Bright Light("YellowSunBigFade4");
        FDMB E 3 Bright Light("YellowSunBigFade5");
        Stop;
    }
    
    override void PostBeginPlay()
    {
        A_SpriteOffset(0, 50);
    }

    action void A_SunExplode()
    {
        A_Explode(65, 150);
        A_StartSound("Fireball", CHAN_BODY);
    }
}
Last edited by peewee_RotA on Sun May 19, 2024 4:25 pm, edited 1 time in total.
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1119
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)
Contact:

Re: Changing SpriteOffset of projectile at spawn

Post by Jekyll Grim Payne »

Why not modify the offset in the actor's PostBeginPlay?

Edit: sorry, you're already doing it. No, there isn't a property for this, but you can make one. But ultimately it'll still have to be run in PostBeginPlay.

You could also try BeginPlay, I believe it should work.
peewee_RotA
Posts: 407
Joined: Fri Feb 07, 2014 6:45 am

Re: Changing SpriteOffset of projectile at spawn

Post by peewee_RotA »

Thanks for the reply. I added a utility class for it so I could use it easier in other places. Now these projectiles just inherit from here.

Code: Select all

class OffsetSpriteActor : Actor
{
	double offsetSpriteX;
	double offsetSpriteY;
	property OffsetSpriteX : offsetSpriteX;
	property OffsetSpriteY : offsetSpriteY;
    
    override void PostBeginPlay()
    {
		if (offsetSpriteX != 0 || offsetSpriteY != 0)
			A_SpriteOffset(offsetSpriteX, offsetSpriteY);
    }
}
Post Reply

Return to “Scripting”