0 votes

Alright, I've been looking at tutorials on youtube to get myself familiarized with Godot.

So far so good, a little hang up as the video is a bit older. The game in question is a brick breaking game. Simple, straight forward. Best way to learn I figured is to tweak it, fiddle, and try to add my own ideas further on it. The snag is I can't seem to figure out how to spawn a new ball when the old one gets past the paddle.

extends KinematicBody2D
class_name Paddle

const new_ball = preload("res://Mini Scene/Ball.tscn")

func ready():
set
physicsprocess(true)
set
process_input(true)

func physicsprocess(delta):
var y = position.y
var mousex = getviewport().getmouseposition().x
setposition(Vector2(mousex, y))

func inputevent(viewport, event, shapeidx):
if event.type == new
ball.end:
var ball = newball.instance()
ball.set
position(position-Vector2(0, 16))
getparent().addchild(ball)

I apologize if I have totally butchered this, as I am new to this. So far in my readings over the course of several hours, all the text i've come across is how to spawn something based on a mouse or the keyboard but I want it to automatically spawn at the point of the paddle.Could I get some help perhaps?

Thank you.

asked Apr 13 in Projects by EtrnlFlux (12 points)

Don't know if my question got buried. I apologize for beating a dead horse, but I feel that this is a bit of important question to ask. So far, I still have yet to find any way to spawn something without input from the user. Is there anyone out there that is capable of answer this? Would really appreciate it!

1 Answer

0 votes

Hey,

How about an Area2D? If the balls enters the zone, que it free and then spawn a new one?

answered Apr 13 by Nuky (14 points)

I wouldn't mind doing that. As I have no problem removing the ball when it goes out of bounds. The thing is, HOW do I create a new ball, without it requiring input from the user?

So far any and all tutorials I have read/seen involve a key press or a mouse input for me to spawn a new ball. Is their no way to make this an automatic feature?

e.g.

func inputevent(viewport, event, shapeidx):
if event.type == new
ball.queuefree():
var ball = new
ball.instance()
ball.setposition(position-Vector2(350, 350))
get
parent().add_child(ball)

Perhaps I am wrong in how I am "phrasing" my code for godot to understand. Im like a childing fumbling in the dark here. But essentially in my eyes, I am saying IF an event.type newball is queuefreed, then get the new_ball instance, set its position, and then I direct it to the balls root scene.

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 How to use this Q&A? before posting your first questions.