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

[godot] Additive mix blending bug after track entries completed #2376

Open
Reltdeats opened this issue Sep 20, 2023 · 2 comments
Open

[godot] Additive mix blending bug after track entries completed #2376

Reltdeats opened this issue Sep 20, 2023 · 2 comments
Assignees
Labels

Comments

@Reltdeats
Copy link

See https://esotericsoftware.com/forum/d/24802-godot-additive-mix-blending-bug-after-track-entries-completed

@Reltdeats
Copy link
Author

To facilitate testing this bug, I replicated the additive blendig demo. Attach this code to the oficial Owl spine ( SpineSprite node ) and uncomment lines 22 to 25 to replicate the error.

extends SpineSprite

@export_range(0.0,10.0) var blend_speed = 5.0

@onready var state = get_animation_state()
@onready var left = state.set_animation('right', true, 2)
@onready var right = state.set_animation('left', true, 3)
@onready var up = state.set_animation('up', true, 4)
@onready var down = state.set_animation('down', true, 5)

var mouse_pos = Vector2.ZERO
var left_alpha =  0.0
var right_alpha =  0.0
var up_alpha =  0.0
var down_alpha =  0.0

# Called when the node enters the scene tree for the first time.
func _ready():
	state.set_animation("idle", true, 0)
	state.set_animation("blink", true, 1)
	
	# left.set_mix_blend(SpineConstant.MixBlend_Add)
	# right.set_mix_blend(SpineConstant.MixBlend_Add)
	# up.set_mix_blend(SpineConstant.MixBlend_Add)
	# down.set_mix_blend(SpineConstant.MixBlend_Add)
	
	left.set_alpha(0.0)
	right.set_alpha(0.0)
	up.set_alpha(0.0)
	down.set_alpha(0.0)
	
func _input(event):
	if event is InputEventMouseMotion:
		mouse_pos = event.position
	else:
		mouse_pos = get_viewport_rect().size / 2
		
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	calculate_blend(mouse_pos.x, mouse_pos.y, delta)
	
func calculate_blend(x, y, delta):
	var size = get_viewport_rect().size
	var center = size / 2
	
	var left_pos = 1 - x / center.x if x < center.x else 0.0;
	var right_pos = (x - center.x) / (size.x - center.x) if x > center.x else 0.0;
	var up_pos = 1 - y / center.y if y < center.y else 0.0;
	var down_pos = (y - center.y) / (size.y - center.y) if y > center.y else 0.0;
	
	
	left_alpha = lerp(left_alpha, left_pos, delta * blend_speed)
	right_alpha = lerp(right_alpha, right_pos, delta * blend_speed)
	up_alpha = lerp(up_alpha, up_pos, delta * blend_speed)
	down_alpha = lerp(down_alpha, down_pos, delta * blend_speed)
	
	left.set_alpha(left_alpha)
	right.set_alpha(right_alpha)
	up.set_alpha(up_alpha)
	down.set_alpha(down_alpha)

@badlogic
Copy link
Collaborator

Cheers!

@badlogic badlogic self-assigned this May 6, 2024
@badlogic badlogic added the bug label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants