Big performance hit for seemingly simple operation(s)

Nomosoft

  • Posts: 122
I have an actor with a single behavior. That behavior consists of a single command, which rotates the actor X degrees per call. Using either "point toward" or "turn by x," I see a drop of 12-20 fps with fifteen or sixteen of these actors on screen. Disabling the behavior or deactivating the rotation command (which is the only command in the behavior) is the difference between 26ish fps and 42+ fps. The time seems to mostly be lost to "update."

Right now, I am working around this problem by putting the rotation on a timer, but I still feel this is a lot of hit for a single command. Am I missing some trick, here? The actor in question needs to detect collisions, but other than that and the rotation, no physics need be applied.

coleislazy

  • *
  • Posts: 2607
Rotation is a very expensive operations for a few reasons. You're probably on the right track with limiting the number of calls.

Weasel8778

  • Posts: 236
Could the rotation be an animation instead?

Ganu

  • Posts: 224
I think that if you will crate 16 animations in diferent angles you could the add behavior that will calculate turning speed etc mind:blow;
Currently waiting for joints in stencylworks.

Nomosoft

  • Posts: 122
Rotation is a very expensive operations for a few reasons. You're probably on the right track with limiting the number of calls.

Does this have something to do with the physics engine, translating collision boundaries or something? I'm curious why rotation is expensive in Flash. I've never even given it a second thought in any other language.

Could the rotation be an animation instead?

Sure, and I think that might be what I end up doing. I know I can get around the problem, but I hate to just dodge problems without understanding them.

coleislazy

  • *
  • Posts: 2607
Collision bounds would be one aspect. Another is how Flixel renders the screen. Each image is a BitmapData object and Flixel draws everything to a screen buffer each frame. You can't really rotate a BitmapData object, since it is essentially an array of pixels, so you have to apply a Matrix to it to figure out where each pixel should be when rotated. This isn't horrible by itself, but when you get a few of them happening at once, it can cause things to chug.