Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 01-05-2012, 07:56 PM   #1
luke40885
Registered User
 
Join Date: Jan 2012
Posts: 4
Default [AS3] scrolling road and the car help

Hi all,

I'm creating a game using flash and need some help.

The game is very basic and includes a scrolling road in which a car has to miss various obstacles ...

At the moment im as far as the scrolling road and the car that can move ... Now im stuck! "/

I want various obstacles to to appear on the road as the map scrolls but I havent got a clue where to even start! The obsacles can be stationary and just need to have a collision detection against the car ...

Any help is appreciated

thanks
luke40885 is offline   Reply With Quote
Old 01-06-2012, 02:19 AM   #2
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,332
Default

An infinitely scrolling road can be created with a loop and a BlitMask.
I tried it as an experiment today and it works pretty well.
Here's a link to the demo. If it's similar to what you're trying to do, I'll try to help you with it.
drivingGame Demo
[afz]snickelfitz is offline   Reply With Quote
Old 01-06-2012, 06:48 AM   #3
luke40885
Registered User
 
Join Date: Jan 2012
Posts: 4
Default

Hi

Yes that game is pretty much spot on , the difference being in mine that the road scrolls vertically.

All I want at the moment is for the static objects to scroll with the road then once the car hits one of them a collision occurs ... hope you can help!

Thanks
luke40885 is offline   Reply With Quote
Old 01-06-2012, 09:53 AM   #4
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,332
Default

I'll write something up later for this.

Basically, I find it impractical to create truly large scrolling panels on the stage in flash pro. So I create the panel by looping through all of the frames of a single 600x400 MovieClip in the library. Each frame is only 600x400, so it's easy to work with on the stage, and the final result after AS3 manipulation is 6000 pixels wide(!)

Long story short: each frame of the movieclip is a tile-able section of the 6000 pixel panel, including the static objects in the road.
The road itself is simply a "hole" in the movieclip; the road you see in the game is actually a background shape that shows through the hole.
I create an instance of each frame of this movieclip in a for loop and add it to the width of a Sprite. 2ms later I have the full-size panel!
ActionScript Code:
var temp:Section = new Sections(); var num:int = temp.totalFrames; var panel:Sprite = new Sprite(); for(var i:int = 0; i < temp.totalFrames; i++) {     var mc:Sections = new Sections();     mc.gotoAndStop(i+1);// if i = 0, this would be frame1     mc.x = panel.width;// this butts the sections end to end in the panel     panel.addChild(mc); } temp = null; // get rid of the temp file I used to get the totalFrames

I then assigned a BlitMask to the panel, which converts the whole thing into one large bitmap with a 600x400 mask.
(including the static objects in the road)
The content of the bitmap outside the BlitMask is totally invisible to Flash Player and is not rendered, and does not contribute to performance overhead. (performance delta is purportedly on the order of 1000% improvement, compared to a traditional mask)
ActionScript Code:
// create an instance of the blitmask; // params: target,x,y,width,height,smoothing,autoupdate,colorfill,wrap // the "wrap" parameter automatically creates infinite copies of the panel in all directions. var bm:BlitMask = new BlitMask(panel,0,0,stage.stageWidth,stage.stageHeight,true,true,0,true); bm.enableBitmapMode();// improves performance. addChild(panel);

I then create bitmapData instances from the panel and car MovieClips, then compare that pixel data in the HitTest. This resolves the problem of invisible rectangular bounding boxes for irregular objects returning false hits.
I wrap this process in a function.
ActionScript Code:
function createBitmapData():void {     carRect = car.getBounds(this);     carBmpData = new BitmapData(carRect.width,carRect.height,true,0);     carBmpData.draw(car);     panelRect = panel.getBounds(this);     panelBmpData = new BitmapData(panelRect.width,panelRect.height,true,0);     panelBmpData.draw(panel); }

The last part is the hitTest in the enter frame loop
ActionScript Code:
if (carBmpData.hitTest(new Point(car.x,car.y),255,panelBmpData,new Point(panel.x,panel.y),255)) {     // if the hitTest returns true (car hit an opaque pixel in the panel), do something, such as display "You've Crashed!" text, stop the panel, explode the car, etc... game over. } else {     // enter frame loop continues to run... panel scrolls, etc... }
Obviously there's a ton of code missing here, mostly for adding objects to the stage, tweening assets on and off the stage, and some simple logic for the score board.
[afz]snickelfitz is offline   Reply With Quote
Old 01-06-2012, 07:10 PM   #5
luke40885
Registered User
 
Join Date: Jan 2012
Posts: 4
Default

See all the road and car works fine , car moves left and right as intended it just when I add obstcles it goes wrong ..

For example I will add an obstacle to the flash library and place it on screen but the obstacle is just sitting still whilst the road scrolls underneath .... how do i stop this so the obstacle effectivley scrolls with the road and then if it connects with the car a collision occurs ...

Hope that makes sense!

Thanks
luke40885 is offline   Reply With Quote
Old 01-06-2012, 08:24 PM   #6
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,332
Default

The add the obstacle to an "obstacles" Sprite; create new bitmapData for the Sprite; Scroll the Sprite at the same rate as the road; use the Sprite bitmapData as the target for your HitTest.
[afz]snickelfitz is offline   Reply With Quote
Old 07-07-2012, 07:33 PM   #7
Oskil
Senior Member
 
Join Date: Jun 2012
Posts: 122
Default

hi,,can you give this tutorial from the start about game your demo??
help

Last edited by Oskil; 07-07-2012 at 07:42 PM.
Oskil is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:16 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.