Be a Supporter!
Response to: Passing parameter to function? AS3 Posted October 25th, 2009 in Game Development

At 10/25/09 07:49 PM, milchreis wrote: why don't youreference the stage directly?

Ok, I played around with the stageRef thing so now it's stageRef= stage. So that solves star, but only because that's all star needed. I have a laser class that I need to setup in a similar way, but it needs the players Ship class to pass it's X and Y coordinates in to laser's init function. So I still need my original question answered, how do I give parameters to a function in another class that's triggered by an event listener?

What I posted up there was just an example, I'm going to have to do this in multiple situations that don't involve stage at all.

Response to: Passing parameter to function? AS3 Posted October 25th, 2009 in Game Development

How do I pass a parameter, any parameter, into a specific function in another class? Would that be like Star.init(parameter)?

Response to: Passing parameter to function? AS3 Posted October 25th, 2009 in Game Development

Its a child of a background movieclip, won't that make it use the background instead of the flash player window? My background rotates and scales so I can't have it use the background as a reference. Unless I'm not understanding something here.


I want to pass the stage as a parameter from my Engine class to an init function in my Star class. I set up an event listener, so it would only perform init after it gets added by the engine, and hopefully not when I put it on the main timeline manually. But it still needs to get stageRef from the Engine. Here's the code for Star class:

public function Star()
{
	addEventListener(Event.ADDED_TO_STAGE, init);
}

public function init(stageRef:Stage): void
{
	this.stageRef= stageRef;
	setupStar(true);

	removeEventListener(Event.ADDED_TO_STAGE, init);
	addEventListener(Event.ENTER_FRAME, loop);
}

And this is where my Engine class starts adding Star to the stage. This was written befor I wrote the init function in star which is why it's trying to pass "stage" directly into Star:

bg.addChildAt(new Star(stage), bg.getChildIndex(Ship));

So the question is, how do I pass stage from engine to Stars init function?

Response to: Market For A Single Player Orpg? Posted October 25th, 2009 in Game Development

I'm not going to say there's no market for a browser run single player rpg, but thr thing is, multiplayer rpgs where you can interact with other real live people who react to situations in unique ways will do much better.

So would you be constantly updating this single player content? Adding new items, maps, enemys, quests, maybe doing limited time themed events? Or is this a game that gets released then nothing ever gets done to it again? That's going to influence wether people will keep coming back and playing to, and probably wether or not it needs its own dedicated webspace.

Just some thoughts.

Response to: In-Game character jitters... help? Posted October 25th, 2009 in Game Development

Fixing a jittering xharacter is easy, no code involved. Just write into the story line that he drinks lots of coffee!

Response to: Better coded leveling system Posted October 23rd, 2009 in Game Development

At 10/23/09 08:28 PM, Toast wrote: It's not about lines of code, it's about having good coding habits... Or in this case, knowledge of how multiplication and addition work.

400+(400*1.2)=880
400+(400*0.2)=480

My number seems more reasonable, unless you want to more than double the hp every level.

Response to: Better coded leveling system Posted October 23rd, 2009 in Game Development

I put on muh robe and dunce cap.

Either way, you get what I'm saying, and it's only 2 more lines of code.

Response to: Better coded leveling system Posted October 23rd, 2009 in Game Development

Maybe you could add a percentage to hpMax, and mpMax every level. Using toasts code:

xpmax = 25;
hpMax=400;
mpMax=300;

 if(xp>xpmax){
 	level ++;
 	xpmax *=2;
	hpMax = (hpMax += (hpMax *= .2))
	mpMax = (mpMax += (mpMax *= .2))
 }

Which would give you 20 percent more hp everytime you level.

Response to: need some help Posted October 23rd, 2009 in Game Development

Where's your hitTest code? What's the problem?

If you're asking how to make a hitTest that would be something like

If(wallInstanceName.hitTest(playerInstan ce)){

doStuff();

}else{

dontDoStuff();

}

Response to: need some help Posted October 23rd, 2009 in Game Development

No.

How about you post what code you got and we'll help you improve it and give you ideas instead.

Response to: Player doesnt respond to gravity Posted October 23rd, 2009 in Game Development

At 10/23/09 05:46 PM, Zer0Reaper wrote: Eesh. Im barely smart enough to grasp simple concepts in as2, let alone as3 :(

AS3 is easy, its like playing with legos, except you're making those legos out of whatever you want. And once you write a bit of code that works, you never have to write it again, you can just call it, and it'll do it's thing. It's all about just learning how to work with the syntax.

Response to: Player doesnt respond to gravity Posted October 23rd, 2009 in Game Development

At 10/23/09 05:19 PM, Zer0Reaper wrote: shoot am I in action script two??! I thought i had as3!

onClipEvent(enterFrame) has been changed to addEventListener(Event.ENTER_FRAME, initfunction, false, 0, true);

Well... kinda. They have a a lot more ways you can handle all sorts of events, its much better.

Response to: Player doesnt respond to gravity Posted October 23rd, 2009 in Game Development

I didn't get very far into AS2 because I felt I better learn AS3 anyway, but here's some code from a platformer I was trying out, maybe it can give you an idea:

onClipEvent(load){
	gravity = 5;
	jump = 15;
	runspeed = 15;

//For hitTest
	onGround:Boolean = false;
}

onClipEvent(enterFrame){

//gravity code
	if(onGround == true){
		_y+=0;
		jump = 15;
	}else{
		_y+= gravity;
		jump--;
	}

//jumping
	if(Key.isDown(Key.UP)){
		_y-= jump;
	}

//hit testing
	If(_root.floor.hitTest(_root.player))
		onGround = true;
		trace("on ground");
	}else{
		onGround = false;
		trace("off ground");
	}

Its not the best code, but maybe you'll find something useful.

Response to: Whats a "caller?" add/remove Child Posted October 23rd, 2009 in Game Development

Ok, I think I'm starting to understand. Is there a way for me to create my own display list, and add/remove things from that instead?

Response to: Best book to get to learn AS3? Posted October 23rd, 2009 in Game Development

I just checked out Essential Actionscript 3.0 from the library. If you only can get one book grab that one. But if you got the money to spring for it, you may check out Actionscript 3.0 Cookbook as well, its a good companion book. If you google around you can find a few of the cookbook chapters online in a pdf form.

Response to: Whats a "caller?" add/remove Child Posted October 23rd, 2009 in Game Development

Awesome thanks :) Changed those to this.- and error went away. I got some other stuff to work out, but I'm going to try it on my own first.

The stage isn't part of the display list though? Weird! I'm still getting used to everything, so far I'm just combining things from different tutorials to see what happens, I've only been doing as3 for a couple weeks. I'm learning a lot tho!

By the way, I love your sig pic :)

Response to: Whats a "caller?" add/remove Child Posted October 23rd, 2009 in Game Development

Crap, forgot the last part of the code, it's probably important to. Where I stopped in my last post is where the actual game engine functions begins, These functions are below that:

public function loadAssets(e:Event):void
		{
			this.play();			
		}
		
		private function flipTheSwitch(e:Event) : void
		{
			gameState = STATE_SYSTEM_GAME;
		}
	
		
	}//end class
	
}//end package

Sorry about that.

Response to: Whats a "caller?" add/remove Child Posted October 23rd, 2009 in Game Development

At 10/23/09 08:00 AM, milchreis wrote: I'd say the caller is the guy who calls the function.

So if this fat guy in front of your house is shouting "removeChild("john")" he can do this all night, but if he has no "john" in his ars, he'll never get rid of him, because he isn't there.

code?

Here it is. Pretty much ThePreloader is setup as a seperate .as file linked to a movieclip. This is the main document class for the fla. The problem I'm having is at line:55 (I'll put a comment next to it)

package com.asgamer.basics1 
{
	import flash.display.*;
	import flash.events.*;
	
	public class Engine extends MovieClip
	{
		//game vars
		private var numStars:int = 80;
		public static var enemyList:Array = new Array();
		private var ourShip:Ship;
		private var scoreHUD:ScoreHUD;
		
		//for switch function
		public static const STATE_SYSTEM_LOADER:int=0;
		public static const STATE_SYSTEM_GAME:int=1;
		public var gameState:int = STATE_SYSTEM_LOADER;
		public var gameStarted:Boolean = false;
		
		//for preloader
		private var preloader:ThePreloader;
		
		public function Engine() : void
		{
			addEventListener(Event.ENTER_FRAME, runGame);
			
			
		}
		
		public function runGame(e:Event):void
		{
			switch(gameState)
			{
				case STATE_SYSTEM_LOADER:
					doLoadScreen();
				break;
				case STATE_SYSTEM_GAME:
					doGameLoop();
				break;
			}
		}
		
		public function doLoadScreen():void
		{
			preloader = new ThePreloader(474, this.loaderInfo);
			stage.addChild(preloader);//adding the preloader
			preloader.addEventListener("loadComplete", loadAssets);
			preloader.addEventListener("preloaderFinished", flipTheSwitch);
		}
		
		public function doGameLoop():void
		{
			if(gameStarted && currentFrame == 3)
			stage.removeChild(preloader);//removing preloader and starting game. This is the problem
			gameStarted = true;

I'm pretty inexperienced, I'm sure it shows. If you need anything explained, I'll be happy too.


I'm getting ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller, when I'm running my code. I know this has something to do with using removeChild() in the wrong place, but I'm still pretty new to AS3. My question is, what exactly is a caller when you're adding and removing children?

Response to: slopes on platforms? Posted October 21st, 2009 in Game Development

At 10/21/09 09:29 PM, ProfessorFlash wrote:
At 10/21/09 04:23 PM, Toast wrote:
At 10/21/09 07:57 AM, jonathansario wrote: Have you tried NOT negating the gravity while he's in contact with the floor?
Err, nope. Don't you know that gravity is gone when your feet touch the floor? Seriously, go learn some physics before you try to make flash games.
Was this a joke or did Toast just bring shame to him and his family? :)

Let's see... Triangle devided by a coeffiecent and some pie... Nope, he's absolutely correct. As soon as your feet touch the ground, gravity goes away. Also, space ends 12 miles up... according to these calculators.

Response to: Tablet or Mouse Posted October 21st, 2009 in Game Development

Ha ha, did you really need to ask that question? Of course a tablet is better for most artwork. If you're looking for a "starter" tablet, check out the Wacom Bamboo. You can pick one up most places for less than 60$ (mine was on sale, I got it for 35$), and its a good solid tablet. It even fits nicely in my laptop case, so bonus!

That being said, when I use the line tool, I almost always use the mouse. Don't ask me why, its just a preference thing really. If you can't get a tablet, try drawing with the line tool and bending your lines into place. It takes a little bit of practice and patience, but you can make very precise, flowing curves with a mouse if need be.

Problem with animated enemy MC Posted October 20th, 2009 in Game Development

How do I get an animated movieclip to play only until the next label, then loop back and play again continously?

I have an enemy movie clip set up with 3 frame labels, the first 6 frames are its movement animation (labeled "default" on first frame), then the next 10 frames are it's explosion animation (labeled "destroyed"), then the last frame is labeled "destroyedComplete".

What I want is for the enemy to keep playing the "default" movement animation continously unless it gets destroyed, but I'm having problems. I set up a function so if the enemy gets hit, gotoAndPlay("destroyed"), then once it gets too "destroyedComplete" it removes itself. But, unless I use a stop(); command, he'll come on screen and instantly play his destroyed animation and vanish. But using the stop() makes him stop on the first frame of default without playing any of his movement animation.

Can anyone help me out please?

Response to: Where to start with Swift 3D Posted October 20th, 2009 in Game Development

I recently got Swift3D as well. Have you read the help files yet? They aren't the cut and dry boring stuff like Flash helpfiles, they're written as if a real person is talking to you. But I'm still newb as well, if I find any tutorials that help me out I'll be sure to post them here.

Response to: Flash CS5 Posted October 20th, 2009 in Game Development

At 10/20/09 12:59 AM, farfenwaffle wrote: Physics? REALLY?! Where will style go? What happened to an inbetween? What happened to animation? I hope that adobe brings back the stuff that makes you feel acomplished when you make a movie. Like, oh I don't know... animation?Hard work? I already miss feeling special for making a good animation.

It's just a prepackaged physics engine, not an animation genie. Let's say you have a character moving around shooting a gun. If the perspective of your character is changing, the physics engine isn't going to be able to animate that for you, you'll still have to do that on your own. However you could use the engine to quickly get spent shells to bounce around on the ground. The way I see it, this tool will help to animate the subtle details, while the more time can be spent animating and refining the main action.

The only thing that peeves me about this is that I JUST got CS4 (upgraded from 8). But it's not out yet, and as far as I've searched there isn't a release date yet. I've been teaching myself AS3, so hopefully by the time this comes out I can justify getting it.

Being able to develop to multiple platforms only increases the market range for flash games. They're talking about iPhone and iTouch right now, how long do you think it'll be before Google wants compatibility with the Android phones? Or for that matter, any of the phone OS's, Blackberry, Palm, Windows Mobile, Simian, ect.? Everyone has a phone, not everyone goes to flash game sites...

I know there is already Flash for phones, but I know very little about it, other than it's not full featured.

Response to: Any good actionscript books Posted October 19th, 2009 in Game Development

Because I'm on my phone walking to the library, and hoping to get some book suggestions from the community before I get there :P

Response to: How does u make teh flahses Posted October 19th, 2009 in Game Development

Great post Pbass, let me add another book to your list. You should check out Animation: From Pencils to Pixels by Tony White as well. Its basically a book on animation theory, what makes good animation good, bad animation bad. It's a broad subject book, and doesn't focus to intently on any really specific topic, but it teacheshow to look at things the way an animator would.

Response to: Any good actionscript books Posted October 19th, 2009 in Game Development

I figure I'll post to this thread instead of making a new one. I'm heading down to the library in a few minutes and I'm wondering if anyone can give me suggestions on books (AS3) that I should look for?

I've already got the Essential Actionscript 3.0 book, and the Actionscript 3.0 cookbook on my list, so I'll be checking out/reserving those as sson as I get there.

Somebody linked me to a book on amazon that was AS3 but revolved around game development. It looked interesting but I lost my link, and can't remember what its called ha ha (any clue?)

I'll be checking back here after I get to the library, I hope someone has a suggestion or two for me beyond what's mentioned here :)

Response to: A Beginers Code w/ Problems Posted October 17th, 2009 in Game Development

Finally something works right! I got him to jump instead of fly! Yes!

if.(global.onground==true){
	_y+=0;
	_global.jump=15;
}else{
	_y+=_global.gravity;
	_global.jump--;
}

I'm making a little bit of headway on the wall problems. It seems like the last instance added to the stage is what works and all other instances won't. I put wallR on the stage first and added the code from above, then put wallL on and did the same. Only wallL works. If I take them both off, then put wallL in first, then wallR, wallR works but not wallL. The same thing happens with multiple floors as well. If I add a floor2 instance, it works, but the original floor instance will let the player fall thru.

I'm wracking my brain trying to figure this one out. If anyone has any ideas please post. I know your coming here, I see the number of views at the top of the page :P

Response to: A Beginers Code w/ Problems Posted October 17th, 2009 in Game Development

OK, so I got a solution for the gravity. It isn't pretty but it works. the character also moves much faster now.

But now I'm having some troubles with the walls! Again, I have 4 instances of movie clips on the stage, and just so I don't have any typos like last time, I'm actually on the laptop that has the game lol. The instance names are player, floor, wallL and wallR. The code for each is as follows:

player code:

onClipEvent(load){
	
	//Movement and physics
	_global.gravity=5;
	_global.jump=15;
	_global.runspeed=15;
	
	//Barriers
	_global.onground=false;
	_global.wallhit=false;
}

onClipEvent(enterFrame){
	//Gravity code
	if(_global.onground==true){
		_y+=0;
	}else{
		_y+=_global.gravity;
		}
		
	//Wall Code
	if(_global.wallhit==true){
		_global.runspeed=0;
		trace("Wall Hit");
	}else{
		_global.runspeed=15;
		}
		
	//Movement code
	if(Key.isDown(Key.LEFT)){
		_x-=_global.runspeed;			
	}
	
	if(Key.isDown(Key.RIGHT)){
		_x+=_global.runspeed;
	}
	
	if(Key.isDown(Key.UP)){
		_y-=_global.jump;
	}
}

floor code:

onClipEvent(enterFrame){
	
	if (this.hitTest(_root.player)){
		_global.onground=true;
		trace("Gravity off!")
	}else{
		_global.onground=false;
		trace("Gravity on!");
	}
}

wallL and wallR code:

onClipEvent(enterFrame){
	
	if (this.hitTest(_root.player)){
		_global.wallhit=true;
	}else{
		_global.wallhit=false;
	}
}

The idea was, turn the floor and walls into switches that change _global variables. This way I can have as many walls and grounds as I want without having to have the player code bloated with 100s of hitTests.

The floor works... ok. the player rectangle sinks into the floor a little bit, but he doesn't fall thru, and he can jump (fly really) away. I've got an idea on the jumping, but I've yet to implement it.

The walls are just kicking my mental ass tho! With the code as it is, wallL stops the player, but wallR doesn't, he walks right thru! The code is the same on both walls, so I don't understand why one would work and one wouldn't. I only recieve the "Wall Hit" trace on wallL.

Also, even tho the player will stop at wallL he can't back away from it. I tried to do a couple things with _x+ but then he just gets stuck inside the wall (but can wiggle around).

A few other things I tried resulted in no left/right movement at all, and one happy little experiment borked the whole game. I'm gonna put a few more trace()'s in there and see if I can figure out whats happening, but I think that for some reason wallR isn't doing it's hitTest >:(

If anyone happens to see where this is falling apart on me, or can give me a few pointers, I would very much appreciate it! There's no typos this time, I promise :)