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 Studio Chat / [request] Parenting sprites

Author
Message
EricFrederick
User Offline
Joined: 20th Aug 2021
Location:
Posted: 20th Aug 2021 09:38
may use the wrong term here. The idea is, it would be nice if we could group sprites in a hierarchy one being the "parent" and others can be the childs. The idea is that when we move, rotate or scale a parent, childs follow and keep relative rotation, position and angle to the parent. Different engines call this different ways. Some call it "parent", some call it "pining" other call it "grouping". I prefer to call it "parent-child" because it is describe perfectly the relation.

We could have a property for sprites called "parent" where we could enter the name of the sprite object that is being considered the parent and so once we update the position, rotation of that parent sprite it is going to also effect the childs. Or the other way is to have a property called "childs" where we could enter the name of sprites to be considered a child. Essentially, it would store the ID of the parent and all child sprites inside an array similar to groups, but in this case, the code would move, rotate only the parent in global space (the first element of the array maybe) and the rest 1 to Array.Length being moved and rotated in local space relative to the parent. So for example if I have a child on the right side of the parent, it is remain on the right side of the parent at all times.
PartTimeCoder
AGK Tool Maker
6
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 20th Aug 2021 15:03
https://forum.thegamecreators.com/thread/227752

I added this to the AppGameKit core but TGC don't seem interested in merging my pull request

https://github.com/TheGameCreators/AGKTier2/pull/18
Open Source plugins
Cl - DnD Plugin
hendron
5
Years of Service
Recently Online
Joined: 20th Dec 2015
Location:
Posted: 21st Aug 2021 00:41
Here's an include I put together for a project. It's a node "tree" system that sprites can optionally be attached to. It's not well-tested though, and there are problems with using different x and y scales. It could also be made more efficient, but it's a start. Feel free to use it/modify it.

Demo code:


Include code:

Login to post a reply

Server time is: 2021-10-21 02:53:07
Your offset time is: 2021-10-21 02:53:07