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 / i Think There Should Be a FixSpriteToSprite Command in the API.

Author
Message
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 17th Aug 2018 17:47 Edited at: 28th Aug 2018 01:49
UPDATE: For anyone who comes here looking for a solution (or starting point for their own solution) I implemented a FixSpriteToSprite command and system in Tier 1 down below.


So... last night I spent my dev time just testing some of AGK's api... the functionality I never mess with. I played around with SpriteTweens for movement and also tested the built-in sprite animation system.

Both of these are very slick very easy to work with.

However, I wondered how complex sprite-based objects would work with tweens. In my current game project I will quite likely have the enemies be compound objects meaning they will consist of multiple sprites.

At the simplest think of a tank where the body and treads are one sprite and the turret on top is a second sprite. I remembered in my 3D work there was a FixObjectToObject command so I thought "this AppGameKit really is amazing... they have thought of everything I need!" typed in FixSpriteToSprite... hmm... doesn't seem to be a recognized command. Went to the documentation and searched... GAsP! There ISN'T a FixSpriteToSprite command. There are physics based joints but that is another thing entirely... I am talking here about a 2D sprite equivalent of the 3D FixObjectToObject command.

I solved this in my experiment by simply positioning the second sprite based on the current position of the first sprite in my update. So the tween moves the first and then my code gets that position and uses it to position the second sprite. It works fine but clearly this will be a mess with many sprites.

This should be as simple with sprites as it is with 3D objects. This is one of the main reasons I generally make everything myself instead of using built-in features (in any game engine / library)... there is always something missing!

Can we please have a FixSpriteToSprite command? With that things will get very interesting!
Icerion
6
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 17th Aug 2018 17:52
I second that!
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 17th Aug 2018 18:08 Edited at: 17th Aug 2018 18:11
I realize of course we can program it... like I said that is generally what I do for everything and is how I solved it last night with a type for TSpriteObjectPart and each object having an array of those types with .x and .y offsets defined... but here I am looking at trying to take advantage of the AppGameKit native features and feel this is a big hole in the functionality.

It's something people would expect to be included for sprites if for no other reason than it already being included for 3D objects (and another big reason being most of the competition provide it one way or another).
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 17th Aug 2018 18:50
Id also agree that the FixSpritetosprite would be good and id like to see it too

If you loaded your object as a skeleton, it does do this for you. So you can just set your turret direction on your tank but the turrent moves with the tank. The entire thing then has bones that you can manipulate. You can even animate the bones too.

FixSprite to sprite would be good ...or more skeleton commands so we can create bones programtically and do this via FixSpriteToSkeleton2D which is a command.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Aug 2018 23:17
I think you can do it with physics and a joint. Might be interesting to experiment with that
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Aug 2018 23:30
I posted a snippet in response to someone a few weeks ago showing how to fix a sprite to another. I'd have to go look for the thread, but it's not very difficult.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 17th Aug 2018 23:48
Yeah I mentioned the physics system joints in the opening post. That is something different. FixSpriteToSprite here would work the same way as FixObjectToObject does.
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 18th Aug 2018 02:18 Edited at: 18th Aug 2018 02:23
Phaelax meant this thread i think
https://forum.thegamecreators.com/thread/222633

I posted this function (renamed) in that thread which is just 2 lines in it...


This works ok. It needs calling every time the parent sprite moves or rotates though

Like Garbenjamin said above, its possible to code this (using a function like above) but it doesnt automatically update when the parent moves or rotates so it needs to be called every frame.

Using a skeleton it would automatically update when the parent sprite moves at least but means using spriter/spine to make the compound (multisprite) object outside of agk first.
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 18th Aug 2018 07:57 Edited at: 18th Aug 2018 08:03
I have a bunch of fix to sprite functions created. Won't share them as we all know how to do it but I have a bunch of them because I sometimes want to pin a sprite to the top left, bottom centre, and centre right etc. so the new fix to sprite function would need extra parameters to position the two sprites in different ways, and not just centred.

I also have the same number of function for pin text to sprite. Handy for things like buttons with text so lets not forget the fix text to sprite function (with extra parameters to fix the text anywhere on the sprite)
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 18th Aug 2018 12:51 Edited at: 18th Aug 2018 12:53
I want to try it too

FixSpriteToSprite Demo:

You can fix them to the corner by setting the offset
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 18th Aug 2018 18:19 Edited at: 18th Aug 2018 18:31
That's pretty close but still not exactly the same functionality or usage.

Ha ha ha!! Not sure how this turned into coding examples but I guess that is what happens when you get a bunch of programmers involved.

Again the key point here is NOT to code up a solution in AGK BASIC but to have this implemented inside the API itself running at the native C/C++ speed automatically taken care of for us just like the FixObjectToObject command and system is. That is the critical bit. No thought. Max performance.

But it was cool to see different takes on it.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 18th Aug 2018 18:34
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 18th Aug 2018 18:44 Edited at: 18th Aug 2018 19:38
LOL! Sure and I could use Unity, Defold (not that I would because I don't like these dev kits that are centered around a GUI editor but this is what the majority of Indies will think... these days there are so many options if something doesn't have what they want they click on to the next) or one of the many others that already have it done too. Or just use 3D planes for 2D games. But that's besides the point! ha ha ha!

Anyway it was just a suggestion from me taking a closer look at what the api offers so I can make more use of it instead of writing everything myself and this stood out as something that should be included but isn't.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 18th Aug 2018 20:30 Edited at: 18th Aug 2018 20:49
You find that quite often in AppGameKit where you get a feature for 3D objects but not for sprites and the other way around or you have object,sprite and fullscreen shaders but no text shaders hint hint !
Not sure how I only upload selected code to github without the other changes I made
I used tortoise svn before...
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 18th Aug 2018 23:55
I've always been hoping for simple hierarchical commands like this. Took them for granted in other engines I guess. A simple parent-child relationship where we could call: SetSpriteParent(childSprId, parentSprId) and then any alterations to the parent sprite would be applied consistently to all descendants. So you could create a "UI" parent node, for instance, and then create all of the UI elements as children of that and then apply scaling/tweening/repositioning of the parent and every child will reflect as you'd expect as one singular group.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 19th Aug 2018 00:35 Edited at: 19th Aug 2018 04:01
That would be cool. Ultimately, I realize (and I think we all do!) not everything will be implemented into any engine / framework but common things... like what I would consider boiler plate type of stuff that is just needed purely from a technical perspective... foundational items... these kinds of things should be included right in the api and backend system. Especially when the same kind of fix object to object functionality already exists for the 3D side.

For what it's worth and in case it is helpful to anybody here is the system and demo I made when I went down the rabbit hole the other day investigating this.

I didn't test all scenarios only an initial test of a single centered turret and then a test of 3 turrets which is what the code and animated gif below illustrate.
It should work for anything but again no guarantees.

This FixSpriteToSprite method works like the native FixObjectToObject method signature in that you only pass in the spriteID that you want to attach and the ID of the sprite you want to attach it to.
The method sorts out how to do that based on the current positioning and angles of the sprites passed in.

Note that for a complete system we'd need to add in a RemoveFixedSprite(spriteID) method which removes that one from the list. Easy enough to do though.

There is a lot of set up code but that doesn't have much at all to do with my FixedSprite system and is just for the demo. Which also illustrates defining waypoints and having an enemy travel across it.

But still this kind of stuff should be built-in and then I could have spent more time working on my actual game instead of playing around with this! LOL!




EDIT: I did some more testing with placement of the turrets and updated the FixSpriteToSprite function accordingly...
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 19th Aug 2018 03:57 Edited at: 19th Aug 2018 04:45
Alright I took a break from watching playthroughs of Ludum Dare game jam videos to test this again with the turrets at different positions and their offsets on the ends instead of the centers.
So my lazy solution failed and i needed to update my FixSpriteToSprite function... I did update that one function in the code posted earlier and below is the code for the new demo.

Anyway, next time I do some game dev it is back to work on the actual game. I will just use this for now and hope that in one of the future updates this kind of functionality is added to the API and 2DUpdate.

Now back to watching LD videos. It is incredible the games people are making these days in a single weekend! If you haven't seen them I recommend checking out some of the videos on YT for LD42 and previous ones.



Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 19th Aug 2018 13:07 Edited at: 19th Aug 2018 13:11
I mentioned it above but this is exactly what the built in skeleton2d system is for. It does the fixing of sprites for you, it handles the parent child relationships and bones in a 2d model for you. It automatically updates positions and rotations etc... It EVEN loads the graphics for you and attaches them to bones in the model!

If you want to fix an additional sprite during your program...you have FixSpriteToSkeleton2D()

It also means you can hide the whole object (all the sprites and its children etc) with one command. Plus...you can animate your whole collection of sprites too.

It means that it takes a really minimal amount of code to do exactly what you are doing above and it also allows for turrets attached to other turrents (children of children etc...)

Take a look at the attached project. Its just one tank with a turret but the code for it is so simple. The entire code is juts this:


Skeletons arent perfect as we could do with a few commands adding (AddBone(), GetBoneSprite() etc...) , but they are pretty good

Attachments

Login to view attachments
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 19th Aug 2018 14:36 Edited at: 19th Aug 2018 14:37
Hey thanks Bengismo I will check it out when I get home later today.

I still think a straightforward FixSpriteToSprite would be great just so both 2D and 3D have it.

Anyway yeah I agree if we could add bones and such programmatically that would be very powerful. I looked into using that system the other day when investigating this but couldn't get anything to work. I didn't see how to actually make a skeleton I used that command CreateSkeleton I think it was but when trying to use the system it needed a bone name for reference and had no clue what the name was. Tried root, base, core, bone etc nothing worked.

I think I bought Spriter years ago but didn't care much for it so never used it for any project. That kind of thing I think is better suited for people who are focusing on impressive animation than it is for quickly getting results. At least that is the impression my initial look left on me. Maybe I will revisit it.

Anyway thanks I will definitely check out your example as soon as I get home!
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 19th Aug 2018 16:13 Edited at: 19th Aug 2018 16:20
Checked out the tank demo. That is very slick.

I guess I am just an oddball because I don't like things like this. I feel it is taking something that should be simple and making it more complicated than it is.
I mean using this means a person can get rid of the code implementing this kind of thing...


BUT... it also requires learning an entire new software and process just to have a simple rectangle with one or more other rectangles attached to it.
Also it looks like people are always using individual images for this and never using sprite sheets / atlases. So I guess for most games using such a thing every part of a character or other object is an additional draw call? I did read something about it having atlas creation support added along with a note that not all 3rd party systems will have implemented it.

I do think if a person is making a game with characters etc and wants to really focus on the animation quality things like this are very useful. Like a 2D fighting game using something like this would be very good I think. One could focus on making very detailed and complex animations for attacks, blocks and even illustrating taking hits to specific parts of the body.

I suppose I might try it some day. I'm just saying it seems like way overkill for something as simple as wanting to make a tank with a separate turret or a spaceship boss enemy that has a dozen turrets and engines on it that can be destroyed individually.

I think that is it basically. It is just a different use case. For me a simple FixSpriteToSprite system is all I need because I don't get into all of that fancy animation stuff. LOL!

Definitely appreciate you sharing it. It does reduce the code a good amount and that is one fantastic looking tank too.
Xaby
FPSC Reloaded TGC Backer
17
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 19th Aug 2018 16:37
@Bengismo

A lot of the Skeleton commands from Spriter or Spine are missing in AGK.

Like
https://docs.yoyogames.com/source/dadiospice/002_reference/game%20assets/sprites/skeletal%20animations/skeleton_attachment_set.html
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 19th Aug 2018 16:42
i agree it would be nice to get more simple commands in the 2D code bank but if you use physics joints you get all the fun of the 2D physics too... and it's only 1 line of code to create the joint (outside of the main loop even) and sync() automatically deals with the rest
this video uses weld joints to attach the pins to the ball if they hit and a rope joint to attach the ball to its starting location (technically a hidden sprite that is there) - well worth learning to use the inbuilt physics even if just for fun
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 19th Aug 2018 17:45 Edited at: 19th Aug 2018 18:11
Yeah, no problem. I just thought people were overlooking a very easy way of doing the whole fixing and relative locations of sprites. Personally, i find it much faster than writing code to tie together complicated sets of images for one object in the game. Id much rather create a boss with 12 turrets using spine or spriter then simply load it rather than try to code all the locations of turrets and rotations etc..

garbenjamin wrote: "it also requires learning an entire new software and process just to have a simple rectangle with one or more other rectangles attached to it."

It literally took less than a minute to put the turret on the tank...much much quicker than it does to actually code the turret to be attached to the tank. Plus you dont have to worry about hardcoding offsets or centres of rotation etc..

Garbenjamin wrote: "Also it looks like people are always using individual images for this and never using sprite sheets / atlases. So I guess for most games using such a thing every part of a character or other object is an additional draw call? I did read something about it having atlas creation support added along with a note that not all 3rd party systems will have implemented it."


Spriter does support texture atlases and actually has good support for it. It will even make a sprite sheets for you if you wanted it to.
https://brashmonkey.com/question/texturepacker-support-in-spriter-pro/

Plus dont forget that you can attach sprites to a skeleton that are themselves sub images from a main atlas if you want to.

I have quite a few files with no animation in them whatsoever. They are there just to be able to easily locate sprites and do so in a graphical environment rather then hard coding it in..... only to want to change it later.

People like different implementations and thats fine though. Iwas agreeing with you above saying that it would be nice to have the fixspritetosprite function


Xaby wrote: "A lot of the Skeleton commands from Spriter or Spine are missing in AGK.

Like
https://docs.yoyogames.com/source/dadiospice/002_reference/game%20assets/sprites/skeletal%20animations/skeleton_attachment_set.html"


Id agree that there is alot of functionality that could be added that would be great. Its also suprising how much you can do with what there is though.

That's ^^ actually a command in another game engine...GameMakerStudio. Thats just how they chose to implement a partcicular way of doing animation. You can have a sprite animate in spriter (change the image it uses over time) and then import into agk and it animates the image used. Great for explosion and smoke efccets etc.... Plus, you can play a sprite animation on a sprite that has been attached to a skeleton. You can also attach other sprites to your skeleton.

So if you wanted to change the sword or the gun your character is useing you can esily add a bone for it in your model, then simply attache the sprite that is the sword/gun to that bone ...this way you can effectively have an attachment position. You can even get the bone id by name so its a ssimply as FixSpriteToSkeleton() with your sword sprite.

I must admit the skeleton commands are quite under supported at the moment though. Some extra commands would be nice. Bone addition would be great so you can literally add them one at a time. We have a create skeleton command that is literally useless as you cant then create any bones so the ONLY way to work with it is to load spine or spriter files.


Anyway..just wanted to point out there are other ways of achieving similar effects. I too would like to see the FixSpritetoSprite implemented and thats what this thread is about so I dont want to derrail it....just show there are good alternatives is all.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 19th Aug 2018 18:26
Hopefully my post didn't come across the wrong way. I absolutely appreciate you sharing that information and example on using the skeleton2D and Spriter approach Bengismo.

It is definitely good to put it in here I think because there may be people who come across this thread who although looking for a simple FixSpriteToSprite solution actually were doing so as a compromise and would be thrilled to learn about this other solution.

GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 19th Aug 2018 18:27 Edited at: 20th Aug 2018 04:53
Regarding using the physics system...

I know... I know... I am an "old school" holdout... LOL! I have refused to use canned physics systems ever since I read a post on Unity forum of a person asking how to move characters in their platformer game and people replying apply movement forces to push them around. I tried it and it seemed like the craziest most illogical thing I have seen in game dev so far. Well that and people posting about their player and enemy characters falling over when bumping into another object, etc. and then were advised to add additional colliders to prevent that from happening. ha ha

I imagine those were just diehard canned physics system lovers though and surely most people don't do that. Lol Seems like so many people make this stuff way more complex than it is trying to use an 18-wheeler every time they need to get some milk and eggs from the grocery store. BUT anyway a desire to take advantage of more of the native AppGameKit features is what prompted me looking into a FixSpriteToSprite feature.

I'm doing good though!! This current project will use tweens and the sprite animation system. That is a HUGE step for me as normally I'd handle those myself.

Next game after this one I will look into using physics too.

For some context here... my grand ambitions at the moment are something along these lines (of course the turret on the tanks will rotate eventually when there is something for it to attack).
80x72 full screen resolution!
Jerry McGuire
7
Years of Service
User Offline
Joined: 25th Mar 2017
Location:
Posted: 28th Aug 2018 18:08
I also use these kind of ad-hoc solutions like using skeletons or setting the position based on the other sprites position. I second GarBenjamin's suggestion for such a feature.
iMac Book Pro, MacOS 10.12.4, Xcode 9.0.1;
iPhone 6, iOS 9.35; iPhone 5s, iOS 9.35; iPad (3rd gen), iOS 9.35;

Dell Precision T7400, Windows 7 Professional 64bit, Visual Studio Community 2017;
Icerion
6
Years of Service
User Offline
Joined: 3rd Aug 2018
Location:
Posted: 28th Aug 2018 18:21
Count me in, I third @GarBenjamin's suggestion!

Thanks!

Login to post a reply

Server time is: 2024-11-23 15:32:40
Your offset time is: 2024-11-23 15:32:40