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 / Changing sprite offset to coordinates in the world

Author
Message
wasol
3
Years of Service
User Offline
Joined: 4th May 2016
Location:
Posted: 22nd Feb 2019 15:18
Hi all
I'm trying to change the offset of a sprite to make it rotate around a position in the world. To make it simple, I'm starting with the center of the screen as the position



My code works by getting the distance between the sprite's starting offset, and the center of the screen, then adds both in order to make the new sprite offset be at the center of the screen.

However, as soon as I try this on a rotated sprite, it stops working... because substracting the coordinates in the sprite from the coordinates in the world doesn't work if the sprite is not parallel to the world

I wonder if there's a simple geometry thing here that I'm not getting.. I'd be thankful for any help
blink0k
AGK Developer
Gold Codemaster
6
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Feb 2019 21:30
have you tried
SetSpriteOffset(sprite,GetSpriteXFromWorld(sprite, centreX, centreY),GetSpriteYFromWorld(sprite, centreX, centreY))
Without the getspriteoffset()
wasol
3
Years of Service
User Offline
Joined: 4th May 2016
Location:
Posted: 12th Mar 2019 10:34
Hi, thanks for your input
I tried it but the sprite seems to now be rotating around some point in the upper left of the game world (in case it matters, this is a sprite that I both resize and rotate some steps before trying to change the offset)
Bengismo
1
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 12th Mar 2019 17:23 Edited at: 12th Mar 2019 17:24
This code works....if you new rotation point is x,y



I think the only thing you were missing was setting the sprites new position to be the new rotation point.

A Full example....


The example allows you to set any point on the screen for the sprite to rotate about by clicking the mouse over and over.

Login to post a reply

Server time is: 2019-07-19 08:49:28
Your offset time is: 2019-07-19 08:49:28