-
Here is the swf : http://www.hanniganpottery.com/games/1.swf
Arrows keys (except backwards) to move.
I think you will see the problem I have having quickly
THe movement for the guy checks to see if the up key is pressed and if a variable called hit in the block movie clip is set to no. If hit inside the block mc is set to yes then the movment doesn't go. THe problem is that once you hit the block you can't get out (because the variable is set to no). I need a way to put the guy just outside the block when is hits it. Here is the code for both things.
Inside the guy:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_rotation -= 5;
} else if (Key.isDown(Key.RIGHT)) {
_rotation += 5;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP) && _root.block.hit == "no") {
xx = (Math.sin((Math.PI/180)*_rotation)) * 2;
yy = Math.cos((Math.PI/180) * _rotation) * 2;
_x += xx;
_y -= yy;
}
}
ANd inside the block:
onClipEvent (enterFrame) {
if (this.hitTest(_root.guy._x, _root.guy._y, true)) {
hit = "yes";
} else {
hit = "no";
}
}
Can anyone help me with my problem? THanks in advance
-
Someone else had a problem with hitTest the other day and Mad Sci suggested changing "this.hitTest" to just "hitTest" (remove the "this.") And it apparently worked!
I have no idea why, but give it a try.
-
Oh, one small suggestion that has nothing to do with your problem.
Rather than making hit="yes" or hit="no", have hit=true or hit=false.
The string "yes" takes up 3 bytes of memory (or 24 bits). But true and false take up just 1 bit.
In your application, it won't make a bit of difference. And in reality, it probably won't make any difference in most (all?) Flash movies. But it's good programming
Keep up the good work!
-
ism
Mabey try this;
Code:
onClipEvent (enterFrame) {
if (this.hitTest(_root.guy._x, _root.guy._y, true)) {
hit = "yes";
_root.guy._x -= _root.guy.xx;
_root.guy._y += _root.guy.yy;
} else {
hit = "no";
}
}
Hope this helps!
BlinkOk
-
it's better to keep code in one place, so i wouldn't place anything in the block. try this:
Code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_rotation -= 5;
} else if (Key.isDown(Key.RIGHT)) {
_rotation += 5;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
xx = (Math.sin((Math.PI/180)*_rotation)) * 2;
yy = Math.cos((Math.PI/180) * _rotation) * 2;
if (!_root.block.hitTest(_x+xx,_y-yy, true)) {
_x += xx;
_y -= yy;
}
}
}
this checks if the guy will hit the block before he moves, and allows him to move only if he wont hit it.
Cheers
-
that Ge0rge your code worked the best. The thing i can't figure out now is how to do a multiple hittest for three (or more) different blocks. I tried using the For command but it doesn't work. Right now i am putting the hittest code all in the block and just checking for one guy, but i would like to put the code in the guy, any ideas?
-
don't need to use a loop.
you can put many blocks inside your _root.block clip and it will still work.
-
that is not true. if you add blocks to one clip, the hitTest boundaries around that clip will be the smallest rectangle around all the shapes
-
Ge0rge thats for the help everything works fine now
guyincognito, ge0rge was right because of the type of hittest i am using, if i were using the standard hittest of one mc to another it wouldn't work.
-
Who needs pants?
trampoline game already been done if u wanna check it out
go here http://www.flashkicks.co.uk/ click on games and goto trampoline game is this what u wanted ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|