Jump to content
Search Community

How to Tween array of Random Objects across stage as a timer.

Fitchett Developments test
Moderator Tag

Recommended Posts

Hey everyone so maybe you can help I have created a game using Flash CS6 and Flash Develop. I have objects that are added to the stage by a timer Event named "_Obstacles". These _Obstacles are all added Randomly to the stage. Now they get pushed onto the stage like so:

 

private function addObstacle(e:TimerEvent):void
        {
             _Obstacles = new mcObstacles();
             stage.addChild(_Obstacles);
             aObstacleArray.push(_Obstacles);
             trace(aObstacleArray.length);
             //TweenLite.to(_Obstacles, 2.7, {x: - 300});
        }

 

In my _obstacle class I removed this:

 

if (sDirection == "R")
            {
                //Move obstacle left
                this.x -= nSpeed;
            }

 

and added the line as shown above to my Main Engine class instead but its still be controlled by the timer:  TweenLite.to(_Obstacles, 2.7, {x: - 300});

 

Now this works fine and they move across the stage correctly. But I am still experiencing major lag. I dont understand why. So I was thinking maybe it could be the TIMER_EVENT that is causing the lag and if i figure out how to push out the random array of objects every 2.7 seconds and remove the TIMER_EVENT someo how it will stop the lag.

 

My game is simple and i dont understand why its lagging this is the only thing i can think of. Its a basic player jumping over the obstacles added to the stage by the timer. So I'm sure that the timer is the corporate. Please help.

Link to comment
Share on other sites

Sorry, based on the information provided I'm really not sure what to advise.

When you say you are getting lag, do you mean the game is running slow? or are the tweens not starting when they should?

 

There could be many factors at play:

 

  • The rate at which new obstacles are created (frequency of timer event)
  • the amount of obstacles that are on stage at once
  • the physical size of the obstacles
  • transparency of obstacles
  • frame-rate of your game
  • other code in your app causing extra stress.

The TweenLite code you have is very simple and from your description it seems to be working as expected. My guess is there is something else in your code that is either interfering or causing an inordinate amount of CPU stress, as you suggested most likely caused by the frequency of the Timer event. 

 

Unfortunately we have to keep our support focused on matters relating to the GSAP API and can't do a whole lot to troubleshoot problems in your game. 

 

If you need a new obstacle to be created every 2.7 seconds, have you tried using a Timer with a 2700 millisecond delay? http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html#includeExamplesSummary

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...