Announcement

User registrations are currently disabled due to high spam traffic.

#1 31/03/08 6:51am

crimsonhotsun
Hardcore Member
Registered: 30/03/08
Posts: 96

Some kips and teys to making psp flash games

I've seen some promising minds in this forum and some people who know how to make an entertaining game from the simplest of elements. Now, I'm not saying I'm an expert or that I can do anywhere near better, but I've been seeing the same mistakes, simple mistakes, that can make a game that would be fast paced action-style become slow and sweaty. Now I know some people here are beginners, and making games is hard enough without having to watch a few hundred different things, but it's always better to start good habits now then try to break the bad ones later.

Tip #1: Use Bitmaps over Vector graphics

I've never used liveswif so I don't know whether or not they can do this, but importing and using bitmap graphics can cut your fps significantly. When you use the pencil tool or circle tool or pen or whatever, you are drawing vector graphics. If anybody uses bitmap tracing, it's even worse for flash. As everybody knows, the psp has superb graphics capabilities that let it process 3d graphics at extreme frame-rates, but the flash player on the psp is too high-level to take use of it, it's a plugin on a browser that is an application on the psp.

Does this mean never use vector graphics? No, in fact sometimes you must use vectors for certain effects. What I'm saying is stay away from using gradients where possible and more complex shapes. Also make sure to stay away from using Alpha (or transparency) in your graphics, whether vector or bitmap, as this takes a huge tole on CPU.

When using bitmaps, however, you are confronted with more of a hassle:

A) Bitmaps using a huge variety of colors will take more space, this will decrease the amount of memory available on the psp for you to use.
B) Large bitmaps also take a large deal of space but can also slow down the player, taking away any benefits you would make by switching to bitmaps.
C) Pixel shifting was somewhat of a problem in earlier versions of flash, this is where flash cuts off one row and column of pixels in your bitmaps. Generally if you switch to low quality on flash, this problem is eradicated.

Another problem with bitmaps is quality, however with the psp screen being as small as it is, it's harder to notice this sort of thing and it looks better anyway.

If you're still having trouble with the whole bitmap thing, check out TonyPa's Tile Based Game Tutorials. (this is for tile-based games specifically, but combining this idea with bitmaps will make your game way more efficient code-wise)

Tip #2: Variables

This is where beginners may begin to lose it. Making code efficient can mean rewriting the whole thing, so it's best to just try to write things right the first time around.

As code is what causes 50% of the speed loss in most flash games on the psp, it's best to watch yourself in your code efficiency. First of all is making sure that your variables are in the right scope. What the heck does that mean? Hopefully you've read something about global and local variables. Where as any single part of a flash file can use a global variable, only a specific function or instance can use a local one. As you might have guessed, a game using only local variables is a good deal quicker than one using global variables, but as I see it this is nearly impossible. Global variables are generally declared like this:

//Actions on _root
var globalvar:Number = 0;

The var identifier is what does the trick. I'm not too keen on this but I think that even without the 'var' you can use a variable anywhere in code, just refer to parent then variable, as in _root.globalvar in this case.

Now, using local variables all the time is almost possible. That is where, in a function, not just on the root, you would declare a variable with the var key word before it. This can actually make your code slower, however, as flash needs to create and destroy variables each time you call the function. What to do then? I have gotten in to the bad habit of recycling variables, which is actually proving quite efficient, though. Simply declare variables on the root and use them as at any other time, not too much of a mess, not so much hassle declaring at the start of every function.

Tip #3: Collision Testing

I had to give this it's own section because it seems to be one of the more major issues. But everybody knows how to do collisions right?

HitTest is easy to use, fits in everywhere, works perfectly, does pretty much what anybody could ask for right? The only issue is that using HitTest is slow. Very slow. On a computer, this isn't much of an issue, but on the psp, this can be the downfall of your game. First of all, let me help you out on collision testing. HitTest is NOT the only way there is. Collision test can be narrowed down to basic checking of whether a point (x-y coordinates) is between a set of points.

The easiest method of this is bounding box collision testing. Take the top left corner of your movie clip, usually mc._x and mc._y. Let's say we want to check if this is in a box. All we have to do is get the box's _x(30), _y(20), _width(10), and _height(60) and check. The statement I would use is:

if(mc._x>30&&mc._x<40&&mc._y>20&&mc._y<80){

which looks like a mouthful at first, but really is just:

if top left corner of mc is between box's left side(box._x, which is 30) and box's right(box._x+it's width(10), which is 40)
and if mc's top left corner is between box's top side(box._y, which is 20) and box's bottom(box._y + height(60), which is 80) then

This is faster than HitTest because HitTest does a function call, where as this does Boolean checking directly in the block of code you run.

Most of the time people want to use HitArea or HitTest to check if two mc's collide. This means that the computer must check each point of each mc to find out if one is touching another(in the case of HitArea). Now don't get me wrong, HitArea is great when used correctly. The only issue is using it correctly.

Now if a box was the only thing you could test, HitTest would be pretty much a necessity in many cases. However, you can do this with a circle as well. Using the distance formula, you can check if a point is a certain distance from the center. This is a basic if-statement for checking this:

if(Math.sqrt(Math.abs(Math.pow(circle._x-mc._x,2)+(circle._y-mc._y,2)))<6){

This is a bit more intensive then checking if a point is between two points, however it can be much more useful. I'm not sure about explaining this one but I think it's pretty much obvious, circle._x and _y are the x and y of the CENTER of a circle, not top left corner, mc is the same as it was before.

Checking whether a point in a triangle is possible, but by the time you finish the calculations for it, you could have done at least 3 HitTests.

Last I have to say on this is that you should split up the screen, don't do collision testing on the top right edge of the screen when your character is on the bottom left, this is stupid and causes unnecessary slow down that can threaten your game's playability.

Tip #4: General code efficiency

Using MovieClip.attachMovie and removeMovieClip is much harder on the cpu than simply moving the clips off the stage when you don't need them. You shouldn't be using that many movie clips anyway, I mean it is the psp.

The other main point in code efficiency is splitting the pieces. You don't want to force the psp to play three different animations, 2 sound clips and the background music, and try to read code from five code blocks. Instead, split your code into only two blocks if you can, on the _root and one for reading keypresses and processing the movie, do animation seperately and don't use code to do it, and let sound run as it is. The key is using what macromedia has given you. if you don't have to gotoAndStop() on each frame, why do that? If you can check button presses from _root instead of on each button simultaneously, why not do that?

You also want to avoid unnecessary function calls. This can fall a normally efficient piece of code. For example, take my piece of collision testing code. It is actually faster than hitTest (though much more of a bother), and does, as far as I can tell, the same thing. Stick this in a function and call it and it ends up taking much longer to call.

Here's another point I found out the hard way- loops should generally be avoided. Using while loops is slower than actually putting the piece of code down however many times. I realize that in cases where you need to do a ridiculous number of loops, this looks awkward and messes up your code, but you can still avoid too much slowdown, for example, by cutting down the number of loops and having each loop execute the same code twice. Also, avoid for() loops entirely. My personal speed tests (but don't take it from me) show that while loops are faster than for loops. Just don't forget to increment the iterator (i++wink at the end of your loop. A nickel for every time....

Tip #5: Making the most out of your memory

I'm not sure most people understand the whole memory thing. I'll explain: The PSP web browser lets you use a small 2 megabytes of it's 32 megabytes of RAM (some people say 64). This doesn't mean it can't play a 2MB flash file, though it seldom can, but that it has that much memory. I can make a 2KB flash file that will require 4 MB of memory, or a 500KB file that requires only 1MB. What memory is is the space for all the data being stored for processing. This means variables, arrays, graphics, sound, functions, animations, etc., anything the flash app needs to store.

So how do you manage it? Make small arrays for starters. Exactly how big I don't know, but if you are even using a 3 dimensional array, I can almost guarantee it's too big. The issue with bitmap graphics is that they can take a decent amount more memory than vectors. Large bitmaps will, as I said before, be your downfall in more ways than one. Using bitmaps is best in tile-based arrangements, which is why I included that link way up there. This is also another reason you would want to make variables local, is that they take up less memory that way. I would go on here but I'm getting tired and I'm sure you can connect the dots.

Tip #6: Getting the most out of input

The input you are allowed on the psp is not great.

A) You have only the d-pad, analog stick, and x button to work with.

B) After firmware 3.5, you cannot take input from more than one direction button at once.

C) This gives you only one button for button pressing.

D) Pressing the L-Button once ends your game.

This may sound daunting but where there's a will there's a way. The analog stick and x button are your mouse, and although it's not as worthwhile as a computer mouse, you can still get somewhere with it. This gives you more than one button for pressing, technically. You can extend this also, however, by using a combination of keys, for example you can use the x button and arrow keys for attacks, arrow keys to move, analog stick to find a menu and x button again to select it.

The arrow keys are these codes:

LEFT: 37
UP: 38
RIGHT: 39
DOWN: 40

And these are used like this:

If(Key.isDown(37)){ //check if Left on the d-pad is pressed

Using UP for jump and X for fire is a good tactic, if you are inclined to make a platformer.



Credits:

PSP Flash Gaming for these forums and the arrow keys

Jeff Nusz On Making games for the PSP
This article was gold, and I got most of my info from here, you'd best check it out.

And last but not least, Sony and Adobe for their cooperation in bringing us this half-baked excuse for a flash player. I know I shouldn't be complaining but they could have done a bit better... right?

And if you've read down to here thanks, if you understood all of it thanks very much, enjoy making games for the psp!

Last edited by crimsonhotsun (10/07/08 3:39am)


[img]http://img101.imageshack.us/img101/9094/20707804nc6.png[/img]

My humble forums: [url=http://hologram.zxq.net/forums/]VirtualWorldForums[/url]

Offline

 

#2 31/03/08 2:04pm

JaXeRiR
Elite Moderator
From: Teh Interwebz
Registered: 25/03/07
Posts: 1925
Website

Re: Some kips and teys to making psp flash games

Thank you.

I am not a Flash developer, but I know many of here are. Thank you for your time and effort.

And welcome to the forum!


[url=http://profile.mygamercard.net/JaX3RiR][img]http://card.mygamercard.net/nxe/JaX3RiR.png[/img][/url]

Offline

 

#3 31/03/08 2:32pm

Dezerith
Moderator of Doom.
Registered: 27/07/07
Posts: 196
Website

Re: Some kips and teys to making psp flash games

Thanks, I didn't quite read it all but what I did read was very helpful.

Welcome to the forum.


[img]http://i26.tinypic.com/28iys08.jpg[/img]
[img]http://www.resiststorage.org/images/blazebytedev53.png[/img]
[img]http://www.resiststorage.org/images/PSPflashForDezBzeByteDev4.png[/img]

Offline

 

#4 31/03/08 8:39pm

nothing
Moderator
Registered: 21/03/08
Posts: 389

Re: Some kips and teys to making psp flash games

Thanks, I'll keep that stuff in mind! Welcome to the forums!


[url=http://pspflashgaming.com/forum/viewtopic.php?id=1078]BioShock[/url] PSP|fPS-Factor Released|[url=http://www.p22server.hostwq.net/index.html]p22 Center[/url]

I'm starting p22 again.

Offline

 

#5 31/03/08 11:17pm

69corvette
That one guy.
From: Not Palmdale, CA
Registered: 01/02/08
Posts: 280

Re: Some kips and teys to making psp flash games

Hey, I'm glad someone finally took the time to compile an article like this, i've meaning to do this since most of this info is found scattered throughout this forum. good job.


[img]http://img221.imageshack.us/img221/8990/smallersigcopylb1.jpg[/img]

Offline

 

#6 01/04/08 2:27am

crimsonhotsun
Hardcore Member
Registered: 30/03/08
Posts: 96

Re: Some kips and teys to making psp flash games

Thanks for all the replies and welcomes, it's nice to join a forum that really fits my interest.


[img]http://img101.imageshack.us/img101/9094/20707804nc6.png[/img]

My humble forums: [url=http://hologram.zxq.net/forums/]VirtualWorldForums[/url]

Offline

 

#7 21/05/08 2:42pm

JaXeRiR
Elite Moderator
From: Teh Interwebz
Registered: 25/03/07
Posts: 1925
Website

Re: Some kips and teys to making psp flash games

I have stickied the thread, as it contains information that many PSP flash developers might appreciate.


[url=http://profile.mygamercard.net/JaX3RiR][img]http://card.mygamercard.net/nxe/JaX3RiR.png[/img][/url]

Offline

 

#8 21/05/08 7:26pm

Zuriki
Flash Dev (The Lazy One)
From: Manchester
Registered: 18/01/08
Posts: 755
Website

Re: Some kips and teys to making psp flash games

Thats a good list of tips you have there, also welcome to PFG.

Outlines flaws and work arounds.

You said:
if(mc._x>box._x&&mc._x<box._x+box._width&&mc._y>box._y&&mc._y<box._y+box._height)

Which uses 2 movieclips right mc and box.

Why not just set it like:
if(mc._x>470){///}
and
if(mc._x<10){///}
and
if(mc._y>262){///}
and
if(mc._y<10){///}

That is less intesive that your code which requires it to check the details of the movieclip as well as checking the details of the box.

Mine just checks the x and y values of the movieclip.

Except you have to manually accommodate for that by setting the bounding box using XY-Co's.

Just a pointer. I haven't much time, I managed to read it all, but I haven't got much time left right now so I am gonig to cut short, bye.


[img]http://img134.imageshack.us/img134/9129/headerxt2.png[/img]
[url=http://zuriki.co.nr/project/traveller/][img]http://i28.tinypic.com/2vspafo.png[/img][/url]
[url=http://zuriki.co.nr]Zuriki - PSP Flash Games[/url]

Offline

 

#9 22/05/08 5:28am

crimsonhotsun
Hardcore Member
Registered: 30/03/08
Posts: 96

Re: Some kips and teys to making psp flash games

Thanks Jaxerir.

And thanks for your comment Zuriki, but do you mean I should put nested loops instead of one giant statement? I realize this thing is a little cluttered, as I sort of zoomed through it one night.

If you compost those four statements you put you get:

if(mc._x>470&&mc._x<10&&mc._y>262&&mc._y<10){

or do you mean

if(mc._x>470){
   if(mc._x<10){
      if(mc._y>262){
         if(mc._y<10){

or maybe you just meant I should write constants down instead of variables.

The problem with doing 470 instead of box._x is inflexibility in coding. I could see why you would do that to save a lot of trouble on the cpu for collision testing, however now you are working with set limits.

If you want to do it that way, I think using an array would probably be more practical in some twisted way, making sure all values are set before the "camera" moves again.

Now if you're using a static screen, I could see your way being a much better choice. As far as side-scrollers are concerned though, you need some kind of flexibility. The statement is rather long though, and a lot of your idea is quite sensible, so I'll change it.

Last edited by crimsonhotsun (22/05/08 5:34am)


[img]http://img101.imageshack.us/img101/9094/20707804nc6.png[/img]

My humble forums: [url=http://hologram.zxq.net/forums/]VirtualWorldForums[/url]

Offline

 

#10 23/05/08 5:52pm

Zuriki
Flash Dev (The Lazy One)
From: Manchester
Registered: 18/01/08
Posts: 755
Website

Re: Some kips and teys to making psp flash games

Well there is little chance of side scollers on PSP Flash games, as they are nearly impossible to play (5FPS at a good one).


[img]http://img134.imageshack.us/img134/9129/headerxt2.png[/img]
[url=http://zuriki.co.nr/project/traveller/][img]http://i28.tinypic.com/2vspafo.png[/img][/url]
[url=http://zuriki.co.nr]Zuriki - PSP Flash Games[/url]

Offline

 

#11 17/11/08 12:38am

danomann
Addict
Registered: 12/08/08
Posts: 210
Website

Re: Some kips and teys to making psp flash games

Good tutoril I started to make games like 1 month ago so im new to this kind of stuff smile


_root.gotoAndDie( [url]www.dako300.co.nr[/url] );

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson