side-scroling shooter (help MEEE!!!)

41 posts

Flag Post

Hi, i am making a side scrolling shooter and i was wondering how i could do some things:

1.how would i do the “side-scrolling”; making asingle strip i think would cause slowdowns, so i need an alternative…

2. how do you cause guns to aim and shoot at you(like on streamline), but i dont need an aming gun, just a bullit to come my direction but not follow me…

 
Flag Post

There are about a hundred ways to handle sidescrolling, but honestly, unless your level was just tremendous, simply having the whole thing scroll together wouldn’t kill it. Another option is to have the level split up into chunks that set _visible to true or false based on whether or not they’re on the screen. Keep in mind that _alpha=0 is not the same as _visible=false, even though they look the same. Setting _visible to false is more efficient. And always make good use of cacheAsBitmap, because it will save your life and cure cancer. Okay fine, maybe not cancer, but it’ll probably cure something. Like itchy eyes or something.

Getting things to point at other things is just some pretty basic trig. Get used to trig, because you’ll use it a lot. And I mean like all over the place.

You can look up tutorials for trig in Flash really easily. Make sure you understand cacheAsBitmap before you start stamping it all over the place, because you’ll really sod up performance if you don’t know what you’re doing.

 
Flag Post

Thank you

 
Flag Post

ok now i got another prob…how do i have a movie clip check what frame its on?

ill i figured out was…

onClipEvent (enterFrame) {
	if (Key.isDown(Key.SPACE) && this.frame = 1) {
		this.play;
	} else {
		this.stop;
	}
}

im having trouble with the

&& this.frame = 1

yes i am an ameure programer

 
Flag Post

this._currentframe will tell you what frame it’s on. Good luck!

 
Flag Post

ok so i got that but it wont work

onClipEvent (load) {
	if (Key.isDown(Key.SPACE) && this._currentframe == 1) {
		this.play
	}
}

all im trying to do is make it that if i press space and this(cannon) is at frame 1 it will play(shoot)

i know its a wierd way to shoot but i want to try it

 
Flag Post

I’m still learning AS too, but try putting it under onClipEvent (enterFrame) instead of onClipEvent (load) or something like that. So what exactly does cacheAsBitmap do?

 
Flag Post

it makes it so vectors are treated as bitmaps

 
Flag Post

onClipEvents are long past outdated. At some point you should learn the other ways to handle events, ie

onClipEvent (enterFrame ){}

becomes

MovieClip.onEnterFrame = function(){}

etc..

 
Flag Post

What? Says who? They do the same thing and they perform at the same speed, as far as I know. Maybe this is something that I missed, but I’ve never heard of clip events being a problem, except when people use like 50 different ones.

 
Flag Post

They are horrible coding practice and create unnecessary limitations/difficulties in developments. They were replaced a long time ago, with the culmination of being completely removed in AS3 for the newer, preferred event model. Theres absolutely no reason to use them, and you will only be making your life harder. Its a practice that is usually followed by newer coders who haven’t learned better practices.

In general, you want to avoid attaching code to objects as much as possible. Its one of the basics you learn when it comes to best practice. Most advanced developers dont even dream of using them.

For reference, here is a quote from Adobes best practices article for Flash. This article has a lot of good tips, even though its a bit outdated in some areas:

Attaching Code to Objects

You must avoid attaching ActionScript code to objects (such as button or movie clip instances) in a FLA file, even in simple or prototype applications. Attaching code to an object means that you select a movie clip, component, or button instance, open the ActionScript editor (the Actions panel or Script window), and add ActionScript code by using the on() or onClipEvent() handler functions.

This practice is strongly discouraged for the following reasons:

* ActionScript code that is attached to objects is difficult to locate, and the FLA files are difficult to edit.
* ActionScript code that is attached to objects is difficult to debug.
* ActionScript code that is written on a timeline or in classes is more elegant and easier to build upon.
* ActionScript code that is attached to objects encourages poor coding style.
* ActionScript code that is attached to objects forces students and readers to learn additional syntax as well as different coding styles that are often poor and limited.
* Users typically have to relearn how to write functions and so on, on a timeline at a later date.

Some Flash users might say it is easier to learn ActionScript by attaching code to an object. Some also say it might be easier to add simple code, or write about or teach ActionScript this way. However, the contrast between two styles of coding (code placed on objects, and frame scripts) can be confusing to developers who are learning ActionScript and should be avoided. Also, users who learn how to write code attached to objects often have to relearn how to place the equivalent code as a frame script at a later date. This is why consistency throughout the learning process, by learning how to write frame scripts, has advantages.


Also, straight from the Flash help file for onClipEvents:


NOTE
Attaching onClipEvent() and on() handlers is not a recommended practice. Instead, you should put your code in frame scripts or in a class file, as demonstrated throughout this manual. For more information, see About ActionScript and events and Attaching code to objects.


http://livedocs.adobe.com/flash/9.0/main/00000841.html

Thats covers only some of the painful reasons why you wouldnt want to avoid this outdated system. Its ok for beginners, but anyone who wants to advance should shy away from the practice immediately.

So to answer your question: the most experienced developers and Adobe themselves say so. Hope that helps.

 
Flag Post

As a part time freelancer I will say there is nothing more frustrating and annoying then hunting around in a FLA for “hidden code”. I’ll spend an hour just finding some snippet of code that is buried 3 symbols deep hidden behind some other object.

Please for your sake (months down the road) and for anyone else that looks at your code put everything on the timeline or preferably an external main.as file that is #include “main.as” on frame 1 of the timeline. Once you are that point it is not far to make the next leap into class based coding which is way that all games (in my opinion) should be made.

 
Flag Post

Well, see, this goes right back to my opinions on AS3. Flash is good at things and bad at things. It’s bad at performance, but it’s good at being an exceptionally fast dev environment. Java, on the other hand, is much better for performance (though still not the best), but it takes a lot longer to dev for due to it’s basis on OOP. Now that AS3 is based entirely on OOP, it’s slow to develop AND slow in performance. Adobe and Macromedia made a pretty bad move in that decision. The basis behind it is that OOP is better for organization in very large projects. Flash is not a place to write very large projects. OOP doesn’t benefit a Flash user in any noticeable way (and I’m sure some bigot will flame me down for saying that) because the average Flash project is small.

All the reasons given by Adobe to not use clip events are things like “This is bad form because we say so” and “This is more elegant.” I use clip events for projects like Stranded 2, which is now up to 2 or 3 thousand lines of code (keep in mind that if this were all OOP, it would be much, much longer). I have not yet had a single problem with having a hard time finding something.

Don’t let people tell you that using a system that is old is wrong just because it’s old, especially if their reasoning is that newer versions are more elegant. If it’s actually faster in performance, then sure, go for it.

Oh, one more thing. Someone’s going to want to spit out a bunch of numbers to show how AS3 is so much faster in performance than AS2 and AS1. This isn’t AS3-it’s just Flash Player 9. It’s more optimized and runs faster. OOP is actually slower in performance AND development than “oldschool” code, and it only caught on how it has because of all the people who like how “elegant” it is. Yes, it can help to organize very, very large projects. But people overuse it to the point where it doesn’t help them any more.

QED.

 
Flag Post

I disagree. If you know what you are doing, OOP is a life saver. I’ve been using Flash since version 3, so I’ve pretty much done it all. If you use it as its intended, with code libraries and such…you save massive amounts of coding and can develop and debug much faster. I personally use a class framework for all of my games, and it saves me great amounts of time. If you arent very good at it, or dont know how to use it to its potential…sure, it will take you longer or be harder.

Somehow I think that if you knew how to use OOP properly, your opinion would be different. I know of no one who’s actually learned how to use it well that has gone back to the old methods. If you have been using OOP for years and know it inside and out, you’d be the first I’ve heard of who reverted. There’s a reason all the top developers use it and look harshly upon those who dont. If you went to a flash conference and gave a session with the above comments, you either get laughed off stage, people would walk out, or they would become irate about wasting their money.

If your project is tiny and you dont wish to expand it or hone your developing skills…sure, skip the class programming. Still, even with classes its pretty terrible practice to put your code on objects.

 
Flag Post

um….my question says hi and it wants to answered

 
Flag Post

You need “play()”, not just “play” for it to work. It’s a function so it needs the parentheses.

And arcane, I’m not talking about OO code being bad. I’m talking about how it’s not useful for a Flash programmer. Making a massive project in Java or C++ would benefit from the extra organization that OOP supplies. Flash just doesn’t need it.

 
Flag Post

Thats not true in the least. It is extremely useful for a flash coder. You may not have found it useful, but the majority of the pros do. Amateurs may be able to avoid it, I’ll say that; but when you get into advanced coding, its just silly to not know how to make use of versatile libraries and subclassing. I use it extensively, so I know that first hand pros and cons of all the practices. I would never go back to not using it, unless it was a quick, sloppy job that I didnt care about.

Regardless, OOP doesnt necessarily have everything to do with onClipEvents. The discussion wasnt about OOP, but about how putting your code on clips is bad practice. You can code your game without OOP if you like; and thats fine; but it is not a wise thing in the least to stick onClipEvent(enterFrame) all over your objects instead of using MovieClip.onEnterFrame (or other methods). I used onClipEvents heavily when they came out, right up till they were replaced. There is just no contest vs the newer, more versatile event systems. You are really only creating more work, and contrary to what you think – the performance can actually be worse due to the style of coding they encourage.

Any good programmer would do well to use alternate means.

 
Flag Post

thank you 2D array i got my shooting mechanism almost done ty!

/if i get any more questions theyll be on here

 
Flag Post

If you have the frame stopped with a stop(); on frame one itself, then play(); will just play that one frame again, and stop. If this is the case, use gotoAndPlay(2); then it’ll start on frame two (not one) and play through to the end and stop again on frame 1 (again, assuming that is where you have the stop(); at).

 
Flag Post

No, see, the OOP concept is the same argument. I could make all the same arguments you’ve made in favor of onClipEvent. Neither one is better than the other, which is why it’s a bad idea for you to be putting one of them down. It’s all personal preference. I put code in objects because I know where to find the code I’m looking for. Personally, when everything is in one place, I take longer to find what I want because I have to look through the code for the whole game instead of just the code for the entity I need.

The performance can actually be worse due to the style of coding they encourage.

I’m sorry to say it, but this argument is just ignorant and empty. Basically you’re saying that…if you use a method badly…it won’t work well? Seriously?

Using OOP badly will cause problems. Using onEnterFrame badly will cause problems. Using shoes badly will cause problems, too.

You can’t possibly win this argument, in the same way that I can’t win this argument. It’s like trying to prove that one religion is better than another. And that’s because neither is actually better.

 
Flag Post

Emacs is better than vi… live with it.

But seriously. Best Practices are put into place for a reason. I will say that real world experience has shown me that when best practices are followed, code is MUCH easier to follow. 2D, once you are 5 years down the road and look back at your code you will see that it would have been much better to organize your code differently. However, I will agree that the shelf life of a flash game is usually pretty short. But if you want to have a job programming (in any language or environment) in the future then it would behoove you to at least try out the way it’s “supposed to be.” But… real world experience has also shown me that there are few companies/groups/divisions that follow best practices to a T, and usually they follow their OWN best practices. So in the end you can never truly win.

Oh, and you can find out what religion is better. All you have to do is die, but I suggest you wait to find out if at all possible.

 
Flag Post

I could make all the same arguments you’ve made in favor of onClipEvent.

No you couldnt. The cons of onClipEvents are so blatant that its pains me to even think of explaining them. Its like explaining that fire = hot =bad.

It’s all personal preference.

No its not. Its factual that certain methods are wiser to use than others, ergo the coining of the term ‘best practices’ and the heavy discussion amongst the pros regarding these practices.

I’m sorry to say it, but this argument is just ignorant and empty. Basically you’re saying that…if you use a method badly…it won’t work well? Seriously?

No its not. if you dont understand it, thats due to your inexperience. Spend a few more years experimenting and learning new ways to code, and then you’ll understand what I’m alluding to.

Sorry 2DArray, but I’m actually surprised at you.I have going on a decade of experience in professional level Flash development that I’m basing my opinions on. I’ve been teaching best practices and advanced development at top Flash seminars (and university guest lectures) for years. My point is: I’m not pulling these things out of the air, or saying them because its the only thing I know. To say I’m ignorant on this is hilariously absurd. Everything I say is based on real world experience, not just what I feel or prefer.

It seems likely that you are defending a practice of yours because you have not developed the skill set necessary to make efficient use of the better practices. Thats typically what I’ve seen a lot of people do, until they actually learn the better ways down the road and change their mind on it. If that is the case, it would explain why you would have such a distaste for AS3, because it would alienate someone like yourself who has not been teaching themselves how to be efficient in advanced coding methods. I’ve used all the above mentioned method extensively for years…have you? Heck, I remember using frame loops and the call() function before we had any of this stuff.

If you really are confident about your methods, thats totally fine, use them. But try walking into a seminar filled with the worlds top developers and telling others this. You’d look like a joke. Thats not meant to be insulting, its just seriously the truth. If you dont understand, go to some seminars. Otherwise, if you dont have years of extensive OOP experience and have extensively tested all the methods in Flash, you are just basing your opinion on your feelings from your own coding limitations.

The sad truth is, you are siding with the opinions of amateurs, and you stand alone with them for the most part (for the record I’m not saying you’re an amateur, I enjoy your work). Just dont encourage others to use bad practices. You may like them, but they are without a doubt, bad practices.

 
Flag Post

2D, you are so wrong about OOP not being faster than using outdated onClip events. Obviously, that’s the big reason that Flash CS3 / AS3 is going to run faster than previous versions, because they don’t have to support inefficient code.

If you haven’t moved past putting code on objects, it’s far past time to do it. Honestly I can’t believe you are able to make a game of the complexity of Stranded 2 without using OOP.

You might think OOP is inefficient or hard if you don’t know anything about it. Coder is right about this: Amateurs can get away with not using OOP, but eventually you should learn how to do it that way, because the benefits far outweigh the costs.

The performance can actually be worse due to the style of coding they encourage.
I’m sorry to say it, but this argument is just ignorant and empty. Basically you’re saying that…if you use a method badly…it won’t work well? Seriously?

YES! Actually writing the code so that it performs efficiently is half the battle. Using OOP is the other half. If you were smart you wouldn’t keep all your code in one place anyway, but putting the code on objects is just so much worse. That’s the point of classes: it’s called encapsulation. Look it up. The point is to make it more managable, not less managable.

 
Flag Post

Honestly, this is getting insane. Various things are getting misunderstood here, because, well, that’s the glory of the internet.

First, I’m not saying that you, arcane, are ignorant. I’m saying that trying to make a point with a comment like “Using a method badly will give you bad results!” is a completely empty statement. It’s like telling a runner that he should remember to always breathe, because if he doesn’t, he’ll probably die.

Second, on a similar note, you guys really seem to think that I’m lashing out at you. I’m commenting on how people love to accept the norm as the only way to do things.

Third, OOP is actually slower than “oldschool” code, like I said before. The reason AS3 runs faster than AS2 is because Flash Player 9 is very optimized for it.

The real idea here is that you can’t call someone out because they use a different method than you. I can blather all I want about my laid back style, you can blather all you want about your standardized style. We’re not going to win over each other. I code the way I do because I can make a product quickly that way. You have your own reasons. The end.

 
Flag Post

I’m not trying to say your style is invalid, 2D, and I think your games are cool, but honestly it would be worth your time to at least look into doing it differently. The big reason is if you ever want to move on from being an independent game coder to getting a job… they will all but require you to know OOP. Okay. I said my bit, I’m done.