View Full Version : getBounds
mario_hater
February 11th, 2007, 02:53 PM
I was just testing the getBounds in flash and made a little game. The only code is on the main timeline but it does not work. Can someone tell me what i am doing wrong? The game is just supposed to stop you moving into the box movieclip.
Insane Knux
February 11th, 2007, 05:50 PM
Can I see some code? I migth be able to help if I saw some. :P
mario_hater
February 12th, 2007, 04:16 AM
yep
hit = 0;
onEnterFrame = function () {
sbounds = square.getBounds(_root);
xmax._x = sbounds.xMax;
xmin._x = sbounds.xMin;
ymax._y = sbounds.yMax;
ymin._y = sbounds.yMin;
if (Key.isDown(Key.LEFT)) {
square._rotation -= 5;
}
if (Key.isDown(Key.RIGHT)) {
square._rotation += 5;
}
if (hit == 0) {
if (Key.isDown(Key.UP)) {
square._x += Math.sin(Math.PI/180*square._rotation)*3;
square._y -= Math.cos(Math.PI/180*square._rotation)*3;
}
if (Key.isDown(Key.DOWN)) {
square._x -= Math.sin(Math.PI/180*square._rotation)*3;
square._y += Math.cos(Math.PI/180*square._rotation)*3;
}
}
if (box.hitTest(sbounds.xMax, square._y, true)) {
hit = 1;
} else {
hit = 0;
}
if (box.hitTest(sbounds.xMin, square._y, true)) {
hit = 1;
} else {
hit = 0;
}
if (box.hitTest(sbounds.yMax, square._x, true)) {
hit = 1;
} else {
hit = 0;
}
if (box.hitTest(sbounds.yMin, square._x, true)) {
hit = 1;
} else {
hit = 0;
}
};
SacrificialLamb
February 12th, 2007, 04:42 AM
What is not working. This code will not work because you have one hit, once it is triggered you will not be able to move away. Is that the only problem with the code?
try some thing like this
hit = 0;
onEnterFrame = function () {
sbounds = square.getBounds(_root);
xmax._x = sbounds.xMax;
xmin._x = sbounds.xMin;
ymax._y = sbounds.yMax;
ymin._y = sbounds.yMin;
if (Key.isDown(Key.LEFT)) {
square._rotation -= 5;
}
if (Key.isDown(Key.RIGHT)) {
square._rotation += 5;
}
if (Key.isDown(Key.UP)) {
mox = Math.sin(Math.PI/180*square._rotation)*3;
moy = -(Math.cos(Math.PI/180*square._rotation)*3);
}
if (Key.isDown(Key.DOWN)) {
mox = -(Math.sin(Math.PI/180*square._rotation)*3);
moy = Math.cos(Math.PI/180*square._rotation)*3;
}
if (box.hitTest(sbounds.xMax, square._y+moy, true)) {
hit = 1;
} else {
hit = 0;
}
if (box.hitTest(sbounds.xMin, square._y+moy, true)) {
hit = 1;
} else {
hit = 0;
}
if (box.hitTest(sbounds.yMax, square._x+mox, true)) {
hit = 1;
} else {
hit = 0;
}
if (box.hitTest(sbounds.yMin, square._x+mox, true)) {
hit = 1;
} else {
hit = 0;
}
if (hit == 0) {
square._x += mox
square._y += moy
}
};
note i have not tested this
Joppe
February 12th, 2007, 08:39 AM
Why use getBounds instead of an hitTest with shapeflag? I find it quite dumb if your not using MX< :/
nathan99
February 12th, 2007, 08:58 AM
... they are using a hitTest with shapeFlag
Joppe
February 12th, 2007, 09:08 AM
oh right, why use getBounds then? There are more effective ways of doing that :^)
mario_hater
February 12th, 2007, 11:58 AM
well i was just seeing if i could use it. And is there a way to make the square stop when it hits the box, which is a weird shape so i didnt think that i could just use a hitTest.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.