View Full Version : Trying to animate Objects in a array. All mimic the last Obj created?

08-13-2014, 11:01 PM
I'm new to JavaScript, but not programming in general. Please take a look at the source
And let me know if anyone knows how I should fix this.

The problem is I have created an object, or an array of objects rather. Everything
works great until the bugs turn either right or left. They all do they're own
thing, just like intended, and the animations work for both right and left. But,
All the objects in the array mimic the last object created. So when it turns,
they turn. Regardless of direction. All the objects move bout independently but, the
animation is basically a clone of the last one.

I am using the Image control to do the animations. and when dealing with each object
(Boundry checking, Movement, etc), I reference them from the array one by one.

Does anyone have any ideas what I'm doing wrong? I fear the structure of the application
is all wrong for the endeavor I have chosen, since I'm new to the language. And
I may have gone about dealing with the objects all wrong. I've been trying to
figure this out for 2 days now and I've thought about maybe an array of Image controls
so each bug has his own control for the animation. But then doing it the way I did it
Id need an object for each control... and that totally defeats the purpose of OOP.
Right? I also thought about adding animation methods to the object so each instance
handles its own Flying... but I cant call the controls from the method.

So If anyone can point me in the right direction Id greatly appreciate it.

The script and images are attached.