Skip to main content
deleted 49 characters in body
Source Link
House
  • 73.5k
  • 17
  • 188
  • 276

I'm playing around with making a puzzle game, haven't done that much before I run into my first problem.

Basically, I want to create a certain amount of the same object/function. But without hardcoding the different instances.

I think maybe an array is a good idea? and then a for loop to push the objects in?

And then Then I need to be able to select one of these objects by clicking on it, how would I do that?

  How do I know which ball in the array was clicked? A loop again?

I made a jsFiddle example (you need to click the orange ball to select, then you can move it around by clicking the canvas).

  This is what I want to do, but with more balls. How would you solve this?

Help appreciated.

I'm playing around with making a puzzle game, haven't done that much before I run into my first problem.

Basically, I want to create a certain amount of the same object/function. But without hardcoding the different instances.

I think maybe an array is a good idea? and then a for loop to push the objects in?

And then I need to be able to select one of these objects by clicking on it, how would I do that?

  How do I know which ball in the array was clicked? A loop again?

I made a jsFiddle example (you need to click the orange ball to select, then you can move it around by clicking the canvas).

  This is what I want to do, but with more balls. How would you solve this?

Help appreciated.

I'm playing around with making a puzzle game, haven't done that much before I run into my first problem. I want to create a certain amount of the same object/function. But without hardcoding the different instances.

I think maybe an array is a good idea? and then a for loop to push the objects in? Then I need to be able to select one of these objects by clicking on it, how would I do that? How do I know which ball in the array was clicked? A loop again?

I made a jsFiddle example (you need to click the orange ball to select, then you can move it around by clicking the canvas). This is what I want to do, but with more balls. How would you solve this?

edited body
Source Link

I'm playing around with making a puzzle game, haven't done that much before I run into my first problem.

Basically, I want to create a certain amount of the same object/function. But without hardcoding the different instances.

I think maybe an array is a good idea? and then a for loop to push the objects in?

And then I need to be able to select one of these objects by clicking on it, how would I do that?

How do I know which ball in the array was clicked? A loop again?

I made a jsFiddlejsFiddle example (you need to click the orange ball to select, then you can move it around by clicking the canvas).

This is what I want to do, but with more balls. How would you solve this?

Help appreciated.

I'm playing around with making a puzzle game, haven't done that much before I run into my first problem.

Basically, I want to create a certain amount of the same object/function. But without hardcoding the different instances.

I think maybe an array is a good idea? and then a for loop to push the objects in?

And then I need to be able to select one of these objects by clicking on it, how would I do that?

How do I know which ball in the array was clicked? A loop again?

I made a jsFiddle example (you need to click the orange ball to select, then you can move it around by clicking the canvas).

This is what I want to do, but with more balls. How would you solve this?

Help appreciated.

I'm playing around with making a puzzle game, haven't done that much before I run into my first problem.

Basically, I want to create a certain amount of the same object/function. But without hardcoding the different instances.

I think maybe an array is a good idea? and then a for loop to push the objects in?

And then I need to be able to select one of these objects by clicking on it, how would I do that?

How do I know which ball in the array was clicked? A loop again?

I made a jsFiddle example (you need to click the orange ball to select, then you can move it around by clicking the canvas).

This is what I want to do, but with more balls. How would you solve this?

Help appreciated.

Source Link

Creating several instances of the same object, and selecting only one

I'm playing around with making a puzzle game, haven't done that much before I run into my first problem.

Basically, I want to create a certain amount of the same object/function. But without hardcoding the different instances.

I think maybe an array is a good idea? and then a for loop to push the objects in?

And then I need to be able to select one of these objects by clicking on it, how would I do that?

How do I know which ball in the array was clicked? A loop again?

I made a jsFiddle example (you need to click the orange ball to select, then you can move it around by clicking the canvas).

This is what I want to do, but with more balls. How would you solve this?

Help appreciated.