Be a Supporter!

Defining Stage End/Stage limits as2

  • 372 Views
  • 18 Replies
New Topic Respond to this Topic
BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 02:25 AM Reply

Hello

as of right now my character can walk to the far enough right that you are no longer on the stage.
What is the most efficient way to establish a stage limit?

I understand this is something best applied to the Left and Right movement commands. If need be i would be willing to share my code.

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 02:46 AM Reply

Assuming your stage has a width of 550 for example, you could simply do:

if(player._x > 550) player._x = 550 
if(player._x < 0) player._x = 0
BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 02:55 AM Reply

At 3/8/13 02:46 AM, 4urentertainment wrote: Assuming your stage has a width of 550 for example, you could simply do:

if(player._x > 550) player._x = 550
if(player._x < 0) player._x = 0

not to sound stupid but is this its own event or is this applied to the left and right controls?

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 04:01 AM Reply

At 3/8/13 02:55 AM, BaronVonBroccoli wrote:
At 3/8/13 02:46 AM, 4urentertainment wrote: Assuming your stage has a width of 550 for example, you could simply do:

if(player._x > 550) player._x = 550
if(player._x < 0) player._x = 0
not to sound stupid but is this its own event or is this applied to the left and right controls?

I'm not exactly sure you would "apply it to left and right controls", but you could add it after your movement code, so that the player moves, and then you check if he is within bounds, and if not, bring him back.

Feel free to post your code if you're still having doubts, or just want to make sure you're doing it right.

BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 04:34 AM Reply

At 3/8/13 04:01 AM, 4urentertainment wrote:
At 3/8/13 02:55 AM, BaronVonBroccoli wrote:
At 3/8/13 02:46 AM, 4urentertainment wrote: Assuming your stage has a width of 550 for example, you could simply do:

if(player._x > 550) player._x = 550
if(player._x < 0) player._x = 0
not to sound stupid but is this its own event or is this applied to the left and right controls?
I'm not exactly sure you would "apply it to left and right controls", but you could add it after your movement code, so that the player moves, and then you check if he is within bounds, and if not, bring him back.

Feel free to post your code if you're still having doubts, or just want to make sure you're doing it right.

absolutely. thank you

I am trying to be as non reliant as possible on this whole project, but this is literally my last code based hurdle and i just want to be done so i can move onto the aesthetic/thematic end

heres my mov clips movement script

if (Key.isDown(Key.LEFT)) {
if (speed>-maxmove) {
speed--;
if (char._x > 800) char._x = 800;
if (char._x < 0) char._x=0;
}
this.gotoAndStop("run");
this._xscale = -100;
} else if (Key.isDown(Key.RIGHT)) {
if (speed<maxmove) {
speed++;
if (char._x > 800) char._x = 800;
if (char._x < 0) char._x=0;
}
this._xscale = 100;
this.gotoAndStop("run");
} else if (Key.isDown(65)) {
this.gotoAndStop("attack");
attacking = true;
speed = 0;
} else if (speed<1 && speed>-1 && !attacking) {
speed = 0;
this.gotoAndStop("idle");
}

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 06:29 AM Reply

In the code you posted, you never actually move the player. All you do is change the speed. I'm guessing you have another part of the code where you do:

char._x += speed;

That's where you move the player. So you need to add the if statements after this, to make sure the character remains within bounds.

Also, if you want to use code tags, just do:

<code*>
Your code here
</code*>

But remove the *.

BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 08:50 AM Reply

At 3/8/13 06:29 AM, 4urentertainment wrote: In the code you posted, you never actually move the player. All you do is change the speed. I'm guessing you have another part of the code where you do:

char._x += speed;

That's where you move the player. So you need to add the if statements after this, to make sure the character remains within bounds.

Also, if you want to use code tags, just do:

<code*>
Your code here
</code*>

But remove the *.

you know what your right, thats what i get for copyand pasting at 4am. I was attempting to spare you the groundhit test/score/health and all that other stuff, must have cut off a bit too much.

thank you

BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 09:37 AM Reply

At 3/8/13 08:50 AM, BaronVonBroccoli wrote:
At 3/8/13 06:29 AM, 4urentertainment wrote: In the code you posted, you never actually move the player. All you do is change the speed. I'm guessing you have another part of the code where you do:

char._x += speed;

That's where you move the player. So you need to add the if statements after this, to make sure the character remains within bounds.

Also, if you want to use code tags, just do:

<code*>
Your code here
</code*>

But remove the *.
you know what your right, thats what i get for copyand pasting at 4am. I was attempting to spare you the groundhit test/score/health and all that other stuff, must have cut off a bit too much.

thank you

For what ever reason it is still not working.... see below also if anyone has an easier way to achieve most of whats below please let me know, this is a montage of a college text book from 2004 & 2 internet tutorials so most likely its redundant or there is an easier way to achieve the same goal

onClipEvent (load) {
	jumping = false;
	speed = 0;
	Xpos = this._x;
	Ypos = this._y;
	maxmove = 15;
}
onClipEvent (enterFrame) {
	_x = Xpos-_root._x;
	if (!_root.ground.hitTest(this._x, this._y, true) && !jumping) {
		this._y += 55;
	}
	if (_root.dead) {
		this.gotoAndStop("dead");
	} else {
		speed *= .85;
		
		//left walls
		if (dir == "right" && !_root.leftblock.hitTest(this._x+20, this._y, true)) {
			_root.health._x += speed;
			_root.score._x += speed;
			this._x += speed;
			_root._x -= speed;
		}
		if (speed>0) {
			dir = "right";
		} else if (speed<0) {
			dir = "left";
		}
		//right walls
		if (dir == "left" && !_root.rightblock.hitTest(this._x-20, this._y, true)) {
			_root.health._x += speed;
			_root.score._x += speed;
			this._x += speed;
			}
		if (Key.isDown(Key.LEFT)) {
			if (speed>-maxmove) {
				speed--;
			}
			this.gotoAndStop("run");
			this._xscale = -100;
		} else if (Key.isDown(Key.RIGHT)) {
			if (speed<maxmove) {
				speed++;
			if(this._x > 800) this._x = 800
			if(this._x < 0) this._x=0;
			}
			this._xscale = 100;
			this.gotoAndStop("run");
			//punch
		} else if (Key.isDown(65)) {
			this.gotoAndStop("attack");
			attacking = true;
			speed = 0;
			//punch
		} else if (speed<1 && speed>-1 && !attacking) {
			speed = 0;
			this.gotoAndStop("idle");
		}
		if (Key.isDown(Key.UP) && !jumping) {
			jumping = true;
		}
		if (jumping) {
			this.gotoAndStop("jump");
			this._y -= jump;
			jump -= .5;
			if (jump<0) {
				falling = true;
			}
			if (jump<-15) {
				jump = -8;
			}
		}
		//ground
		if (_root.ground.hitTest(this._x, this._y, true) && falling) {
			jump = 12;
			jumping = false;
			falling = false;
		}
		//end ground
	}
}
//punch 2
onClipEvent (keyUp) {
	if (Key.getCode() == 65) {
		attacking = false;
	}
}
//punch 2
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 10:20 AM Reply

At 3/8/13 09:37 AM, BaronVonBroccoli wrote: For what ever reason it is still not working.... see below also if anyone has an easier way to achieve most of whats below please let me know

Apply the movement, then just run the tests mentioned by 4urentertainment

this is a montage of a college text book from 2004 & 2 internet tutorials so most likely its redundant or there is an easier way to achieve the same goal

As said before: Stop copy&pasting code, especially if it's as old as this code.

BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 10:31 AM Reply

At 3/8/13 10:20 AM, milchreis wrote:
At 3/8/13 09:37 AM, BaronVonBroccoli wrote: For what ever reason it is still not working.... see below also if anyone has an easier way to achieve most of whats below please let me know
Apply the movement, then just run the tests mentioned by 4urentertainment

this is a montage of a college text book from 2004 & 2 internet tutorials so most likely its redundant or there is an easier way to achieve the same goal
As said before: Stop copy&pasting code, especially if it's as old as this code.

crap i copied the script without the newcode.

and i know your right, but until I can get either comfortable with another flash editor or the cash to shell out for a non student copy/newer version i'm stuck with this.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 10:37 AM Reply

At 3/8/13 10:31 AM, BaronVonBroccoli wrote: and i know your right, but until I can get either comfortable with another flash editor or the cash to shell out for a non student copy/newer version i'm stuck with this.

Nobody forces you to write code on symbols.

A code editor is as complicated as a text editor.

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 10:47 AM Reply

What you're not comfortable with is learning how to code and writing it yourself. If you're going to steal other peoples code and not bother to take advice when people offer it don't bring your problems here.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 8th, 2013 @ 12:21 PM Reply

At 3/8/13 10:47 AM, MintPaw wrote: What you're not comfortable with is learning how to code and writing it yourself. If you're going to steal other peoples code and not bother to take advice when people offer it don't bring your problems here.

what i was referencing by not being comfortable with was the layout of programs like flash developer vs adobe flash
specifically the ability to visually associate everything right then and there, and then define it as a mov and then apply code.

and no one is ignoring anyones advice, I took it into consideration, and if i do anything else outside of this one game, yes i will focus more on as3. For the simple project I am doing i am sticking with what i have, especially considering i am the only one who will ever play it.

BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 9th, 2013 @ 02:52 PM Reply

At 3/8/13 10:47 AM, MintPaw wrote: What you're not comfortable with is learning how to code and writing it yourself. If you're going to steal other peoples code and not bother to take advice when people offer it don't bring your problems here.

hey i wanted to apologize if thats even needed, you were right I was wrong.
I scrapped my whole game starting from scratch and ensuring that everything is of my own doing.
i'll bug you guys in a month or so if i have any issues when (hopefully) get everything back up to where it currently is with the copy and paste amalgamation of doom.

flashMan
flashMan
  • Member since: Aug. 24, 2009
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 9th, 2013 @ 04:27 PM Reply

well you are starting again so here is some useful stuff:

please dont code in symbols, just code in the first frame.

when coding in the 1st frame you can use onEnterFrame = function(){

You can refer to movie clips via their instance names

try to learn about arrays, it shortens your code

try to learn about functions too, it shortens your code

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Defining Stage End/Stage limits as2 Mar. 9th, 2013 @ 08:16 PM Reply

At 3/9/13 04:27 PM, flashMan wrote: You can refer to movie clips via their instance names

This. I advise against.

Although it's all about how much you care, like, if it's just a school project and you don't really care about Flash or programming then you can do it how you want, but the more you actually care about programming the more strict you can be.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 10th, 2013 @ 11:36 AM Reply

at this point this project is to prove to my self that i can do it. nothing more no end game outside of that.

I am just getting overwhelmingly frustrated because i built a couple games back in college (1 platformer 1 trivia 1 space invaders/defender clone) in college and was fine, that was 7 years ago though and its irritatingly rough to get back into this

BaronVonBroccoli
BaronVonBroccoli
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Defining Stage End/Stage limits as2 Mar. 10th, 2013 @ 03:43 PM Reply

i didnt think this was worth starting a new thread over, and i promise this is the last post in this thread from me

how reliable do these tutorials look

http://www.makeflashgames.com/gamedesign/replayability.php

i like the idea that each tutorial gets progressively more complicated while still working off of reoccuring concepts.

FlyingColours
FlyingColours
  • Member since: Jul. 3, 2011
  • Offline.
Forum Stats
Member
Level 06
Programmer
Response to Defining Stage End/Stage limits as2 Mar. 11th, 2013 @ 07:33 AM Reply

In addition to flashMan's advice, don't use _root. Also, always declare variables. I couldn't see any var statements, so I guess you either put them somewhere else or didn't use them.

var myVariable:Type;

By the way, Stage.width and Stage.height are the stage width and stage height in AS2.

Hope this helps. ;)