Forum Topic: AS: Platform Placing

(2,623 views • 15 replies)

This topic is 1 page long.

<< < > >>
Happy

Hoeloe

Reply To Post Reply & Quote

Posted at: 5/1/06 02:02 PM

Hoeloe LIGHT LEVEL 22

Sign-Up: 04/29/04

Posts: 3,976

RELATED LINKS:
AS: Main
AS: Duplicated Movie Clips
AS: Frame Functions
Ultimate Tutorial 2

THE TUTORIAL:
First off, create a ball. Make it a movie Clip with the instance of circle, then add the actions below:
onClipEvent (load) {
fall = false;
_name = "circle";
jump = 0;
speed = 8;
jumpheight = 15;
maxfall = -54;
}
onClipEvent (enterFrame) {
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (Key.isDown(Key.SPACE) && fall == false && jump == undefined) {
fall = true;
jump = jumpheight;
}
if (jump<>undefined) {
if (jump>maxfall) {
jump--;
}
_y -= jump;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
}

this makes the player moveable and jumpable when on a platform

Next, draw a platform on the floor. do not give it an instance name. add this script to it:
onClipEvent (load) {
activated = false;
down = false;
}
onClipEvent (enterFrame) {
_root.report.text = Math.round(_root.circle.yMax)+" "+Math.round(yMin);
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (_root.circle.xMax>xMin && _root.circle.xMin<xMax && _root.circle.yMax<yMin) {
if (_root.circle.yMax-_root.circle.jump*2>yMi
n) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}
if (Math.round(_root.circle.yMax)>Math.round(
yMin)) {
if (hitTest(_root.circle) && _root.circle.xmax<xmin) {
_root.circle._x -= _root.circle.speed;
}
if (hitTest(_root.circle) && _root.circle.xmin>xmax) {
_root.circle._x += _root.circle.speed;
}
if (hitTest(_root.circle) && _root.circle.ymin>ymax && _root.circle.jump>-1) {
_root.circle.jump = -1*(_root.circle.jump);
}
}
if (activated == true && not hitTest(_root.circle) && _root.circle.jump == undefined) {
_root.circle.jump = 0;
activated = false;
}
if (hitTest(_root.circle) && _root.circle.ymax>ymin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
if (_root.circle.ymax-_root.circle.jump>ymin && _root.circle.xMin<xMax && _root.circle.xMax>xMin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}

this makes a fully funtional platform with walls, ceiling and floor.

now copy that and resize it to make walls and a ceiling. You can dowload a sample file of the above in Ultimate Tutorial 2.
Now, make a small square movie clip off screen with the instance "plat" no quotes, and the sam script as the platform.
Now make a Dynamic Text Box with the variable name "power" no quotes.
Add the following actions to the frame:
onLoad = function(){
i = 1;
power = 100;
placing = false;
}
onMouseDown = function(){
placing = true;
}
onEnterFrame = function(){
if(placing){
if(power >0){
i ++;
_root.plat.duplicateMovieClip("plat"+i,100
0 + i);
_root["plat"+i]._x = _root._xmouse;
_root["plat"+i]._y = _root._ymouse;
_root["plat"+i]._alpha = power;
power --;
}
}
}
onMouseUp = function(){
placing = false;
}

this makes the plat movie clip duplicate when the mouse is down, and creates a platform that will work in the same way as the floor, walls or ceilings, and makes you only be able to build one if you have power.

The last thing to do is go to File/Publish Settings and make sure that the export flash player is 6, yes flash 6, or it wont work.

To view a sample, click here

I never claim to know everything, people just assume I do anyway.
------------------------------
THE LAST WIZARD AND THE DOOMSDAY RINGS NOW IN PRODUCTION!

BBS Signature

None

Nick

Reply To Post Reply & Quote

Posted at: 5/1/06 02:06 PM

Nick FAB LEVEL 22

Sign-Up: 08/22/05

Posts: 1,966

Should be a Foss, IMO.


Questioning

Hoeloe

Reply To Post Reply & Quote

Posted at: 5/1/06 02:33 PM

Hoeloe LIGHT LEVEL 22

Sign-Up: 04/29/04

Posts: 3,976

wot is FOSS?

I never claim to know everything, people just assume I do anyway.
------------------------------
THE LAST WIZARD AND THE DOOMSDAY RINGS NOW IN PRODUCTION!

BBS Signature

None

yam

Reply To Post Reply & Quote

Posted at: 5/1/06 02:43 PM

yam NEUTRAL LEVEL 02

Sign-Up: 03/12/06

Posts: 1,670

Could of explained the code abit better, but nice!


None

Toast

Reply To Post Reply & Quote

Posted at: 5/1/06 02:44 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

You didn't write that code, and you didn't give any explanations neither...

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

yam

Reply To Post Reply & Quote

Posted at: 5/1/06 02:47 PM

yam NEUTRAL LEVEL 02

Sign-Up: 03/12/06

Posts: 1,670

At 5/1/06 02:06 PM, _Nick_ wrote: Should be a Foss, IMO.

four more posts nick, then you get 1337


None

Nick

Reply To Post Reply & Quote

Posted at: 5/1/06 03:07 PM

Nick FAB LEVEL 22

Sign-Up: 08/22/05

Posts: 1,966

At 5/1/06 02:33 PM, Hoeloe wrote: wot is FOSS?

Free Open Source Software :D


None

Toast

Reply To Post Reply & Quote

Posted at: 5/1/06 03:15 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

At 5/1/06 03:07 PM, _Nick_ wrote:
At 5/1/06 02:33 PM, Hoeloe wrote: wot is FOSS?
Free Open Source Software :D

ur teh 1337 :o

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

Hoeloe

Reply To Post Reply & Quote

Posted at: 5/1/06 03:19 PM

Hoeloe LIGHT LEVEL 22

Sign-Up: 04/29/04

Posts: 3,976

At 5/1/06 02:06 PM, _Nick_ wrote: Should be a Foss, IMO.

so is that a compliment or an insult?

I never claim to know everything, people just assume I do anyway.
------------------------------
THE LAST WIZARD AND THE DOOMSDAY RINGS NOW IN PRODUCTION!

BBS Signature

None

Nick

Reply To Post Reply & Quote

Posted at: 5/1/06 03:40 PM

Nick FAB LEVEL 22

Sign-Up: 08/22/05

Posts: 1,966

At 5/1/06 03:19 PM, Hoeloe wrote:
At 5/1/06 02:06 PM, _Nick_ wrote: Should be a Foss, IMO.
so is that a compliment or an insult?

Neither really. Had you have titled it Foss, then I would've said something like "Good work".

Aww, i'm not 1337 anymores :'(

None

Hoeloe

Reply To Post Reply & Quote

Posted at: 5/1/06 04:46 PM

Hoeloe LIGHT LEVEL 22

Sign-Up: 04/29/04

Posts: 3,976

ok the first two pieces of code(player + platforms) are explained in Ultimate tutorial 2,
the third code i can explain however as i wrote it:
onLoad = function(){ //the same as onClipEvent(load)
i = 1; //sets i
power = 100; //sets power
placing = false; //sets placing to false
}
onMouseDown = function(){ //same as onClipEvent(mouseDown)
placing = true;//sets placing to true
}
onEnterFrame = function(){ //same as onClipEvent(enterFrame)
if(placing){ // if placing is true
if(power >0){ // and power is bigger than 0
i ++; // i adds 1
_root.plat.duplicateMovieClip("plat"+i,100
0 + i); // duplicates plat
_root["plat"+i]._x = _root._xmouse;
_root["plat"+i]._y = _root._ymouse;// plat duplicate moves to the mouse position
_root["plat"+i]._alpha = power; // the less power you have, the less visible the platforms are
power --;// power decreses by 1
}
}
}
onMouseUp = function(){//same as onClipEvent(mouseUp)
placing = false;//sets placing to false
}

this basically means that if the variable placing is true, then a platform will appear at the mouse's x and y, and that you can hold down and drag to place many platforms

HAPPY NOW?????

I never claim to know everything, people just assume I do anyway.
------------------------------
THE LAST WIZARD AND THE DOOMSDAY RINGS NOW IN PRODUCTION!

BBS Signature

None

KougaijiGyumao

Reply To Post Reply & Quote

Posted at: 6/6/06 02:02 AM

KougaijiGyumao EVIL LEVEL 08

Sign-Up: 05/26/06

Posts: 157

Can this AS work with a non-ball MC? Sorry if it's dumb, but I don't know why it won't work for me...


None

Kenney

Reply To Post Reply & Quote

Posted at: 6/6/06 02:13 AM

Kenney NEUTRAL LEVEL 17

Sign-Up: 03/16/02

Posts: 2,336

At 6/6/06 02:02 AM, KougaijiGyumao wrote: Can this AS work with a non-ball MC? Sorry if it's dumb, but I don't know why it won't work for me...

Yes ofcourse, it can have any shape.

Visit my website: Kenney.nl


None

KougaijiGyumao

Reply To Post Reply & Quote

Posted at: 6/6/06 02:51 AM

KougaijiGyumao EVIL LEVEL 08

Sign-Up: 05/26/06

Posts: 157

Can you guys help me? I used this AS and I modified some parts, and well... I can't seem to make it work...

Here's the wrong parts in my AS:
onClipEvent(load){
stop(); dir=0;
}
onClipEvent (enterFrame)
{if (Key.isDown(Key.RIGHT))
{_x+=speed; gotoAndStop(2); dir=0;}
else if (Key.isDown(Key.LEFT))
{_x-=speed; gotoAndStop(3); dir=1;}
else if (Key.isDown(Key.17) && dir=1)
{_x-=speed; gotoAndPlay(15); dir=1;}
else if (Key.isDown(Key.17) && dir=0)
{_x-=speed; gotoAndPlay(5); dir=0;}
else { if (dir==0) {gotoAndStop(1);}else{gotoAndStop(4);}
}


None

KougaijiGyumao

Reply To Post Reply & Quote

Posted at: 6/6/06 02:53 AM

KougaijiGyumao EVIL LEVEL 08

Sign-Up: 05/26/06

Posts: 157

oops. wrong thread. >_< I was reading this and AS:Movement. T_T egad, please don't BAN me!! >_<


None

TehBoss

Reply To Post Reply & Quote

Posted at: 9/9/08 07:52 PM

TehBoss EVIL LEVEL 12

Sign-Up: 04/11/07

Posts: 490

At 5/1/06 02:33 PM, Hoeloe wrote: wot is FOSS?

Free Open Source Software, like the source engine for Half Life 2.

2008 Ban Count: 1 || Look out for A Fight For America and the Mod Kit!
AS: Main || AS3: Main || FOSS: Main || MB Web


All times are Eastern Standard Time (GMT -5) | Current Time: 01:42 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!