Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / How do I anchor a sprite on its center when scaling and rotating.. SetSpriteOffset()?

Author
Message
Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 12th Jul 2017 22:06
I thought SetSpriteOffset() would do the trick but cannot get it to work. also experimented with SetSpriteScaleByOffset() but no joy.



Above should (or not) change the offset from the top left to the middle of the sprite but is always drawn at 0,0 world cords.

Ultimately what I want to achieve is to have a sprite that can scale and rotate on it's centre.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 12th Jul 2017 23:41 Edited at: 13th Jul 2017 01:14
I don't think the offset values should be negative. They should be positive. I know i've tried this and it works. See attached

Attachments

Login to view attachments
Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 13th Jul 2017 08:23
Thanks Blink, ill take a look at that when I get home, I did try all kinds of values but the sprite always stayed in the same position but your example should clear this up for me.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 13th Jul 2017 08:36 Edited at: 13th Jul 2017 08:37
I think you can use SetSpriteScaleByOffset()

EDIT: That should scale the sprite from its offset point, moving all 4 sides away from or closer to the center of its offset point.
13/0
Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 13th Jul 2017 09:26
Yes I think I need to use both in combination, though SetSpriteOffset() didn't seem to have any effect yesterday, but, today is a new day so time will tell.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 13th Jul 2017 16:52
also it's good to remember that height and width will take into account any hidden pixels, it's easy to forget when dealing with animated sprites especially as stuff like weapons can make the sprite bigger for a while but on normal viewing the sprite may appear smaller or offset.
life\'s one big game
spec= 2.6ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 15th Jul 2017 23:11
so after you run setspriteoffset(spr_turnip,w,h) would that change the call for setspriteposition or setspritepositionbyoffset?

Is spr_turnip going to be moving while scaling and rotating? If not maybe define the offset before you make changes



I am still a beginner, so I can't say this is the best solution (99% sure its not the easiest way to go) but its the way I would approach it. Hope it helps.

I'd like to see the finished code once you get it figured out!
Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 17th Jul 2017 22:54
Thanks for the post, yes I got it figured out in the end, set function with and without 'byoffset' is what was tripping me up.

Login to post a reply

Server time is: 2024-11-22 07:51:02
Your offset time is: 2024-11-22 07:51:02