Jump to content

How x & y position in SCON file is calculated?


clym

Recommended Posts

Hi there,

I'm currently trying to work with the .scon (json) file type that Spriter exports and I'm slightly confused by some of it's translation...

Q: (Using Spriter release 11)

- For the root bone, the X & Y positions found in the timeline array are the same as in the editor.

- However the child bones X&Y position in the .scon seem to be very different to the editor and I can't figure out if the position is relative to the end X&Y of the parent/root bone? Or something else.

any info on that would be great! Let me know if you need an aditional info/pics

I'm finding the bone info under: entity[0].animation[0].timeline[0].key[0].bone.angle

Thanks,
Clym

Link to comment
Share on other sites

Hi @lucid many thanks for your speedy reply!

That's also what I thought originally although the numbers aren't coming out the same...maybe i'm doing something wrong. Let me give an example of just 2 bones:

bone1 (root): X: 0, Y: 0, angle: 43.688, width: 149.44399. Using Cos and Sin method, the X+Y of the end is about: X: 108, Y: 103 (Math.cos(angle*(Math.PI/180))*width and Math.sin(angle*(Math.PI/180))*width) - which when I check in editor by manually placing a bone at those coordinates it seems correct. (Although Y is actually negative -103 vs 103 but that's fine).

bone2 (parented to root): (in editor): X:190.322, Y: -182.258. (in .scon): X: 263.515, Y: 0.33074.

Now even if we took just the Y value of bone 2: 103 + 0.33074 does not equal -182.258 or 182.258. Even if I do: 103 - 0.33074 it still remains no where near that -182 mark!

If I go for the X: 108 + 263 = 371 or 108 - 263 = -155 or 263 - 108 = 155. So as you can see no matter what I try it still is no where near the editor values of X:190.

I've attached some pics hopefully that all makes some sense! Any light shed would be amazing! Thanks :)

Clym

Screenshot_7.png

Screenshot_8.pngScreenshot_10.pngScreenshot_9.png

Link to comment
Share on other sites

46 minutes ago, lucid said:

The editor numbers are absolute rather than relative.

Yes relative to the x&y of the end of the root bone?

Is the root bone x+y absolute? If so...

If i take the x of the end root bone and + the "relative" value to that...it comes to 371 in the example I gave. Vs it actually needs to be x:190 not 371!

Any ideas how to convert that relative number to an absolute one?

cheers

Link to comment
Share on other sites

Just thought of a couple of things it could be.  First, since Spriter uses only rigid transformations, apply the xScale and yScale before applying the angle.    Also, in your original post, you used 'width' and 'height' in your formulas.  You would use xScale and yScale.  Width is only for if you want to draw the actual bone itself.

Link to comment
Share on other sites

12 minutes ago, lucid said:

Just thought of a couple of things it could be.  First, since Spriter uses only rigid transformations, apply the xScale and yScale before applying the angle.    Also, in your original post, you used 'width' and 'height' in your formulas.  You would use xScale and yScale.  Width is only for if you want to draw the actual bone itself.

I've attached an image to show that I'm trying to get the "???" x + y value.

Yeah I used the length (or width) of the root bone found in "obj_info" as "w:149" line 110 in the attached file - and the angle to find the x+y end position using basic trigonometry. The end x&y position of the root bone comes out correct (tested in the editor by creating a new bone with no parent).

The xScale and yScale are default 1, for all the bones so I don't think that even showed up in the .scon file. I'll attach that file ...

Even If I did apply that I'm not sure how that would change? for example 371*1 = still 371.

Cheers,

boneTest4.scon

Screenshot_11.png

Link to comment
Share on other sites

Ah!  I see.  I totally misunderstood what you mean by 'end X&Y of the parent/root bone'.  I thought you meant the x and y of the parent after any transformations, which is the correct method.  You just transform the child bones and sprites from the parent's x and y values after they've been transformed by their parents. There's no need to calculate the endpoints with the bone width unless you want to draw the bones on screen.

Link to comment
Share on other sites

4 hours ago, lucid said:

Ah!  I see.  I totally misunderstood what you mean by 'end X&Y of the parent/root bone'.  I thought you meant the x and y of the parent after any transformations, which is the correct method.  You just transform the child bones and sprites from the parent's x and y values after they've been transformed by their parents. There's no need to calculate the endpoints with the bone width unless you want to draw the bones on screen.

Hmm so in the example given, you're saying bone_001's X&Y position will be that of the parent? At frame 1 the parent bone (bone_000) x&y = 0, so bone_001's x&y is therefore 0?

I'm not quite sure I follow how that would work? :shock:

Is there somewhere that has .scon reference so I know what each part is referring to?

Cheers

Link to comment
Share on other sites

3 hours ago, lucid said:

It's the same as what you started with, but the pivot of your rotation is the base of the parent bone, not the endpoint of the parent bone.

OOooh I got it thank you!!

So the reason I was messing up was on the example I gave, the angle was set to 43....once I set it to 0 degrees the X&Y were correct!!

Then I apply the rotation based on the parent X+Y & parent Angle vs what I was doing which was trying to find the X+Y using the parent end point haha.

Thank you for your patience!! Cheers @lucid

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...