PDA

View Full Version : Tile-based scrolling - slowdown



MysticDrow
July 10th, 2008, 02:12 PM
Hello,

I am programing a tile-based RPG game and I want the player's character to stay in the center of the screen while walking, scrolling the screen in the oposite direction instead of moving the char.

I'm an AS3 beginner and I didn't know that it would result in a great slowdown of the game, so first I tried just to move the whole world. Then I read about the scrollRect method but when I used it the speed didn't improve, even using cacheAsBitmap (it works only for a small scrolling area and I don't want my RPG to be gameBoy-sized). I tried some other things like moving each tile with a loop and even blocks of 50 tiles with 1ms intervals (that worked but looked strange). I even tried to copyPixel but I must be doing something wrong because it causes an ever greater slowdown. The problem is that I don't know how to copyPixel into a bitmap without creating a new BitmapData and then a new Bitmap. Right now each tile is a movieclip stopped in the corresponding frame with some properties I use for the pathfinding.

So now I don't know what to do and I need your help. I know there is some GAS scrolling method but I couldn't find how it works. There are some other advanced tricks out there but I don't understand them well, so I hope you could help me.

Any other methods would also be great. Anything that works for a scrolling screen at last, lets say, 600X500.

GrndMasterFlash
July 10th, 2008, 03:39 PM
what sort of event listeners are you using?
enter frame is of coarse very heavy, and so are timer (though i could be wrong i think timer is a little lighter)
anyways here is an article about streamlining code to make it run faster

http://osflash.org/as3_speed_optimizations

also, are you using vectors or bitmaps?
vectors are much lighter to load but require more memory to move on a screen
bitmaps take longer to load but move with ease
instead of cashing as bitmap you might want to think about using real bitmaps for the get go.

also use graphics whenever possible as opposed to movie clips, and just stay away from buttons period.

i guess this doesn't really answer your question but i hope it might help speed up your game a little.

best of luck, game making is a love/hate field, but very rewarding :beer2:

dthought
July 11th, 2008, 12:27 AM
Hang on, you're not displaying the whole world at once are you? eg. several thousand px across in one direction?

MysticDrow
July 11th, 2008, 09:16 AM
GrndMasterFlash, thanks a lot for the optimalizations, they are very important once the game gets complicated.

I tried both, timer and EnterFrame listeners but that made no difference. I don't know how to use other listeners to keep the stage centered, I tried making a call to the center() function in the main class from the character object each time it changes position instead of using the timer but I think it's useless because the character movement function is also called by a timer Listener (I have only one timer running and the objects that need a timer <for now just one character> just reference it). I made also a bitmap (drawn at the start of the game) and scrolled it but it's just the same.

I am using bitmaps, not vectors. I tried drawing the tiles with simple code, just to be sure - I mean with the drawRect function and the difference was little if any. A special function counts the character's steps per second. When the map doesn't move it is 7-8 and that's what I want it to be. When I just move the screen by changing it's x and y it lowers to 4-5 (with a scrolling area of just 220X220). ScrollRect is a little bit faster (5-6 steps per sec) but still no good - when I set the rect size to 300X300 it lowers. If i had't cacheAsBitmap it would be even worse (2-3 steps per sec).

I also noticed that even when I don't scroll the game but move the flash player window with the mouse instead the speed also drops dramatically, which doesn't hapen eg. with a playing winamp movie. I know they say flash is slow, but it can't be THAT slow, there must be an answer to this problem. Mabe if I knew how to copyPixel properly... If you could explain how to use the copyPixel method to update the map I would be grateful.

Dthought, I am now using the scrollRect, as far as I know it doesn't move everything but only a selected area - quite like a mask. Even when I scroll the whole world it's not so much because that "world" isn't big (about 1000X600). I am not yet removing the tiles that are out of the screen. Any Ideas?

__EDIT:__

I think I finally understood how to use copyPixel (with the lock/unlock and all). I tried copying tile by tile and also the whole visible area at once but it's still too slow. Just the same as scrollRect. I'm kind of defeated by this stupid problem and I'll have to go on without scrolling TT_TT