I have a very simple prototype of a farmville-style mechanic that hits a wall pretty quickly on the performance side. The user clicks on the canvas to create a small plot of dirt which will wait 5 seconds, turn yellow, wait 5 seconds, and turn green. The problem is that after adding about 14 of the plots, the frame-rate will just plummet and the game becomes unplayable.

The brown, yellow and green plots are each a separate object. The brown and yellow objects each have a timer, the green does not. When a timer is triggered, the next object is spawned and the previous object destroys itself (brown spawns yellow, yellow spawns green, green has no timer - spawns nothing).

Yes, I was about to say this.. Your "Green" tile is doubling each time in the debugger and causing the slowdown.

@jggiles

Why don't you spawn once each time("brown") when you first plot your grass and then change the animation over time aka ("yellow" then green") This should save memory too instead of just constantly spawning objects. KazaaMafia2013-11-06 17:30:24

Actually, I don't entirely understand why this is happening. My event sheet seems to plainly instruct the engine to spawn the green object, then destroy the yellow object (and I assume the yellow object timer by estension). Why, then, is it spawning hundreds of green objects on top of each other?

I'll probably take KazaaMafia's advice, but I'd still like to understand what is going wrong here.

I figured out one reason for the crazyness - I accidentally created two "brown_ghost" objects at the game start. because this is the location of the very first spawn point for a new object, the fact that there were two meant everything after was double spawning.

That alone doesn't explain the exponential increase, but it doesn't matter because the method suggested by @KazaaMafia is infinitely less cpu / memory intensive.