Be a Supporter!

Can you do this?

  • 319 Views
  • 4 Replies
New Topic Respond to this Topic
HypNosE777
HypNosE777
  • Member since: Mar. 5, 2009
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Can you do this? 2010-12-09 01:27:36 Reply

btw its like 8 in the morning, and i haven't slept, plus my english speling isn't the best, so it might be a bit confusing, but i hope I get a reply anyway (:

like i'v sayed in my other post i'v made, im a newbi to AS.
and i sadly got a bit too much into AS2 then AS3

but im n artist, so i just wan't to know some basic stuff and such.

anyway im working on a platform game, and i have this problem,
that when my player hits a wall (witch is acterly just the ground haveing a to block like a wall)
my BG keeps moving, and im trying to give it a bit of death. so then i sat and tryed some scrips n stuff, i rly find it fund to try hard first to see if you can figure it out, but then after a few hours of trying i came here to ask if this is even posebel.

is there any way i can make my MCbg move, lets just say like _x +=5 everytime MCplayer move _x +=10?
and then if my MCplayer hits a wall and still useing key.LEFT but it is acterly not moveing, so the MCbg wont move either?

and ofc it would work the same way with the - and + Y and X ?

i know this is a bit confusing, but as i sayed im sort a new to this and working kinda hard on it ;D
and i'm a wither and artist. :b but would like to be able to make small mini projects myself


BBS Signature
HypNosE777
HypNosE777
  • Member since: Mar. 5, 2009
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Can you do this? 2010-12-09 01:29:50 Reply

again this is AS2 im working in (:


BBS Signature
cdjproductions
cdjproductions
  • Member since: Jul. 2, 2010
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Can you do this? 2010-12-09 02:45:18 Reply

It's probably a better idea to have the background move only when the foreground is moving, rather than the main character. Not exactly sure how I would code it just yet, I'm new to AS2 as well. :)

So here's what I can tell you...
When you have left key down:
- check a hit test to your left before you move
- if your character can move left, do; otherwise, don't move

Right key is almost the same, except you switch out "left" with "right"

If your character is moving:
- move the foreground to match (x and y)
- move the background half as much as the foreground (x/2 and y/2)

Hope this helps!


This account is now defunct and will now serve as an alt - _)-UltimateCJ64-(_
Seriously, I'm serious.

biohasard
biohasard
  • Member since: Apr. 11, 2008
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Can you do this? 2010-12-09 18:24:23 Reply

Might be a little late, But no one really answered you and I thought you might still need help.

I think the problem is that the player MC is the only thing you're telling to check for collisions.
You need to tell the background to check for collisions between player and terrain aswell.

I think it's best to make the background move with the same keys as the player, and the same speed.
speed should be a variable on both the player, and the background. You should make the background check for collision between the player, and your terrain. If such a collision occurs, you can set your speed variable to 0.

So something like this on your background,

onClipEvent(load){
speed=10; stop();
}
onClipEvent (enterFrame) {
_x+=Key.isDown(Key.RIGHT)*speed;
_x-=Key.isDown(Key.LEFT)*speed;
if(player.hitTest(_root.wall)) {
speed=0;
}
}

This might not be 100% accurate, but it's hard. your question was rather vague.


Biohasard, Staying neutral since 2009!

BBS Signature
HypNosE777
HypNosE777
  • Member since: Mar. 5, 2009
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Can you do this? 2010-12-09 18:56:21 Reply

I'v worked on it today and this is what i came up with but i have another problem now.

when player hits wall it stops, but only one of the wall MC
the other one wall MC wont have any effect.

here is a swf
LINK HERE

red = Background
blue = forground
green = ground
purpleish = wall tricker

onClipEvent (load) {
	var MoveMyBg:Boolean = true;
	var bgspeed:Number = 5;
	var fgspeed:Number = 10;
}

onClipEvent (enterFrame) {
if(MoveMyBg == true)
{

  if(Key.isDown(Key.RIGHT))
  _root.MyBg._x +=bgspeed;
  
  if(Key.isDown(Key.LEFT))
  _root.MyBg._x -=bgspeed;

}
}

onClipEvent (enterFrame) {
if(MoveMyBg == true)
{

  if(Key.isDown(Key.RIGHT))
  _root.MyFg._x -=fgspeed;
  
  if(Key.isDown(Key.LEFT))
  _root.MyFg._x +=fgspeed;

}
}

onClipEvent (enterFrame){
	if(this.hitTest(_root.wall))
	MoveMyBg = false;
	
	else{
		MoveMyBg = true;
	}
}

BBS Signature