Jump to content
GradusGL

v. 1.1.0 update Spriter 2D: Game Maker Studio extension

Recommended Posts

4 hours ago, Whillbo said:

Thanks GradusGL for making this. Also sorry if I'm just being a dummy how would go about doing collision with my objects using spriter_gm.

You can use the usual way, add sprite mask to you object. And you can use spriter box object. Add it on you spriter animation where you need to check collision (ex. in attack frame, or making hitboxes to check different damge).

collision_box = spriter_get_box_collision_rectangle(self,other_object,"box_000");
if collision_box!=noone
{
    show_message("Collision!");
}

Share this post


Link to post
Share on other sites

Hey GradusGL,

First off, excellent work, thank you. I, like most of the spriter/game maker community, have been waiting for this for sometime and will be implementing it into my project ASAP.

I haven't played around with this yet, but it sounds like you are saying the collision detection is specific to the mask made in Spriter? For example, can you make it so only collisions with the mace (or sword etc) are registered as collisions during the attack animation? Also, can you reference the specific coordinates/ spriter image (i.e., a weapon or the eyes of an animation) and access them in game maker to emit particles and special effects programatically? 

Might be a good idea to go over some collision functions in a tutorial video? I was a little lost as to the point of the point direction part of the video, seemed to not work properly in one direction.

This is looking promising. Any word on Spriter2/ GM2 support/ collaborations?

Share this post


Link to post
Share on other sites

@GradusGL Hey there! I'm currently trying to add something to this for my project. I'm trying to add the ability to change a sprites color during runtime.

I added a blend variable to the CGMObjectInfo class and I added setter/getter functions. Then I added the following to the exported functions

double spriter_GetObjectInfoBlend(double ModelIndex, double InstanceIndex, double ObjectInfoIndex)
{
	if (!CSpriterGM::GetSingleton()->IsObjectInfoValid(ModelIndex, InstanceIndex, ObjectInfoIndex))
		return 0;

	return CSpriterGM::GetSingleton()->GetSpriterGMModel(ModelIndex).GetInstance(InstanceIndex).GetGMObjectInfo(ObjectInfoIndex).GetBlend();
}

double spriter_SetObjectInfoBlend(double ModelIndex, double InstanceIndex, double ObjectInfoIndex, double newBlend) {
	if (!CSpriterGM::GetSingleton()->IsObjectInfoValid(ModelIndex, InstanceIndex, ObjectInfoIndex))
		return 0;
	CSpriterGM::GetSingleton()->GetSpriterGMModel(ModelIndex).GetInstance(InstanceIndex).GetGMObjectInfo(ObjectInfoIndex).SetBlend(newBlend);
}

The project I'm testing this with doesn't have any bones, just sprites, so I thought that zero for the object info index would be the first image. But when I call the function spriter_SetObjectInfoBlend(modelIndex,instanceIndex,0,c_blue) in GM:S, I get an "ImageFile not valid" error.

I'm just trying to add a color variable to each image being used so I can change the color at runtime. Colors in GM:S are just numbers so it's easy to pass them back and forth and I already know how to get the color on the sprites by changing one line in the spriter_render script. I'm hoping you might have an idea on why this isn't working. If you could help me better understand how the object info indices work, I think I can get this working relatively easy. Any help would be greatly appreciated.

 

 

Update: I managed to find a solution without changing the source code. This is a great extension. I probably sound like a broken record, but thanks again for making this.

Share this post


Link to post
Share on other sites

Many many thanks for this tool!

But I have some questions about finding coordinates of sprites generated by Spriter.

How to exactly use spriter_get_box_collision_rectangle(object, object_check, box_name) and spriter_get_box_point_x(object, object_index, point_name)???

What are box_name and object_index? Can you provide a little explanation?

For what I can say object_index refers to a sprite in the spriter hierarchy, but how can I get the bounding box (or width and height) of the whole sprite?

Thanks again ;)

Share this post


Link to post
Share on other sites

The object index is asking for index of the object that loaded the spriter model. For object index you generally want to use "id" which is the id of the instance that uses it. I haven't messed with boxes but I'm assuming box name is the name you give it inside Spriter.

 

 

 

@GradusGL I'm having issues with one of the functions. spriter_GetObjectInfoName always returns an empty string. I'm trying to change the color only for certain parts of my skeleton object. In this case it's for the hair and eyes. My solution at first was to check the filename but that makes a huge switch statement as I continue adding more hair styles and other parts that can have their color changed. I'm trying to be able to go from

if (name == "Path/To/Hair1.png" || name == "Path/To/Hair2.png" || name == "Path/To/Hair3.png") {
    color = SomeColor;
}
if (name == "Path/To/Eye.png) {
    color = SomeColor;
}

to something like

if (name == "image_hair") {
    color = SomeColor;
}

if (name == "image_eye_left") {
    color = LeftEyeColor;
}

if (name == "image_eye_right") {
    color = RightEyeColor;
}

 

The downside of the first solution is it requires a bunch of OR operators or a large switch statement as I add more hairstyles and the eyes are stuck to only being a single color since it's going by the filename vs the object name.

 

I print the result of spriter_GetObjectInfoName to the console output. I call it inside the spriter_render function within the loop that runs through all the objects. spriter_GetObjectInfoFileName and spriter_GetObjectInfoString both return what they're supposed to but I don't know why spriter_GetObjectInfoName isn't working.

 

Share this post


Link to post
Share on other sites

spriter_GetObjectInfoName(...) return name of box, point and bone objects. spriter_GetObjectInfoType(...) return enum such as UNKNOWN = 0, IMAGE = 1, BOX = 2, POINT = 3, BONE = 4. For example:

var count = spriter_GetObjectInfoCount(modelIndex, instanceIndex);

for (i = 0; i < count; i++)
{
    var type = spriter_GetObjectInfoType(modelIndex, instanceIndex, i);
    var name = spriter_GetObjectInfoFileName(modelIndex, instanceIndex, i);
    
    if (type != 1)
    {
        name = spriter_GetObjectInfoName (modelIndex, instanceIndex, i);
    }
}

I think for the color you need to use ds_map.

var count = spriter_GetObjectInfoCount(modelIndex, instanceIndex);

for (i = 0; i < count; i++)
{
    var type = spriter_GetObjectInfoType(modelIndex, instanceIndex, i);
    var name = spriter_GetObjectInfoFileName(modelIndex, instanceIndex, i);
    
    if (type != 1)
    {
        name = spriter_GetObjectInfoName(modelIndex, instanceIndex, i);
    }
    
    blend = image_blend;
    
    if (ds_map_exists(color_map, name))
    {
        blend = ds_map_find_value(color_map, name);
    }
}

 

Share this post


Link to post
Share on other sites
10 hours ago, hippyman said:

The object index is asking for index of the object that loaded the spriter model. For object index you generally want to use "id" which is the id of the instance that uses it. I haven't messed with boxes but I'm assuming box name is the name you give it inside Spriter.

Mmmh, doesn't seem to work this way: if I use id in object_index I always get an error.

// this gives error
var tlx = spriter_get_box_point_x(self, id, "TopLeft");

// this seems to work
var tlx = spriter_get_box_point_x(self, "fake_Spriter_sprite_name", "TopLeft");

But this forces to make a fake sprite in Spriter that is as great as the wanted bounding box. I can't find another way to get the dimensions of a sprite imported in GMS with this extension.

Please correct me if I'm wrong.

Share this post


Link to post
Share on other sites

You need to add box to your spriter project than check collision.

var object_index = spriter_find_object(self, "box_000");

if object_index != -1
{
    var top_left_x = spriter_get_box_point_x(self, object_index, "TopLeft");
    var top_left_y = spriter_get_box_point_y(self, object_index, "TopLeft");
    var bottom_right_x = spriter_get_box_point_x(self, object_index, "BottomRight");
    var bottom_right_y = spriter_get_box_point_y(self, object_index, "BottomRight");
  
  	//2D collision detection
}

Another way:

var object_index = spriter_find_object(self, "box_000");

if object_index != -1
{
     var top_left_x = spriter_GetObjectInfoMeshPointX(modelIndex, instanceIndex, object_index, 0);
     var top_left_y = spriter_GetObjectInfoMeshPointY(modelIndex, instanceIndex, object_index, 0);
     var top_right_x = spriter_GetObjectInfoMeshPointX(modelIndex, instanceIndex, object_index, 1);
     var top_right_y = spriter_GetObjectInfoMeshPointY(modelIndex, instanceIndex, object_index, 1);
     var bottom_right_x = spriter_GetObjectInfoMeshPointX(modelIndex, instanceIndex, object_index, 2);
     var bottom_right_y = spriter_GetObjectInfoMeshPointY(modelIndex, instanceIndex, object_index, 2);
     var bottom_left_x = spriter_GetObjectInfoMeshPointX(modelIndex, instanceIndex, object_index, 3);
     var bottom_left_y = spriter_GetObjectInfoMeshPointY(modelIndex, instanceIndex, object_index, 3);

	 //2D collision detection
}

or:

if (spriter_get_box_collision_rectangle(self, enemy, "box_000") != undefined)
{
	//Collision
}

 

Безымянный.png

Share this post


Link to post
Share on other sites
10 hours ago, Gillmog said:

spriter_GetObjectInfoName(...) return name of box, point and bone objects. spriter_GetObjectInfoType(...) return enum such as UNKNOWN = 0, IMAGE = 1, BOX = 2, POINT = 3, BONE = 4. For example:

I think for the color you need to use ds_map.

Okay cool after knowing this I managed to get a readout of my skeleton and found the individual IDs of each image that I wanted to color. Thanks for you help :-D

 

 

9 hours ago, simonmatts said:

Mmmh, doesn't seem to work this way: if I use id in object_index I always get an error.


// this gives error
var tlx = spriter_get_box_point_x(self, id, "TopLeft");

// this seems to work
var tlx = spriter_get_box_point_x(self, "fake_Spriter_sprite_name", "TopLeft");

But this forces to make a fake sprite in Spriter that is as great as the wanted bounding box. I can't find another way to get the dimensions of a sprite imported in GMS with this extension.

Please correct me if I'm wrong.

Sorry when I was saying use id, I meant to use that where you're using self. But again like I stated, I haven't used boxes or points yet, so I was just assuming from the way the other scripts work.

Share this post


Link to post
Share on other sites
22 hours ago, Gillmog said:

You need to add box to your spriter project than check collision.


var object_index = spriter_find_object(self, "box_000");

if object_index != -1
{
    var top_left_x = spriter_get_box_point_x(self, object_index, "TopLeft");
    var top_left_y = spriter_get_box_point_y(self, object_index, "TopLeft");
    var bottom_right_x = spriter_get_box_point_x(self, object_index, "BottomRight");
    var bottom_right_y = spriter_get_box_point_y(self, object_index, "BottomRight");
  
  	//2D collision detection
}

Безымянный.png

Many thanks, this is what I looked for.

The only thing I don't understand is (sorry, I'm totally new to Spriter): why do you create a box_000, what is it? Can't you simply set the longsword as object?

And so, if I wish to know the bounding box of the entire sprite (or a significant portion of it, like in the image below) should I create a little sprite and adapt it to the wanted size?

 

box.png

Share this post


Link to post
Share on other sites
2 hours ago, simonmatts said:

Many thanks, this is what I looked for.

The only thing I don't understand is (sorry, I'm totally new to Spriter): why do you create a box_000, what is it? Can't you simply set the longsword as object?

And so, if I wish to know the bounding box of the entire sprite (or a significant portion of it, like in the image below) should I create a little sprite and adapt it to the wanted size?

 

box.png

It possible to add box object to check collision! For example, you attack animation contains sword in all frames, but in game you need deal damage in fixed phase of animation. 

ttut.png

Share this post


Link to post
Share on other sites
21 hours ago, GradusGL said:

It possible to add box object to check collision! For example, you attack animation contains sword in all frames, but in game you need deal damage in fixed phase of animation. 

ttut.png

Great, thanks! This is what I really missed.

Again: thanks for this awesome extension and for Spriter which I'm starting to love!

Share this post


Link to post
Share on other sites

With my current project, I'm using sprites rather than bones.

When I switch from one animation to another, it seems like the new animation starts at the current time of the old one (for example, if the old animation is at 200ms, the new one starts at 200ms, rather than 0ms). This can cause weird stuttering in the animations.  How do I manually tell the game to go back to frame 0 of the animation?

Share this post


Link to post
Share on other sites

There is no image index with this. I'm not sure what the purpose of this function is, but it's what we have to use to apparently make animation transitions work properly. The documentation is really basic so it's kind of hard to tell what some of these are for.

Share this post


Link to post
Share on other sites

I have problems with my GM project, as characters won't show in my other computer. I have been working with my laptop using Game Maker Studio (working fine for most parts), and when I tested it with my desktop, characters are nowhere to be seen. As I thought it would be problem with exported application, I send project file to other computer as whole, opened it there, and tried run file. Characters do not show, everything else works. What might be reason?

 

Oh, and it seems I have problem with blending animations. Stuttering occurs when you start blending new animation before previous blending has ended. This is especially visible when character is crouching, then stand and shortly run. I think it might occur also if you try go back to original animation before blending is finished. Is there boolean command like 'is blending'?

Share this post


Link to post
Share on other sites

Hi, is it really necessary to do all those tedious tasks to run and build for Android?

Quote

• Open Global Game Settings in the tab Android/Fire write Min SDK 15

• Change in the file /GameMaker-Studio/Android/runner/gradle/gradle/wrapper/gradle-wrapper.properties distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip to distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip

• Change in the file /GameMaker-Studio/Android/runner/RootFiles/build.gradle classpath 'com.android.tools.build:gradle:2.1.0' to classpath 'com.android.tools.build:gradle:2.2.2'

• Change in the file /GameMaker-Studio/Android/runner/RootFiles/settings.gradle include ':${YYAndroidPackageName}' to include ':${YYAndroidPackageName}', ':libspritergm'

• Copy file from https://github.com/Gillmog/spriterGM/blob/master/GameMaker-Studio/Android/runner/RootFiles/local.properties to /GameMaker-Studio/Android/runner/RootFiles/ Change the path to sdk and ndk in local.properties ndk.dir=C\:\\Android\\sdk\\ndk-bundle and sdk.dir=C\:\\Android\\sdk to your path

• Create symbolic link from GameMaker-Studio/Android/runner/RootFiles/ to root folder of the git clone, for example on Windows that to be mklink /D c:\Users\user-name\AppData\Roaming\GameMaker-Studio\Android\runner\RootFiles\libspritergm git-folder\SpriterGM\

• File example for GameMaker are in the: https://github.com/Gillmog/spriterGM/tree/master/GameMaker-Studio

• When the plugin update be sure to remove Cache, if there are any errors.

I get this error:

A problem occurred configuring project ':com.salamandra.dungeonsandme'.
> Could not resolve all dependencies for configuration ':com.salamandra.dungeonsandme:_debugApk'.
   > Project :com.salamandra.dungeonsandme declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :libspritergm.

 

Share this post


Link to post
Share on other sites

@GradusGL I cannot get out of this problem with Android build/run... I've tried many combinations of android sdk and ndk, but every time I get this error, even with your included project:

 

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':com.companyname.SpriterGM'.
> Could not resolve all dependencies for configuration ':com.companyname.SpriterGM:_debugApk'.
   > Project :com.companyname.SpriterGM declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :libspritergm.

What can be the problem?

Share this post


Link to post
Share on other sites

Hi everyone, i'm testing how to use spriter animations with gamemaker. I did everything like in the tutorial and took this file : https://github.com/Gillmog/spriterGM/blob/master/extension/spriterGM.gmez

But my animation doesn't appear when i'm running the "game"

I compared with your examples and really i can't see where i did wrong. Maybe there are some special things to do in Spriter that i'd have forgotten.. Custom save options maybe... ?

Maybe it's the same problem that Drandula met... If someone can help me it would be really appreciated :-) thanks !

 

test_use_spriter_01.gmz

Share this post


Link to post
Share on other sites

Okay so i put my scml file with my animation in the SpriterGM_tutorial1 (with moss_golem) i downloaded. I did all the events etc and here it's working. My animation is played when i'm running the game, but... i'd like to understand where is the problem :-/

It seems that the difficulty is with my game maker project or with the scripts spriterGM.gmez. Are the scripts used in the tutorial files the same as the last spriterGM.gmez that i used?? Or is there another step to execute in GM (i'm using GM studio 1.4) ?

I'd really like to be able to start from scratch and not use your tutorial file as a template.. If you have any clue, please do tell me :-)

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