-
your problem with the current hitTesting is that the key press is captured inside the loop. i think that if you switched the lines like this:
PHP Code:
if (Key.isDown(Key.LEFT)) {
for (var i = 0; i<_root.lineArray.length; i+= 1) {
if (!_root.lineArray[i].hitTest(_x-_width/2, _y+_height/4, true)) {
_root._x += xspeed;
_root.menu._x -= xspeed;
this._x -= xspeed;
_root.flag._x -= xspeed;
}
}
}
you might have the proper results.
after you made me realize that i had no idea how to do this, i was up last night putting this swf together. see if it's what you want or not. unfortunately, i still have no idea how to properly do slopes lol. one more thing, at tight angles(say less than 60 degrees or so) the character can jump through the line above his head
-
Hehe I think your slope movements even better then mine ;). I'll try your code now :).
-
heh. how'd you do yours? i just set a pre-x and pre-y variable to see where the char was before he moved, then i tested to see if it hit a line, and if it did, i just set its x and y back to the pre-x and pre-y
-
My guys code is pretty simple, it uses a while function to see if your characters bottom is touching the terrain and if not it moves him up smoothly. (y--)
-
hmm,looking again at your game, i think you should increase the gravity a little bit. that will make the action of falling down a slope look a lot better and more realistic
-
Hey I tried what you said but I still am having some real unusual problems with the character. The while y--; thing isnt working properly on the various movieclips but only the first one and the character is moving way to fast =\. Oh and you were right about the gravity, =] increasing it made the slope movement a lot better.
-
hmm. well, the way i built my engine, i guess you could call it, it moves the character, not the rest of the mc's. so i'm not exactly sure how you could do that. i can tell you why everything is moving so fast though.
ok, before the loop happens, lets set a variable
spd1=5
ok, so, now if you use that variable to move something, it moves it fine, right?
look at what a loop does though, for every iteration of the loop, all of the code within the loop is called. test this by using a small loop and a trace comand inside of it and you'll see that what was supposed to be traced is traced several times. so...
for(var i=0;i<5;i++){
mc._x+=spd1
}
says that you are adding spd1 to the mc's x position everytime that the loop iterates, rather than just the initial time.
if it were me, i'd simply create a function that handles the hitTests with the loop inside that function separately, then return a boolean if there is a hitTest. after that, you can use the same movement code, except, you won't need the loop, and instead of saying "if(!wall.hitTest(char))" or w/e
you could say "if(!collDetected())"
where collDetected is the function i described earlier
-
ok i'm ganna have to build one now just to see if i can do it, god that's amazing squid, i'm sorry ab9003 i think i had more fun playing with squid's than yours
-
rofl, sorry 'bout that ab9003. of course, the only major difference i could see between mine and his is the gravity coming off of the slopes.
-
yea but i think the little figure that you built was what got me
-
lol, its just circle and a square...
-
Ouch what a stab in the heart, I worked so long on this project =[. Anyway the thing you said I tried to do but it didnt really work so I resorted to this:
for (var i = 0; i<_root.lineArray.length; i+= 1) {
while (_root.lineArray[i].hitTest(_x, _y+_height/2, true)) {
_y-= 1 /_root.d;
yspeed = 0;
jumping = 0;
}
}
It evens itself out by dividing the extra data out, but its a very poor way of solving the problem and rather ineifficient (not to mention not working so well), I just dont know what else to do..
-
you could try the method i use. it moves the items no matter what, but if the items hit, they are moved back.
-
Id just like my code to be something like this:
for (var i = 0; i<_root.lineArray.length; i+= 1) {
while (_root.lineArray[i].hitTest(_x, _y+_height/2, true))} (close for statement before while begins) {
_y-= 1 /_root.d;
yspeed = 0;
jumping = 0;
}
}
You know, so it only loops the hitTest but nothing else. Im having a hell of a time trying to make it work though =X
-
hmm...i'm not sure how to do it that way, sorry
-
Well like you were saying with the function before how would I change that to work as a function, I'm having trouble making it work that way.
-
well, it would be something like:
PHP Code:
function collDetect(obToDetect){
for(var i=0;i<lineArray.length;i++){
lineToTest = lineArray[i]
if(lineToTest.hitTest(char._x,char._y,true)){
return true
}
return false
}
then, way to add that to the movement code would be this:
PHP Code:
onEnterFrame = function(){
if(Key.isDown(Key.LEFT)){
if(!collDetect()){
//things to be moved
}
}
}
-
k i've got free time i wanna see if i can build something similar so i can add input
-
Heh slicer if you figure this out let me know, I'm very close to just giving up :(. Its so much work just to make an undo button -.-. Maybe I should look online for a whole different slope function then my own that works with created clips..
-
k here's what i came up with:
line drawer
i still have some problems with small lines but i think i have an idea how to fix it and he kinda looks weird walking on the ground anyways:
basically how i did the undo:
i have variable named cl //current line
and in the drawing line function it loops though the cl variable rather than the array length
so when i click undo button i just clear all the lines and my draw function simply...re-draws all the lines