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.

AppGameKit Classic Chat / T2: SetSpriteOffset

Author
Message
Greg_C
13
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 8th Mar 2012 20:05
I want to position my sprites by using the center of the sprite (width*.5,height*.5). When I do this it offsets the center of the rotation. Can I not offset my sprites by position and keep the rotation in the center? I mean I could just call the function again after creation but I feel we should be able to pick if the rotation is affected when changing the offset.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Mar 2012 20:24 Edited at: 8th Mar 2012 20:26
You need to position using setSpritePositionByOffset()

I might have misunderstood. Using byOffset or not defines how the sprite is positioned...

Greg_C
13
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 8th Mar 2012 21:10
Yeah I am doing that.

Problem is, if you don't set an offset and do SetSpriteByOffset it would just position the sprite base off the top left corner right? I want to position my sprite based off the center so I set the offset to the center.this works fine but because the rotation of an object is based off the center when the offset is at 0,0 (the top left) when I do an offset it screws up my rotation. Again I could just reset it after I position the sprite just wondering if anyone has had this problem?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Mar 2012 22:11 Edited at: 8th Mar 2012 22:13
I see, so you want to rotate the sprite around 0,0 on the sprite but position it by the centre?

Let me just add you to my awkward list... OK that's done

You could use my sprite to world functions to find out how far away it is from the position you want it to be then reposition...


I haven't tried this though so it might not work quite how you want...

Any chance you can post some example code?

Greg_C
13
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 8th Mar 2012 23:56
Glad I could make the awkward list ...I think....

It's not to big of deal and I don't have to spawn my objects at their center point. It was really just a preference thing for me but I think being able to set the rotation position would be a nice little feature for agk in the future without having to offset the position as well.

Anyway thanks for you time.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Mar 2012 05:55
Greg_C, one possible solution would be to just offset them manually. Basically, just create an offsetx and offsety in your class/struct and then subtract those values from the normal x,y positions respectively. This also leaves the center of rotation untouched.

Quote: "Glad I could make the awkward list ...I think...."

The trick is to get on there multiple times like I have.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Mar 2012 09:35 Edited at: 9th Mar 2012 10:03
...or make your images twice the size, put your actual image in the bottom right hand corner and offset to the middle... not very memory conscious though

EDIT: Just saw your comment Hodgey, yes you are in the top three of my awkward list

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 9th Mar 2012 17:46 Edited at: 9th Mar 2012 17:47
Quote: "Problem is, if you don't set an offset and do SetSpriteByOffset it would just position the sprite base off the top left corner right?"


By default the offset of a sprite is in its center, so using SetSpritePositionByOffset will use the center point without you having to change anything.
Greg_C
13
Years of Service
User Offline
Joined: 22nd May 2010
Location:
Posted: 10th Mar 2012 18:15
@Paul
Ah okay, that makes my life so much easier. I don't know why I didn't really even think to just test SetSpriteOffSet without setting the offset. That's why you never assume

Thanks for all the help guys.

Login to post a reply

Server time is: 2024-05-07 13:14:36
Your offset time is: 2024-05-07 13:14:36