• Editor
  • Menu buttons with spine (Cocos2d)

  • Đã chỉnh sửa

I want to create menu with Spine. I believe that I have to make bones with names. Then check the name of bone that I touch to run suitable method.
Where I can find some example of checking collision with bounding box of specific skeleton parts?

I've found how to find specific attachment by name(http://esotericsoftware.com/forum/viewt ... slot#p2731) But it seems that now attachments doesn't have ->quad.

Related Discussions
...
  • Đã chỉnh sửa

Take a look at CCSkeleton boundingBox. Code is like:

	float vertices[8];
	for (int i = 0; i < _skeleton->slotCount; ++i) {
		Slot* slot = _skeleton->slots[i];
		if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
		RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
		RegionAttachment_computeVertices(attachment, slot, vertices);
		// Do something with:
		// vertices[VERTEX_X1]
		// vertices[VERTEX_Y1]
		// vertices[VERTEX_X2]
		// vertices[VERTEX_Y2]
		// vertices[VERTEX_X3]
		// vertices[VERTEX_Y3]
		// vertices[VERTEX_X4]
		// vertices[VERTEX_Y4]
	}

Note I am just about to update boundingBox like the above because I saw it is more efficient not to use a quad.

Once you have the vertices, rotated, scaled, etc... you can use a winding number algorithm: http://geomalgorithms.com/a03-_inclusion.html

Don't worry if the article makes your head spin, there's code at the bottom. Make sure to add the first vertex at the end of the array you pass in.