Multiple platforms, only one workin
- Jayspear
-
Jayspear
- Member since: Jul. 24, 2005
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
I am working on a relatively simple flash platform game, but the problem is for me that the chatacter only stops falling against one specific platform, even though the other ones is a copy of the first.
The code is a bit wonky so I am thinking about redoing it for the third time.
I am relatively new at flash, so I am unfamiliar with classes and such...
And we are talking about flash 2.0 here.
AAaand the script is a mess of failed scripts and experimentation. Only the experimentation isn't taking me anywhere caus I seem to lack some knowledge to contionue.
And as a sidenote: The AS part of "The Flash Tutorial collab 08" is utter crap and half of it work.
onClipEvent(load){
}
onClipEvent (enterFrame){
dir = Key.isDown(Key.RIGHT) - Key.isDown(Key.LEFT);
_x += dir * 7;
}
// Dvs att variablen dir påverkas av hruvida man trycker ner antingen höger eller väsnter. Dirs värde påverkar i sig hur objektet rör sig i x-led.
// positivt är alltså höger, negativt vänster. Bläh. Enkelt förklarat: Dirs värde styr rikting, piltangenter adderar och subtraherar värde.
/*
onClipEvent(enterFrame){
if(hopp){
faller += 0.5;
_y += faller;
if(this.hitTest(_root.golv)){
hopp = false;
faller=0
}
}
else{
if(Key.isDown(Key.SPACE)){
hopp=true;
faller=-10;
}
}
}
onClipEvent (load){
var Gravit:Number=0
}
onClipEvent(enterFrame){
if(this.hitTest(_root.golv)){
gravit=0 }
else{ gravit=
}
}
// Detta är då själva gravitationen. Lycligtvis har flash en inbygd kollisions-test funktion, så den är smärtfritt
// inslagen i scriptet. Problemet var att får "charactären" att falla även om ett hopp inte var startat.
//
*/
onClipEvent (load){
var gra=0;
}
onClipEvent (enterFrame)
{
var gra=5;
if(this.hitTest(_root.golv))
{
_y+=0
}
else
{
_y+=gra;
}
} - henke37
-
henke37
- Member since: Sep. 10, 2004
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
Your script is crap and you know it. You need a datastucture containg all items that you want to collsioncheck against.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
At 3/31/09 08:14 AM, Jayspear wrote: I am working on a relatively simple flash platform game, but the problem is for me that the chatacter only stops falling against one specific platform, even though the other ones is a copy of the first.
if(this.hitTest(_root.golv))
This only checks against one MC, instanceNamed golv
To hitTest against multiple platforms, you need to use a for loop to check against all instance names of the different platforms... eg:
onClipEvent(enterFrame){
this.contact=0;
for(var i=1;i<5;i++){
if(this.hitTest(_root["golv"+i])){
this.contact=1;break;
}
}
if(this.contact){
_y+=0;
}else{
_y+=gra;
}
}
This assumes your instance names for the platforms are golv1, golv2... golv4
For future reference, you only need one (not three) onClipEvent(load) and onClipEvent(enterFrame)
- littleMonsterGames
-
littleMonsterGames
- Member since: Dec. 24, 2008
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
At 3/31/09 08:14 AM, Jayspear wrote: I am working on a relatively simple flash platform game
since when are platform games simple? if you meant 'bad' then that makes sense, but platform games are actually not simple, and require knowledge of all the foundation programing concepts. You'll need to know functions, classes, loops, all that jazz, and plus, you'll need to be great at making graphics. It's not as simple as it seems!
I am relatively new at flash, so I am unfamiliar with classes and such...
Okay, well good luck with your platformer then...
And why does being new to flash mean that you don't know classes? Someone could be new to flash, but be a really good programmer. I think what you meant was 'not only am i new to flash, but I also have no idea what I'm doing... help...'
- Yambanshee
-
Yambanshee
- Member since: Oct. 5, 2008
- Offline.
-
- Forum Stats
- Member
- Level 11
- Blank Slate
try learning shapeflag hitTests, and testing on one movie clip containing all of your platforms
- littleMonsterGames
-
littleMonsterGames
- Member since: Dec. 24, 2008
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
At 3/31/09 09:37 AM, Yambanshee wrote: try learning shapeflag hitTests, and testing on one movie clip containing all of your platforms
This will also allow you to use curved platforms (with a bit of extra code for the rotation). I recommend this technique.
- henke37
-
henke37
- Member since: Sep. 10, 2004
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
I recommend against using point vs object hittesting for anything but gun shots and the mouse position.
Instead, I recommend a tile based engine. It was good enough for Mario, it is good enough for you. With proper design, you can actually get perfect collision logic with slopes then, instead of those messy guessing games that tries to probe the vector drawings how they turn. (WTF!)
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
- Jayspear
-
Jayspear
- Member since: Jul. 24, 2005
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
At 3/31/09 09:16 AM, littleMonsterGames wrote: since when are platform games simple? if you meant 'bad' then that makes sense, but platform games are actually not simple, and require knowledge of all the foundation programing concepts. You'll need to know functions, classes, loops, all that jazz, and plus, you'll need to be great at making graphics. It's not as simple as it seems!
Wow we sure are cranky are we? I have never understood people that actively post in threads just to complain. Yes I am new to flash, but no I am no virgin i programing. I am just not a "leet haxxor".
And since when did I say platformers were hard? And since when did I say I wanted to make the best platformer in teh world? I am simply trying to learn by doing, trial and error. I have a hard time seeing why you bothered to post at all, since all you're saying is
"Fuck you flash is hard make a dress-up. Go learn somewhere else"
And thanks to all the other people in this thread that knows what constructive posting is about.



