|
-
hittest for scrolling map help please
Well I have been racking my brains off on this for what has been 2 days now and I still have not got anywhere.
Basicly what i want to happen is this.
the player presses a direction key, and the map moves in that direction (thus simulating a scrolling map) now when the character (that is constantly staying still) gets to the end of the map or hits a tree area then the map should stop scrolling but no matter what I do it just does not work.
I'll attach the FLA file but please do not steal the map. Took me ages to CG it into photoshop
Any help given will be shown on the credits once the game has been developed.
Please Help :'(
Last edited by neomaximus2k; 01-17-2008 at 10:17 AM.
-
Senior Member
Try this:
Code:
onClipEvent (load) {
s = 1;
function move(x, y) {
if (!this.hitTest(_root.hero._x-x, _root.hero._y-y, true)) {
_x += x;
_y += y;
}
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
move(0, -s);
}
if (Key.isDown(Key.DOWN)) {
move(0, s);
}
if (Key.isDown(Key.LEFT)) {
move(-s, 0);
}
if (Key.isDown(Key.RIGHT)) {
move(s, 0);
}
}
-
Thanks
Thanks, didnt think of checking it for not hit testing... would mean a slight change but that shouldnt be a problem 
Wont be able to try it out tho till the morning left my laptop at the hotel room and not back there till hte morning now
-
sadly it didnt work this is what i have now, i have the map moving and when it collides with the "wall" the player stops but then you can not move the char at all any suggestions?
fla file attached
Last edited by neomaximus2k; 01-17-2008 at 10:17 AM.
-
Senior Member
Yea, the problem is, is that once it hits something, you never tell it to move off what it is hitting. So do something like:
code: onClipEvent (load) {
s = 1;
function move(x, y) {
if (!this.hitTest(_root.hero._x-x, _root.hero._y-y, true)) {
_x += x;
_y += y;
}
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
if(this.hitTest(_root.hero._x-x, _root.hero._y-y, true)
{
_y+=s
}
else
{
move(0, -s);
}
}
if (Key.isDown(Key.DOWN)) {
if(this.hitTest(_root.hero._x-x, _root.hero._y-y, true)
{
_y-=s
}
else
{
move(0, s);
}
}
if (Key.isDown(Key.LEFT)) {
if(this.hitTest(_root.hero._x-x, _root.hero._y-y, true)
{
_x+=s
}
else
{
move(-s, 0);
}
}
if (Key.isDown(Key.RIGHT)) {
if(this.hitTest(_root.hero._x-x, _root.hero._y-y, true)
{
_x-=s
}
else
{
move(s, 0);
}
}
}
That will give your hero a little bounce in the opposite direction
-
Thanks for your help dogtown08, I managed to fix the error before you posted lol, your way would have worked but i dont like the whole "bouncing" look, this is the fix that I managed to came up with, was strange i did it whilst asleep as well. Wondering how? well was just typing away on laptop, fell asleep still typing when i woke up amongst the pages of word documment I was writing I had 2 AS scripts and this was one of them
code:
onClipEvent (load) {
b = this.getBounds(this);
s = 1;
}
onClipEvent (enterFrame) {
if (_root.map.wall.hitTest(_x+b.xMin+1, _y+b.yMin+1, false)) {
if (_root.map.wall.hitTest(_x+b.xMax-1, _y+b.yMin+1, false)) {
if (_root.map.wall.hitTest(_x+b.xMin+1, _y+b.yMax-1, false)) {
if (_root.map.wall.hitTest(_x+b.xMax-1, _y+b.yMax-1, false)) {
if (Key.isDown(Key.UP)) {
if (!_root.map.wall.hitTest(_x, _y+b.yMin/2, true)) {
_root.char.hero._rotation = 0;
_root.map._y++;
}
}
if (Key.isDown(Key.DOWN)) {
if (!_root.map.wall.hitTest(_x, _y+b.yMax/2, true)) {
_root.char.hero._rotation = 180;
_root.map._y--;
}
}
if (Key.isDown(Key.LEFT)) {
if (!_root.map.wall.hitTest(_x+b.xMin/2, _y, true)) {
_root.char.hero._rotation = 270;
_root.map._x++;
}
}
if (Key.isDown(Key.RIGHT)) {
if (!_root.map.wall.hitTest(_x+b.xMax/2, _y, true)) {
_root.char.hero._rotation = 90;
_root.map._x--;
}
}
}
}
}
}
}
Originally posted by dogtown08
Yea, the problem is, is that once it hits something, you never tell it to move off what it is hitting. So do something like:
That will give your hero a little bounce in the opposite direction
Last edited by neomaximus2k; 09-27-2004 at 09:41 PM.
-
im a fat **** and i deserve to die
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
|