I am adding things to an arkanoid-like game I did years ago in AS2.
In the original there were keyboard controls only, now I’m adding mouse control.
The mouse control apparently makes the frame rate fall. When I move the mouse and the related paddle, the game lags. I just don’t understand why…and the code is very simple.
mousecontrol = function() {
onMouseMove = function() {plat2._X = _xmouse}
}
I have isolated this as the cause of slowdown. The keyboard controls aren’t responsible. This line of code makes it so the game slows down WHEN I MOVE THE MOUSE. It just doesn’t keep the target 60 fps as long as there’s that line of code, and I move the mouse (everything is smooth if the mouse is still).
Maybe there’s a less expensive way to do the same? But I can’t believe that alone doesn’t allow me to do a 60 fps game. All graphics are bitmaps and even if I put low quality, the mouse move makes it slow down. Incredible.
Any help is appreciated.
You could always try:
onEnterFrame = function(){
thing._x = _xmouse
}
Is there anything under the mouse or the moving item that would be expensive to redraw?
EnterFrame changes nothing. I have tried with everything barebones, just normal png graphics of small size; the mouse move causes the slow down.
But the slowdown is noticeable only in the stand alone flash player (which is updated to the last version). I’m on Mac. I plan to release the game as a standalone Mac app so it’s important that it’s smooth over there…
performance inside of Flash and in browser is good, I mean the slowdown because of mouse movement is probably still there but it just isn’t noticeable in the browser. Only in the standalone flash player.
Ah, that’s a crucial thing to specify.
You could try using Scout if you have access to that product. It won’t do a detailed script breakdown like it can for AS3, but I believe it still gives insight into frame rendering issues.
I vaguely recall Adobe making decisions that would sacrifice the performance of older (AS1/2) content in favor of newer stuff, but I forget if that was just hypothetical or if it actually happened.
What happens if you only update plat2
’s position every once-and-a-while? Like using setInterval
to call the same function at 15 or 7 frames per second?
What happens if you move plat2
onEnterFrame
, but not tied to the mouse position? Like, just move it 2px every frame?
Haven’t tried that exactly yet, but if I move plat2 using the keyboard, no slowdowns. It seems to be something about Flash’s mouse API.
I am not an expert programmer. I have just done a test with Stencyl, a 2D game engine which uses AS3. Even there, if I set the position of a sprite to follow the mouse, it still suffers a slowdown, just less extreme - this just for setting the position to mouse. Slowdown as I move the mouse. Still Flash Standalone player, this time AS 3.0.
only that in the case of my AS2 project, it is extreme enough to make the game not fun. In Stencyl is negligible.
But…I will try Scout. I am afraid there’s no solution, that it’s just something inherent in Flash, but I’m curious.
As I expected, this happens on the Mac version of the standalone player only. On PC it is very fast!
I remember that the Mac version of the standalone player was much slower than in Windows. And if I remember right sometimes the browser plugin would show itself as slower on Macs too. I remember that from circa 2005, I thought they would have fixed it since!
I guess I won’t do the Mac version of this small game after all. It’s still interesting, because this is definitely a bottleneck that I wouldn’t have noticed otherwise. And that I entirely didn’t expect. But again, I am no programmer.
I’m with you there. This sort of weird platform- and player-type-specific performance bug shows up every once and a while. Like 31fps used to be optimal on Macs for some time frame a long time ago, but it was eventually fixed. That sort of problem is exacerbated now that Flash Player is on life support with a skeleton crew of bug fixers. (And AS1/2 have been on life support since AS3 came around in 2005-2006.)
You could also wait to see if @senocular shows up. He knows a lot more about how rendering and display lists and such work in FP than me. (Can you set WMODE in the standalone player?)
Yes, Flash on Mac was always slower from what I remember. Again, I thought it evolved and this was a thing of the past - after all the games I made in 2005 run much better now on modern machines. But the player…still incredibly slow! Unless you use Stage3D of course.
It’s just a small casual game I’m making so I guess I can make it windowed and not full screen for Macs. It’s not for the App Store anyway obviously, I would distribute it on Desura or something I think. On Windows I can have full screen as I hoped. In browsers it will run fantastic. I was very discouraged until I now found out that on Windows there’s no issue. I also still have to run Scout.
I guess you’re referring to some bug concerning WMODE? I’ll try and let you know. Will I be able to do some sort of fancy frame at least, for the Mac version?
Sorry I got completely confused earlier and you might have asked yourself what the hell I was talking about. I talked about full screen…
When I made the first version of this game the Flash standalone would still slow down in full screen, but this is not the case anymore…the problem I’m having with the mouse event is whether the app is full screen or not. Full screen has nothing to do with it and the “frame” idea I was talking earlier is silly!
The app slows down with that line of code on Mac standalone, full screen or not. I am aware full screen is hardware accelerated now. Not the case in 2005 I think. You couldn’t full screen a Flash app and expect to be happy of the result.
The mouse having an effect on performance is not unheard of. It’s something we’ve looked at before, and I don’t know if anything got addressed or not (and this was a few years ago on top of that). One of the things involving the mouse is, with the more elements you have on screen, the more work there is that has to be done to identify which of those elements needs to get mouse events. Each OS handles this differently, and historically, Mac has received less attention than its Windows counterpart. Additionally, standalone is largely forgotten as most of the focus is put towards the web players. Given the move away from interactive CDs and projectors only made this more so the case.
What you can do to help? First thing, disable your mouse. No one needs them anymore. You can do everything with the keyboard, even on Macs! …almost. I kid, I kid. Really the big thing to do is render offscreen into a BitmapData and simply show the bitmap as the only thing on your display list. This reduces the mouse calcs needed to only one element, and most of the time, especially for games, you don’t need to worry too much about rollover and rollout so much as just mouse position which you can still get.
Like the 31 fps trick, this was something seen more in Mac circles because of the performance gap there, but also something that is common not just in Flash, but other places as well, so its kind of nice to see what its all about first hand.
Other than that I’m not sure what else to do other than keep to google and see if you can dig up any additional information about it. Others struggling with this problem may have identified other solutions too.
Thank you senocular,
I have done my googling first of course and didn’t find much help except finding out that Flash is slow with the mouse in general and of course confirming the Mac standalone is much ignored as you said.
I am googling on the 31 fps issue as it’s the first time I hear about it! Perhaps it will help.
“The big thing to do is render offscreen into a BitmapData and simply show the bitmap as the only thing on your display list.”
Can you give me a small one or two-lines example of this? I only know the bare basics of AS2. Never used BitmapData. I am using a basecode made by another programmer and just adding the mouse control as the keyboard controls he developed sucked. So I really want to implement the mouse…especially with easing (which doesn’t impact performance in any noticeable way), it’s much better for this game.
As we’re speaking of bitmaps, I have noticed another thing having impact here is the number of bitmap blocks I have on screen (it’s a brick-breaker game). Maybe this BitmapData trick you’re speaking of can help there too? How do I lower the performance impact when I have hundreds of (absolutely static) bricks movieclips on the stage? When I have fewer bricks, performance improves; would be nice to have the same when I have more.
Hmm. Well BitmapData is in AS2 - added in Flash 8 if I remember right - but I think the trick I’m thinking of only works for AS3, not so much AS2 since you can’t do things offlist in AS2 (and I forgot we were talking about AS2 by the time I got to the end of reading the thread). In other words in AS3 you can have movie clips exist in code only, and aren’t on the screen, and from those movie clips you can render them into a bitmap that is the only thing on screen. In AS2 if you create a bitmap, its always on screen.
So then, given that you said you’re using a bunch of bitmaps, maybe the solution would be to manually render your entire game in a bitmap instead of using Flash’s display list. That would probably require you to rewrite your game though
Anyway, there’s not much to do about more-bitmaps=slower-performance. That’s just the way it is. The more you do, the harder the computer has to work to do it.
There are some optimizations you can do for bitmaps, such as not rotating or scaling them. There are fast paths for bitmap rendering if they’re not transformed (…I assume they are applied to AS2 too; I know there are some specific things that are needed in AS3 that might not translate to AS3). And really, AS2 was known to be slow which was the whole reason AS3 was made, to be performant. And with that, and the age of optimizations for flash, most attention was given to AS3 leaving AS2 to be forgotten. AS2 is kind of like Macs in that respect.
So really, you’re in the worst position possible! AS2! Mac! Standalone player! Includes a mouse!
2 Likes