|
-
[RESOLVED] [AS3] Moving large backgrounds around in a flash game
I'm making a game right now which moves a battlefield around as you pilot your plane.
http://prosata.com/test/Mi/Mi.swf
Controls
-------------------------
Move Forward- Up Arrow
Turn Right- Right Arrow
Turn Left- Left Arrow
Fire Bullet- Ctrl
------------------------
The Problem:
The battlefield is resized according to your browser's dimensions. I know that by making the battlefield large it causes the player to lag more.
I was just wondering which is the best way to create a constantly moving large background?
Currently I'm using one large Sprite Object now and moving it around. It seems to be the quickest method so far, but still sluggish.
I tried using a BitmapData object and then using the fillRect method, but this was even slower.
Any advice would be greatly appreciated
-
If it's going to be really big, I would try splitting the background up into tiles which you can occlude when not in view. From my own tests, though, I have found that less than a certain size, moving a single sprite is faster than moving tiles covering the same area. I think once you get really big, though, a tile method will be faster. My tests involved an area of 2048x1024, which I tried splitting into a 16x8 array of tiles and hiding tiles out of the viewable area. As I said, I ended up just using a single sprite.
-
Script kiddie
I recommend the use of scrollRect. It's very, VERY fast at scrolling big bitmaps, only takes one line of code, easy to set up, and even does you the handy favour of not rendering anything out of the bounds of your chosen mask (I think).
-
Also, if you are using bitmaps, check into the BigAssCanvas class. It allows you to stitch together bitmaps to create a single BigAssCanvas object that can be treated much the same as a single bitmap.
-
Truimagz.com
lol I use that one all the time, though I think there is an F bomb somewhere in the name of my class.
-
Ooops, forgot the link, it is an actual class:
http://www.bit-101.com/blog/?p=1199
-
Thanks for all the advice. I'm currently going to use the copyPixel method to copy the background to by bitmap canvas which I paint everything onto b4 render.
I don't want to use the tile method specifically because it is real real slow when it comes to rendering many child Sprite Objects.
That BigAssCanvas class looks like a nicely made class. I remember I made a class called BigBitmap which basically does the same thing but only has the draw method successfully implemented. It won't help me with my current problem though.
Anyways, has anyone seen a user made class method which copys bitmaps faster than the AS3 Bitmap copyPixel? Maybe some sort of method which copy's a set of pixels faster, but loses quality because of that?
-
Script kiddie
-
I've used scrollRect before, but assumed it was slow. I'll try out some tests, hopefully it's as quick as you say, not with just the moving of the boundaries, but also at rendering.
Thanks!
-
Still didn't solve my problem, don't know if it's solvable since I'm trying to get the game to run smooth in Firefox...
In this version of the game I am using VENGEANCE_MX's advice and using scrollRect on a big bitmap.
Check the game out Here:
http://prosata.com/test/Slokoto/Slokoto.html
Controls:
Arrows-To Move
Ctrl- Bullet
Space- Fire Missile
As you can see the game lags when you start to move, which makes the background move also.
Anyone have any suggestions on how I can make my game run smoother. I have to scroll the background since the screen size is usually small for a flash game, and the battlefield is quite large. Maybe there's a technique I should use instead of scrolling? Maybe some other way of creating this type of game?
Also if anyone knows of any games with similar gameplay can you post them so I can see how they made their game?
As always any comments, help and other stuff would be greatly appreciated
-
Senior Member
Runs ok in Opera. Since Opera and FF use exactly same Flash Player, the low perfomance in FF can be improved by fixing the FF.
-
Script kiddie
Shouldn't be getting that kind of slowdown... have you made sure that the background's cacheAsBitmap property is set to true?
-
I resolved it, thanks for your help vengeance mx! 
Turns out it was just the way I was bounding my bitmap, it created a sort of illusion as if it was lagging. I increased the frameRate and am not always moving changing the bitmaps scrollRect now, only when it needs to change do I change it, for instance, now when the ship is on the side it has a boundary so the background dose not have to move then.
It's smooth enough now.
Last edited by tariqm; 05-03-2008 at 08:07 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|