Jump to content
Spriter Forums

Generic Java Importer


Discobeard

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

Link to comment
Share on other sites

  • 5 weeks later...
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!

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
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

Link to comment
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

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

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

Link to comment
Share on other sites

  • 6 months later...
  • 2 years later...
On 11/11/2014 at 11:18 PM, jraselin said:

I've done some patch to fix these bugs

Character map with "hidden" object => the objects are still drawed

inside SCMLReader

 

 

protected void loadCharacterMaps(ArrayList maps, Entity entity) {
		for (int i = 0; i < maps.size(); i++) {
			Element map = maps.get(i);
			Entity.CharacterMap charMap = new Entity.CharacterMap(map.getInt("id"), map.getAttribute("name", "charMap"
					+ i));
			entity.addCharacterMap(charMap);
			ArrayList mappings = map.getChildrenByName("map");
			for (Element mapping : mappings) {
				int folder = mapping.getInt("folder");
				int file = mapping.getInt("file");
				if (mapping.get("target_folder", null) == null) {
					charMap.put(new FileReference(folder, file), null);
				} else {
					charMap.put(new FileReference(folder, file), new FileReference(mapping.getInt("target_folder"),
							mapping.getInt("target_file")));
				}
			}
		}
	}

 

and the Drawer

 

 

public void draw(Iterator it, CharacterMap[] maps) {
		while (it.hasNext()) {
			Timeline.Key.Object object = it.next();
			if (object.ref.hasFile()) {
				// apply map
				if (maps != null) {
					for (CharacterMap map : maps) {
						// key exists
						if (map != null && map.containsKey(object.ref)) {
							// draw if not "hidden" 
							if (map.get(object.ref) != null) {
								object.ref.set(map.get(object.ref));
								this.draw(object);
							}
							break;
						} else {
							this.draw(object);
						}
					}
				} else {
					this.draw(object);
				}

			}
		}
	}

Hi....

this seems to be a good partial fix...

it now recognises "hidden" sprites on the first character map but not on any others 

or am I doing something wrong?

 

 

Edited by Matt_UK
condescending
Link to comment
Share on other sites

this was me doing it wrong....

I didnt understand the charactermaps example code properly (and probably I still don`t)

i used:

 
public boolean touchDown (int screenX, int screenY, int pointer, int button) {

if(button != Input.Buttons.RIGHT)

player.characterMaps[i] = charMaps[i]; //set the character map to the one saved in maps 
  else   player.characterMaps = null; //set the char map to null, to remove it   i = (player.characterMaps.length+(++i))%player.characterMaps.length;   return false;  

}

 

 

but when i changed it to 

  player.characterMaps[0] = charMaps[i]; //set the character map to the one saved in maps

 

everything worked as planned.

 

I then spent a day with a working character map demo and being unable to get the Spriter Player to render within my game logic.

turns out I didn`t understand Camera classes properly either so now that`s fixed i seem to be able to completely get rid of spritesheets in my game and the world is a wonderful place again :)

 

                         

 

Link to comment
Share on other sites

  • 1 month later...

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...