RipX:
I don't wanna spam this thread up 'cause it's one of the few really good ones at the moment IMHO, but it's a new game ( ColourWorld is long dead ).
It scrolls and it blasts and I'll post an alpha as soon as possible. The very few people who have seen it so far like it, and they are all people whose views I really value, so I'm quite pleased at the moment.
It's my attempt at a AAA game and is far and away the biggest thing I've attempted in Flash.
--- End spam ( And hype ) ---
jtnw:
Prototypes don't have to be for code that is used a lot, you could quite easily write any game you could think of in Flash and never use a prototype. It's just a structured way to increase an objects functions.
Functions don't have to be used locally, you just use them for code that may be repeated in a game. The concept of functions is that you write them generically so they can take arguments and can be re-used.
For example, take a function that does all the collision detection for all the baddies in your game. It can take any baddies x/y position and perform a test and give you back the result. Then later on during development you have this killer idea but it means you need to pass the animation frame to the collision function. 'Cause it's in a function you only have to alter that and all the baddies will use the same code, rather than updating each instance of the collision code by hand.
Performance wise calling a function is actually slower, but there is a cut off point where optimising will just make your code un-readable ( I can't stand seeing code with one letter var names, it's just so easy to screw things up and when you look at that code in a months time it's going to take you twice as long to understand it ).
Also another beauty of using functions is that once it works you can re-use it in every other project you do.
The easiest way to describe prototypes, in the movieclip sense, is that all of the current functions in a movieclip (stop() lineTo() etc.) are all prototypes, each movieclip has access to these functions.. lets say we define a function
Woohoo!
Here's another tip most of you may probably already know:
when making a tilebased game, the same actions with very few differences apply whenever the character moves. So instead of having an on(enterframe) event or putting the same code for every keypress, just make a function with the code and call it on a keypress. Cuts down on the code and makes the game faster, too.
I wish I know as much as all of you do. My game could without doubt be xx% faster. Most of the code I'm using are so clumsy.
In one of my badguy MCs I have on the first keyframe this code which loops till it hits the "guy" (the hero), when guys is hitted it goes to the labeled frame "random"
keyframe 1 that loops:
Code:
if (_root.guy.hitTest(this)) {
gotoAndPlay ("random");
code on the random labeled frame:
Code:
f = [78, 112, 134, 172];
r = random(4);
frame=f[r];
gotoAndPlay(frame);
78=highkick, 112=highpunch....... (yeah I know, why dont I use labels instead of numbers??... donno )
I have a little problem which I have solved but I think it can be made much shorter. You see all the keyframes in a row marked green...[attached picture).. All of them are the same, they are just copied. The code on one of them are: (the same for all of them)
Code:
if (_root.guy.highkick.highkick.hitTest(this)) {
this.scores.gotoAndPlay("score100");
scores._xscale=this._xscale;
_root.panel.score += 100;
gotoAndPlay ("death4");
} else if (_root.guy.lowkick.lowkick.hitTest(this)) {
this.scores.gotoAndPlay("score100");
scores._xscale=this._xscale;
_root.panel.score += 100;
gotoAndPlay ("death3");
} else if (_root.guy.punch.punch.hitTest(this)) {
this.scores.gotoAndPlay("score200");
scores._xscale=this._xscale;
_root.panel.score += 200;
gotoAndPlay ("death1");
} else if (_root.guy.lowpunch.lowpunch.hitTest(this) and _root.score eq 1000000) {
gotoAndPlay ("nutpunch");
} else if (_root.guy.lowpunch.lowpunch.hitTest(this)) {
_root.panel.score -= 100;
this.scores.gotoAndPlay("score-100");
scores._xscale=this._xscale;
gotoAndPlay ("nutpunch");
} else if (_root.guy.jumpkick.jumpkick.hitTest(this) and _root.bonus eq 12) {
this.scores.gotoAndPlay("score5000");
scores._xscale=this._xscale;
_root.bonusmc.gotoAndPlay(2)
_root.bonus = 0
_root.panel.score += 5000
gotoAndPlay ("death2");
} else if (_root.guy.jumpkick.jumpkick.hitTest(this)) {
this.scores.gotoAndPlay("score300");
scores._xscale=this._xscale;
_root.bonus += 1;
_root.panel.score += 300;
gotoAndPlay ("death2");
} else if (_root.killallenemies=="on") {
gotoAndStop ("kill");
}
I had to put this code on ALL the frames in a row otherwise when guy kicks or punches the badguy, nothing happends.
If anyone of you understand what I mean (I know I don't), please explain how to only use this code once instead of alot of keyframes in a row..
Well, lookin at that, this is where I think OOP may start to come in handy, I don't know OOP at all so what I say may be totally wrong and I don't completly know the benefits but it's good for keeping your code organised. Also using OOP let you plan everything before you start to avoid this spaghetti like structur of code (which I do too)
Object Oriented Programming!! There's loads about this stuff on the message board and i'm trying to learn it myself!! It's basically a way to assign code to objects and build code relative to real life situations / objects but that's about all I know to make constructing your code organised and easy to deal with! lol - Also check out
Well, in all honesty, your code is scruffy as hell (tried not to say that) - Using OOP will help you to organise your code in a more structured and understandable way to avoid the messy layout of your code; using cases may also help you to avoid all that elseif/if bumpf.
How 'bout making a new layer and making a keyframe on the first frame and making the rest of the frames just plain ol' frames?
Then stick the code on the keyframe, DONT use stop(), and it should work fine.
Looks weird . I'll use my long code, it's easier to understand and read . thanks anyway
Yeah, functions are kinda hard to understand at first, but they simplify your life after you get the hang of it. I love them
I dunno if Ed Mack has any tutes on them, but seriously, give them a try.