View Full Version : AS3 Movieclip moving slowly
-Z-
January 15th, 2007, 08:20 PM
I have a game where the FPS are calculated on an On Enter Frame event...
and I have another event that listens for key presses (other for mouse events... but all are disabled...)
And I have game tiles loaded onto a movieclip in the following order...
Flex2Canvas.rawChildren.addChild(map);
map.addChild(thetilecliphere); <- that part is looped alot...at the start to generate the tiles
And then I go and press the down button, and move 'map'... and the game FPS drops from 40 to 10... so i moved the canvas, and it still droped... but nothing moved (strange), and then i went child by child moving them, and it moved again, but still the 10fps...
I tried cacheAsBitmap... and nothing... I would post the code, but with all the stuff inbetween it... it's like 700 lines long.... i'm giving a general over view... Is the problem based on the fact that I'm using the flex canvas to work off of?? Is there any way I can do my own 'canvas' like mc... that falls under the canvas, and before all the GUI? I tried adding children to the canvas and it didn't work.
-Z-
January 15th, 2007, 08:23 PM
Oh and I don't know if this will help but if i lower the map's alpha to 0 it speeds up on most occasions...
to me. that means the math is fine.... :/
I just did another test... where I activated most of my code... and made the alpha 0.. and it lowered to 20fps... which is alot better than 10fps but still strange drop in frames
jjcorreia
January 15th, 2007, 08:30 PM
Well thats a little confusing..
What is the code that executes when you press the down key?
-Z-
January 15th, 2007, 08:59 PM
public function f_key_press(e:KeyboardEvent):void
{
if(e.keyCode == 39)
{
f_map_move(-30,0);
}
}
public function f_map_move(x_change:int, y_change:int):void//moves all the tiles
{
map_clicker.x += x_change;
map_clicker.y += y_change;
v_map_x += x_change;
v_map_y += y_change;
}
map_clicker is inside of canvas... and contains all the tiles
v_map_x is just a variable that i use to calculate tile's relative x position to the stage.
jjcorreia
January 15th, 2007, 09:24 PM
Well thats not a lot of code. It doesnt look like it should be bogging it down, so perhaps it lies in the graphics. Are you moving a lot of clips at once? Can you show us your swf?
-Z-
January 15th, 2007, 10:10 PM
There are 324 tiles in this current refresh, but it varies alot... they are made up of png's with transparencies... and a mask over them (inside the actual individual tile)
It actually got slower once when i took out the png's and left it as vector squares... but i can try that again
But still.... 320 tiles isn't much... i've seen people rendering like 8000 polygons with no lag :/ and they used complex trig as well...
jjcorreia
January 15th, 2007, 10:28 PM
It looks like its graphics then. Are they animated? Did you cacheAsBitmap on the main holder clip or just on each individual clips?
-Z-
January 15th, 2007, 10:36 PM
I did cache on both the main and then on each individual... Also I replaced the png's with pure vector art... just little squares and it stillllll is as laggy... if not laggier
-Z-
January 15th, 2007, 10:47 PM
Seems like when I chache the vector art as bitmap it doesn't loose any speed....
Erm.... I just republished the tiles... as png's and kept the holder as cached and it is still fast.... why i havn't a clue, becaues I tried that before at least 2 times...
-Z-
January 16th, 2007, 08:22 AM
So apparantly when I cacheAsBitmap, each individual tile it also seems to help it... with most of my algorithm's working it seems to run around 15-20fps
However I plan on having alot more than just those working which makes me nervous... anyone see anything that needs to be added here??
package tiles
{
import mx.core.MovieClipAsset;
[Embed(source="../images/tiles.swf", symbol="tiles")]
public class map_tiles extends MovieClipAsset
{
public var t_x:int;
public var t_y:int;
public var sortplace:int;
public var nm:uint;
public function map_tiles():void
{
//creates a new map tile
this.cacheAsBitmap = true;
this.gotoAndStop(0);
this.x = 0;
this.y = 0;
this.visible = false;
}
}
}
-Z-
January 16th, 2007, 02:00 PM
I GOT IT!!! finnaly after 2 or so days... I figured it out
Flex and possible Flash itself runs events like everyone knows, move events keyboard events etc... however they take priority over the grafic refresh things....
So Instead of 'moveing' the map when I do something, now I add the change of the moved map into the buffer... and then on each frame, I move the map... that way I can tell it 10 times inbetween each frame refresh that I want it to move, and it'll only move it once... speeding things up... and since people can only see things that change once every frame anyways... it REALLY doesn't make much difference...
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.