Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement alpha when drawing sprites #6

Open
slyddar opened this issue Mar 6, 2024 · 1 comment
Open

Implement alpha when drawing sprites #6

slyddar opened this issue Mar 6, 2024 · 1 comment

Comments

@slyddar
Copy link

slyddar commented Mar 6, 2024

Was wondering if you could implement a way to pass an alpha value to disarm_mesh_add_armature(). I added it as an argument to pass _alpha in and then modified this line of the function as such :

var alpha = slot.alpha * _alpha;

All this does is darken the sprite a little though. So is there anyway to change the alpha of the drawn sprite?

@slyddar
Copy link
Author

slyddar commented Mar 6, 2024

Actually I did get it working using this exact method. Guess it might be something you could add to the main branch as it does work to allow alpha values for drawn sprites.

While I'm here though, a huge thank your for putting this project out for others to use, it does a really good job once implemented. I also added these functions which maybe others can use :

  • disarm_get_animation_length - get the length of the spriter animation
  • disarm_get_animation_speed - get the speed of the sprite animation
  • disarm_anim_time_is - used like image_index checks but for spriter animations

For these to work just like image_index does, I've changed the project timing, where as you had animations between 0 and 1 for aTime, incremented by aSpeed of 0.01, I wanted it to correspond to the frames in the animations. So I use anim_time which is incremented per step by anim_speed, which is 1000/60 so 16.667. These three functions can then be used to do checks such as see what animation frame we are on, or if the animation has ended using the same frame numbers as Spriter shows.

Thanks again, if you need more info on these additions, let me know.

/// @desc returns the passed animations length
/// @param {struct} arm The Disarm instance to update.
/// @param {real} anim_name_or_id The name of the animation to return
function disarm_get_animation_length(_arm, _anim) {
    var entity = _arm.entities[_arm.currentEntity];
    var anim_id = entity.anims[__disarm_get_index_id_or_name(entity.animTable, _anim)];
	return anim_id.duration;
}

/// @desc returns the passed animations animation speed
/// @param {struct} arm The Disarm instance to update.
/// @param {real} anim_name_or_id The name of the animations anim_speed to return
function disarm_get_animation_speed(_arm, _anim) {
    var entity = _arm.entities[_arm.currentEntity];
    var anim_id = entity.anims[__disarm_get_index_id_or_name(entity.animTable, _anim)];
	return 	(0.01 / (anim_id.duration / 1000));
}

/// @desc returns true if anim_time is at the passed time
/// @param {real} time returns true if the anim frame is at the passed time
function disarm_anim_time_is(_time) {
	if anim_time >= _time and anim_time < _time + anim_speed return true;	
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant