Creating several instances of the same object, and selecting only one
Posted
by
hustlerinc
on Game Development
See other posts from Game Development
or by hustlerinc
Published on 2012-03-28T13:27:03Z
Indexed on
2012/03/28
17:46 UTC
Read the original article
Hit count: 205
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.
© Game Development or respective owner