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 / AGK2 Sprite Group Rotation

Author
Message
IronManhood
5
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 17th Mar 2015 05:06
So I've been working on a tiled map maker and for the most part I have been able to overcome the problems I've run into. However, I just can't figure out how to solve this one. Let me explain...

What I would like to do is have a selection of tiles rotate around the center point of the group. So each sprite would orbit around a point that would be calculated from each sprites position.

Any help is appreciated.
BatVink
Moderator
17
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Mar 2015 06:40
The simplest answer is to "cheat"

I would make the central sprite a Kinetic physics object, and then attach all of the other sprites to it with solid joints as dynamic physics objects. Set the masses to 0 and zero friction. When you rotate the central sprite, the rest will rotate with it.

Quidquid latine dictum sit, altum sonatur
IronManhood
5
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 17th Mar 2015 06:59
Well that's assuming there is a sprite in the center of the group, which there shouldn't be. Also, wouldn't it be simpler just to use math and setspriteposition?
BatVink
Moderator
17
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Mar 2015 09:13 Edited at: 17th Mar 2015 09:14
Create an invisible sprite at the centre.

You can always use maths, somebody will come along and show the calculations I'm sure. I just use whatever is most convenient at the time.

Quidquid latine dictum sit, altum sonatur
baxslash
Valued Member
Bronze Codemaster
13
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Mar 2015 09:38 Edited at: 17th Mar 2015 12:18
Quote: "somebody will come along and show the calculations I'm sure"

I happen to have a function for this, just enter the sprite ID, the point to rotate about and the angle to rotate by:


Using AppGameKit V2 Tier 1
IronManhood
5
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 17th Mar 2015 10:43
A point I forgot to mention, all of the tiles, or sprites, are saved in an array. So I will be iterating through that array.

Quote: "I happen to have a function for this"


I suppose if that function was used with a loop it could work. Although, it's funny how I had that same code and it didn't quite work for my application. But to clarify I'm interested in learning the math for future use. I'll give another try at using your function and see if I was doing something wrong.
baxslash
Valued Member
Bronze Codemaster
13
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th Mar 2015 12:17 Edited at: 17th Mar 2015 12:19
I edited that function incorrectly to simplify it. There were errors that I've corrected...

I call this function in my 2D animation code for an array of sprites. Yes, just iterate through the array and put each sprite ID into the function.

Using AppGameKit V2 Tier 1
CJB
Valued Member
16
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 17th Mar 2015 14:18
Excellent little function baxslash! I can see this being used in conjunction with setviewoffset and setviewzoom for some really cool top-down shooters.

V2 T1 (Mostly)
Uzmadesign
IronManhood
5
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 17th Mar 2015 21:49
Wow! That was somewhat simple. It works. Thanks for the help guys.
baxslash
Valued Member
Bronze Codemaster
13
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Mar 2015 08:39
Always glad to help

Using AppGameKit V2 Tier 1
BatVink
Moderator
17
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Mar 2015 17:29
Nice code snippet, taken for future use, thanks!

Quidquid latine dictum sit, altum sonatur
Conjured Entertainment
AGK Developer
15
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 20th Mar 2015 14:38
Top notch work as usual Baxslash.
Thanks for sharing this great example!

Quote: "Wow! That was somewhat simple. It works."

He only made it look simple with such a nice breakdown of the formula.


Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
baxslash
Valued Member
Bronze Codemaster
13
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 20th Mar 2015 17:06
Actually like much of my work I am like a bumble-bee bouncing against a window for a while until I stumble on the opening... I tend to do a lot of experimentation to make something like this work. I do use trig a lot in my daily life too developing plugins for CAD software

Using AppGameKit V2 Tier 1
IronManhood
5
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 20th Mar 2015 21:21
Another random question, would there be info on how to use the forum?
IronManhood
5
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 20th Mar 2015 23:35 Edited at: 12th Apr 2015 20:41
Nevermind, I found the Website board nestled under "DarkBasic Products".

Login to post a reply

Server time is: 2020-09-24 23:05:48
Your offset time is: 2020-09-24 23:05:48