The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I used this code:
extends Area2D

var rand = RandomNumberGenerator.new()

onready var attacksprite = get_node("Attack1")

onready var timer = $AttackTimer

func ready():
timer.start()
rand.randomize()
add
to_group("attack")

set_process_input(true)
get_sprite_frames(0).get_frame_count("Attackanimation")

func process(delta: float) -> void:
var frames = preload("res://assets/Attackanimation.tres")
getchild(0).setframes(1)

func onAttackTimertimeout():
queue
free()

for making my attacks appear, but it's not working. Can you please help me?

Godot version 3.2.3
in Engine by (23 points)

1 Answer

0 votes

Next time you ask a question, it would be helpful to post what specific errors you're getting.

So I see a bunch of errors here:

get_sprite_frames(0).get_frame_count("Attackanimation")

Area2D does not have the method get_sprite_frames() - it's for AnimatedSprite and takes no arguments since it's an accessor method. If attacksprite is the AnimatedSprite you need

attacksprite.frames.get_frame_count("Attackanimation")

Also, if attacksprite is the first child of the Area2D, there is no need to have get_child(0) when you already have a variable that points to that node. Also, set_frames() isn't a method. You're probably looking for set_sprite_frames(), but you can just set the frames property directly since there are no private properties in GDScript. It doesn't take an int as an argument but rather a SpriteFrames resource, which I'm guessing is the frames variable.

I suggest that you read some more tutorials on GDScript so you understand how methods and variables work.

by (8,550 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.