I got a car game but when i drive the car, it can go outta my screen! What should i do to prevent that?
Please give me the script as i am a newbie and do not understand how variables worked...
thanks if you can give me the answer
Printable View
I got a car game but when i drive the car, it can go outta my screen! What should i do to prevent that?
Please give me the script as i am a newbie and do not understand how variables worked...
thanks if you can give me the answer
Hey, Tongxn.
Please take a few minutes and read through the guide sticky at the top of the forums; note especially the section on providing all necessary information for your question.
From the information you have provided, there is little that I or anyone else can do to help; is this a side-view or top-view game? what code are you using to move the car?
If you can cut and paste the code you are using, we might be able to help.
I am using the code from the turtorial Car movement from FK, but the tutorial didn't say what to do to stop the car running out of the boundary lines of the screen. someone told me to do hittest but their information's not complete either...
Anyway, i got this frontpage saying which car do u want, and then there's 4 scenes each containing a car and the background is the same. but i found out that the car just drive out of the screen and it drives me mad!
Any ideas would be appreasiated.
hello tongx think in terms of _x and _ys you dont really need hittest() for keeping your car within the screen boundaries
for left to right just check if _x is less or greater then the stage width if so stop car
for up and down check if _ y is less or greater then stage hieght if so stop car
also posting your fla or some code would be good
hope it helps
If you can understand a car script, it should be bloody easy for you to add boundaries. Here's the pseduo-script, you'll use it after the movement script:
if car's _x is more than the max x boundary,
set car's _x to max x boundary.
else if car's _x is less than min x boundary,
set car's _x to min x boundary.
if car's _y is more than the max y boundary,
set car's _y to max y boundary.
else if car's _y is less than min y boundary,
set car's _y to min y boundary.
It doesn't take an expert to figure this out. Hell, you should've been able to do it without any help if you understood the tutorial...
Alright I get the point, but how do you stop the car from moving?
If it's constantly being moved back to the furthest place it will go, it will appear as if it isn't moving at all. For instance, if it's 25 pixels away from the left border, and moves 100 pixels to the left (a bit unrealistic, but still), it gets moved back 75 pixels. Now it's right on the border. If it continues moving at that speed next frame, it will move 100 pixels left, and be pushed back 100 pixels to the right. This will happen again the next frame, and the next frame, and so on, until it changes direction.
sorry, I didn't get that, i am rubbish at guessing ASs...
Basicly, if you set boundrys to the game e.g.
where you change the numbers to whatever space you want you car to be able to drive in, then when you detect that the car has gone outside one of these boundrysCode:minX = 0
maxX = 500
minY = 0
maxY = 500
Then you can place the car ON the boundryCode:if (car._x > maxX) {
This will make it look like the car isnt moving because it all happens in 1 frame.Code:car._x = maxX
Ali
Just made a quick lil example for you (you wont get this every time you ask for help so make the most of it :p). The code is on frame 1. Ive highlighted the bit you need with coments. The rest you dont need to worry about, i thought i would just make it a bit more interesting by giving the car some simple physics :p.
Ask if you have any questions
Ali
wow man, u got that going on!
THANKS
Hey, I know! Delete the car MC and then it can't drive out of the boundries! Damn, I'm a genius...
Or a dumb spammer.Quote:
Originally Posted by bloghogger1
no, i would go with smart ass. that's A S S! not ass with some stupid stars. @$$! i can beat the system!
other options with walls:
Code:if (land.hitTest(car._x, car._y, true)) {
car.speed *= -.7;
}
no stars... wow.
no thanks, i think the original post by alillm's better
nevermind...
I must have been in a real bad mood when I posted this.
Honestly, I didn't post that. I'm guessing my friend did, seeing as how he was looking around flashkit when I was in the bathroom.
Sorry 'bout that! ;)
Never Mind.... We all need a laugh sometimes...
:P