Jump to content
Discobeard

Generic Java Importer

Recommended Posts

Okay... I am done... except for the LWJGL implementation, which I won't implement now, since it takes more effort to code a usable one and it seems that everyone uses LibGDX anyway.

Every specific implementation has its own project:

Generic, required by every implementation: https://github.com/Trixt0r/spriter

LibGDX: https://github.com/Trixt0r/gdx-spriter

Slick2D: https://github.com/Trixt0r/slick2d-spriter

Java2D: https://github.com/Trixt0r/java2d-spriter

Share this post


Link to post
Share on other sites
On 12/1/2016 at 5:01 PM, Trixt0r said:

Okay... I am done... except for the LWJGL implementation, which I won't implement now, since it takes more effort to code a usable one and it seems that everyone uses LibGDX anyway.

Every specific implementation has its own project:

Generic, required by every implementation: https://github.com/Trixt0r/spriter

LibGDX: https://github.com/Trixt0r/gdx-spriter

Slick2D: https://github.com/Trixt0r/slick2d-spriter

Java2D: https://github.com/Trixt0r/java2d-spriter

Thanks for all your awesome work, it looks great! I look forward to trying this in my project.

Happy Holidays!

Share this post


Link to post
Share on other sites

Hi and thanks for your work Trixt0r.

How can I set the position of my (Animation)Player without having any interpolation ? I just want to set it's position normally (teleport it) since my game logic is controlling my character by itself.

For now I got something like that https://i.gyazo.com/e5682ad2a6f8ea6c4579713a54e6385f.mp4

Thanks 

 

EDIT: Sorry, I was just setting the position before updating... So no problems

Share this post


Link to post
Share on other sites

Hi all,

Thank you Trixt0r for your implementation. After adapting the generic C++ reference implementation for the Windows platform on the CF2.5 game engine, I am now porting this implementation to Android.

I used your code to perform this but I have got the usual first nightmare which is the coordinate system which is not really standard on this game engine.

I got this on grey guy standard example (see attached image).

From your experience, where do you think I need to investigate first and where in code?

- reverse Y on Load?

- reverse angle on Load?

 

bug_drawing.jpg

Share this post


Link to post
Share on other sites
On 11.3.2017 at 9:58 PM, conceptgame said:

From your experience, where do you think I need to investigate first and where in code?

This looks like the origin of your sprites is not applied/renderer properly, i.e you don't calculate the pivot points correctly.

It also looks like your y-axis is pointing down, i.e. it grows to the bottom while Spriter's y-axis points upwards.

- Trixt0r

Share this post


Link to post
Share on other sites

Thanks for the help Trixt0r,

I tried the obvious possibilities (1-pivot.y and -y) in SCMLReader but with no luck.

protected void loadFiles(ArrayList<Element> files, Folder folder){
		for(int j = 0; j < files.size(); j++){
			Element f = files.get(j);
			File file = new File(f.getInt("id"), f.get("name"),
					new Dimension(f.getInt("width", 0), f.getInt("height", 0)),
					new Point(f.getFloat("pivot_x", 0f), 1.0f-f.getFloat("pivot_y", 1f)));
			
			folder.addFile(file);
		}
	}


protected void loadTimelineKeys(ArrayList<Element> keys, Timeline timeline){
		for(int i = 0; i< keys.size(); i++){
			Element k = keys.get(i);
			Curve curve = new Curve();
			curve.setType(Curve.getType(k.get("curve_type", "linear")));
			curve.constraints.set(k.getFloat("c1", 0f),k.getFloat("c2", 0f),k.getFloat("c3", 0f),k.getFloat("c4", 0f));
			Timeline.Key key = new Timeline.Key(k.getInt("id"), k.getInt("time", 0), k.getInt("spin", 1), curve);
			Element obj = k.getChildByName("bone");
			if(obj == null) obj = k.getChildByName("object");
			
			Point position = new Point(obj.getFloat("x", 0f), -1.0f*obj.getFloat("y", 0f));
			Point scale = new Point(obj.getFloat("scale_x", 1f), obj.getFloat("scale_y", 1f));
			Point pivot = new Point(obj.getFloat("pivot_x", 0f), 1.0f-obj.getFloat("pivot_y", (timeline.objectInfo.type == ObjectType.Bone)? .5f:1f));
			float angle = obj.getFloat("angle", 0f), alpha = 1f;
			int folder = -1, file = -1;
			if(obj.getName().equals("object")){
				if(timeline.objectInfo.type == ObjectType.Sprite){
					alpha = obj.getFloat("a", 1f);
					folder = obj.getInt("folder", -1);
					file = obj.getInt("file", -1);
					File f = data.getFolder(folder).getFile(file);
					pivot = new Point(obj.getFloat("pivot_x", f.pivot.x), 1.0f-obj.getFloat("pivot_y", f.pivot.y));
					timeline.objectInfo.size.set(f.size);
				}
			}
			Timeline.Key.Object object;
			if(obj.getName().equals("bone")) object = new Timeline.Key.Object(position, scale, pivot, angle, alpha, new FileReference(folder, file));
			else object = new Timeline.Key.Object(position, scale, pivot, angle, alpha, new FileReference(folder, file));
			key.setObject(object);
			timeline.addKey(key);
		}
	}

The current result is in attachment. What we cannot see on screenshot is that the hands are going away from body when this one is going down although it should be the contrary in the original spriter file for the grey guy.

 

I tried also all the combinations with angle (360-angle) and spin (-spin) but there is always something not working.

From what I can see, all seems ok in the animation excepting the y axis which seems to go in the wrong direction. But as explained before just changing this:

Point position = new Point(obj.getFloat("x", 0f), -1.0f*obj.getFloat("y", 0f));

does not help.

I cannot figure out what is going wrong. I guess I need to debug with Android Studio, which is really a pain on my "little" configuration.

EDIT:

ok, i compared with my implementation in generic C++ importer and changed the right-handed transformation in Point to the left-handed system and it seems better (I replaced the last attachment before edit with the new screenshot) but still not perfect. Any ideas?

public Point rotate(float degrees){
		if(x != 0 || y != 0){
			float cos = Calculator.cosDeg(degrees);
			float sin = Calculator.sinDeg(degrees);
			
			//float xx = x*cos-y*sin;
			//float yy = x*sin+y*cos;
			/*
			// Left Handed rotation in CF2.5 (Direct3D convention)
			p'x = p.x * c + p.y * s;
			p'y = -p.x * s + p.y * c;*/
			float xx = x*cos+y*sin;
			float yy = -x*sin+y*cos;
			
			this.x = xx;
			this.y = yy;
		}
		return this;
	}

Screenshot_20170320-121859.png

Share this post


Link to post
Share on other sites

I removed the pivot inversion in loadFiles from SCMLReader and finally all keyframes are placed correctly but the interpolation seems to be broken.

Did I forget something related to my specific coordinate system?

Edit: I found that the deltaTime between each update is not working properly. It happens often that asking for help is rising new ideas for debugging.

Thanks for those who took time to read my questions.

I can now go forward with the Android port.

Share this post


Link to post
Share on other sites

Hi again,

What is the status of the following features:

- SubEntities

- Events (Triggers)

- Sounds

- Variables (I saw that there is a Meta class but it does not seem to be used at all and no parsing in SCMLReader)

- Tags

If not implemented I will look to make my changes so that I can push the changes back into to trunk afterwards.

Share this post


Link to post
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...