View Full Version : 2d car racing
basilisk
September 18th, 2010, 09:39 AM
Am trying to make 2d car racing game, but am stuck one problem. Am moving the BG in the game, instead of the car in x and y direction. But am not able to handle the rotation of the bg. can anybody help me with it?
The game setting is such that, The Map Sprite and the car sprite are both attached on the stage. i.e car and map, both are children of stage.
am trying to make the camera move like it is in this game http://www.flasharcade.com/arcade-games/counter-drift.html
bluemagica
September 18th, 2010, 01:45 PM
Well there are many ways to do this, you should show your code so that we can help you with your approach.
Alternatively try using Vcam, for easy camera like features.
basilisk
September 20th, 2010, 04:21 AM
ok the code is something like this:
//in car class
var car_position:rBody= new rBody()
var vel:Vector2d = new Vector2d()
// so only the position is updated in this class
// like this
position.addVel(vel)
//and u get the updated postion
//from this
var car_pos:point = position.getPosition()
//pos.x and pos.y is the car position
//and u get the rotation like this
var car_angle:Number = position.getAngle()
//in the background class.
//basically i have to use the car_pos and move the BG.
//the car sprite is placed on screen.
var _bg:Sprite = new Sprite() //assume this is a 640 X 480 box.
//so..
_bg.x = (800 / 2) - car_pos.GetPosition().x;
_bg.y = (600 / 2) - car_pos.GetPosition().y;
//so far this works fine. But am stuck at the part where i have to add rotation to the map.
//_bg.rotation = car_angle
//but when rotation comes in. it gets messed up. basically i need to transform the "car_pos" values after applying the rotation. So i guess this is my real question.
i wish i could post the entire code, but i cant.
basilisk
September 20th, 2010, 09:29 AM
I have attached a fla it shows the kind of effect i want. the only thing i want to change is this part of code(from fla).
if (kdown)
{
vy += 2;
}
var m:Matrix = _bg_mc.transform.matrix;
if (rdown)
{
var _mat:Matrix = _bg_mc.transform.matrix;
MatrixTransformer.rotateAroundInternalPoint (_mat, _pos.x,_pos.y,-3);
_bg_mc.transform.matrix = _mat;
}
if (ldown)
{
var _mat:Matrix = _bg_mc.transform.matrix;
MatrixTransformer.rotateAroundInternalPoint (_mat, _pos.x,_pos.y,3);
_bg_mc.transform.matrix = _mat;
}
vy *= .9;
_car.y += vy;
_car.x += vx;
//See how am applying vel to bg here.
_bg_mc.x += vx;
_bg_mc.y += vy;
// instead i want to be able to do this
//_bg_mc.x += _car.x;
//_bg_mc.y += _car.y;
//which creates a problem.
basilisk
September 21st, 2010, 05:18 AM
Anybody?? :)
LOLFlash
September 21st, 2010, 11:43 PM
Anybody?? :)
I did attached file take a look
basilisk
September 28th, 2010, 05:02 AM
Thanks LOLflash. i will check it out.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.