Forum Topic: Variable Problems

(198 views • 10 replies)

This topic is 1 page long.

<< < > >>
None

ggully

Reply To Post Reply & Quote

Posted at: 11/25/07 01:24 PM

ggully NEUTRAL LEVEL 05

Sign-Up: 11/08/07

Posts: 27

Ok, im trying to make a platformer, i have a very basic code, but when it hits the ts1 movie clip, it doesnt change the speed.

Thisis the code i have

onClipEvent(enterFrame){
speed = 5;
if(Key.isDown(Key.RIGHT)){
this._x += speed;
}
if(Key.isDown(Key.LEFT)){
this._x -= speed;
}
if(Key.isDown(Key.UP)){
this._y -= speed;
}
if(Key.isDown(Key.DOWN)){
this._y += speed;
}
}
onClipEvent(enterFrame) {
if(_root.p1.hitTest(_root.ts1.ts1)) {
speed +=5;
}
}

any help plz?


None

Synk

Reply To Post Reply & Quote

Posted at: 11/25/07 01:27 PM

Synk LIGHT LEVEL 02

Sign-Up: 12/03/05

Posts: 39

put speed=5 above the line above it, it'll work fine then.


None

nobody404

Reply To Post Reply & Quote

Posted at: 11/25/07 01:28 PM

nobody404 NEUTRAL LEVEL 11

Sign-Up: 04/27/07

Posts: 279

If the whole code was on the same frame, it wouldn't work.

Put the speed+=5 on a seperate frame, and it will speed up when it reaches that frame.


None

Synk

Reply To Post Reply & Quote

Posted at: 11/25/07 01:31 PM

Synk LIGHT LEVEL 02

Sign-Up: 12/03/05

Posts: 39

^^ ya, that's right

the reason is ur speed=5 line is getting redone every frame, so the speed+=5 doesn't ever do anything b/c on the next frame it resets to speed=5. put speed=5 somewhere where it only activates once


None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 11/25/07 01:38 PM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

I can fix your code, but I'm not sure what you're looking to make it do exactly. I've fixed the code the way it is now to what it should be, but I don't think that this is what you want:

onClipEvent (load) {
	speed = 5;
}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.RIGHT)) {
		this._x += speed;
	}
	if (Key.isDown(Key.LEFT)) {
		this._x -= speed;
	}
	if (Key.isDown(Key.UP)) {
		this._y -= speed;
	}
	if (Key.isDown(Key.DOWN)) {
		this._y += speed;

		if (this.hitTest(_root.ts1.ts1)) {
			speed += 5;
		}
	}
}

None

ggully

Reply To Post Reply & Quote

Posted at: 11/25/07 01:41 PM

ggully NEUTRAL LEVEL 05

Sign-Up: 11/08/07

Posts: 27

Thats what my problem is, for instance on frame one of a seperate layer i have

Mouse.hide();
ch.onMouseMove = function() {
ch._x = _xmouse;
ch._y = _ymouse;
updateAfterEvent();
};

speed = 5;

and then p1 wont move as if it never set speed

Also does anyone kno anything about making a movieclip rotate with a the mouse and how to set it center so its perfectly insync?

i have

this.onMouseMove = function() {
_rotation = (Math.atan2(_root._ymouse - _y, _root._xmouse - _x)) * (180 / Math.PI);
};

but its not lined up with the mouse


None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 11/25/07 01:44 PM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

At 11/25/07 01:41 PM, ggully wrote: Also does anyone kno anything about making a movieclip rotate with a the mouse and how to set it center so its perfectly insync?

i have

this.onMouseMove = function() {
_rotation = (Math.atan2(_root._ymouse - _y, _root._xmouse - _x)) * (180 / Math.PI);
};

but its not lined up with the mouse

Your code is fine. Make sure that the function is working with a movieclip, and not the stage itself. Also, make sure the shape inside the movieclip is facing right when using that code.


None

ggully

Reply To Post Reply & Quote

Posted at: 11/25/07 02:03 PM

ggully NEUTRAL LEVEL 05

Sign-Up: 11/08/07

Posts: 27

ok thanks it worked, but now back to the variable thing i realize it might of been hard to understand, this is what i have tho...

Layer 1, Frame 1 - Actions
speed = 5;

mc.ts Frame 1 - Actions
//This is barracade, im trying to make it act as a wall
onClipEvent(enterFrame) {
if(this.ts.hitTest(p1)) {
p1._x - 1
p1._y - 1
}

never sets the variable and it never performs the command on hittest

thanks agian for the help
}


None

POWER-RANGER-PINK

Reply To Post Reply & Quote

Posted at: 11/25/07 02:06 PM

POWER-RANGER-PINK NEUTRAL LEVEL 01

Sign-Up: 09/03/07

Posts: 106

(_root.ts1.ts1)

Why do you have _root.ts1.ts1? Unless you have another movieclip with the instance name ts1 inside the already existing one with the name ts1, you should just do (_root.ts1)


None

TrueDarkness

Reply To Post Reply & Quote

Posted at: 11/25/07 02:11 PM

TrueDarkness EVIL LEVEL 27

Sign-Up: 08/31/04

Posts: 4,718

Here, get rid of that code on the barricade, and put this directly on the player.

onClipEvent (load) {
	speed = 5;
	w = _width/2;
	h = _height/2;
}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.RIGHT)) {
		this._x += speed;
	}
	if (Key.isDown(Key.LEFT)) {
		this._x -= speed;
	}
	if (Key.isDown(Key.UP)) {
		this._y -= speed;
	}
	if (Key.isDown(Key.DOWN)) {
		this._y += speed;
	}

	if (_root.ts1.ts1.hitTest(_x+w, _y, true)) {//If the barricade detects collision from the right side of this MC.
		_x -= speed;//This MC subtract speed on X axis (acts as barrier)
	}
	if (_root.ts1.ts1.hitTest(_x-w, _y, true)) {
		_x += speed;
	}
	if (_root.ts1.ts1.hitTest(_x, _y-h, true)) {//If the barricade detects collision from the bottom side of this MC.
		_y += speed;//This MC subtracts speed on Y axis
	}
	if (_root.ts1.ts1.hitTest(_x, _y+h, true)) {
		_y -= speed;

	}
}

Now whatever you want to act as a barrier, just draw it in the ts1.ts1 movieclip.


None

ggully

Reply To Post Reply & Quote

Posted at: 11/25/07 11:54 PM

ggully NEUTRAL LEVEL 05

Sign-Up: 11/08/07

Posts: 27

Ok, i tried the code you gave me and it doesn't work, i even modded it to see if i could find the problem and came out with this..

onClipEvent (load) {
speed = 10;
w = _width/2;
h = _height/2;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT))
{
this._x += speed;
}
if (Key.isDown(Key.LEFT))
{
this._x -= speed;
}
if (Key.isDown(Key.UP))
{
this._y -= speed;
}
if (Key.isDown(Key.DOWN))
{
this._y += speed;
}
if (_root.ts1.ts.hitTest(this._x+w, this._y, true))
{
this._x -= speed;
}
if (_root.ts1.ts.hitTest(this._x-w, this._y, true))
{
this._x += speed;
}
if (_root.ts1.ts.hitTest(this._x, this._y-h, true))
{
if (_root.ts1.ts.hitTest(this._x, this._y+h, true))
{
this._y -= speed;
}
}
}

The only reason its ts1.ts is because i have a mc, in that mc there is ts(a block for right now) and a shadow...maybe if i eliminate that i could make it easier?


All times are Eastern Standard Time (GMT -5) | Current Time: 07:28 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!