|
-
[AS3]I posted THis In Many Forums , PLz Help!
Hello all , its been really long time i kept trying and trying to find an answer all over and i didn't find any :S
and i posted here my question several times On one of the forums and no one answered except one gave me some files i will share it with you , but still i keep getting error over and over each time i try something
Then i Decided to end it One time and for all ...
i decide to post the SAME Thread In Many Action-Script Fourms , by this way , i can find out My answer fast ...
so here is the deal :
----------------------
1) i made a carMC MovieClip >>> inside this movie Clip i wrote all the AS Code for the car movement and speed
**Work perfect with small bug ( i have to click on it first to activate it )
2) i made a simple Black Square and and gave its Instance name buildings_mc
and i wanted to make a function between those two to test "Hit" between them
i) all i know about that is "hittestobject();" didnt work out and some dude told me it cant work with "hittestobject" and he gave me a Link for new stament "BitMapdata" "mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/" <--- u add www
ii)i toke that link and i decided to try it out ... it wasnt really teaching much because in the function name he keep writing 255 and i dont know what is it :S , anyway .. i decided to edit it to my carMc and Buildings and made few changes and it Worked !
the Current Problem is :---
___________________
what should i write to make the flash
1)not allowing Bitmapdata(carMC) to move on buildings_mc or under it
2)Record the Hit angle .. and respond to the hit by reflecting it ( like real )
3)how to make the Machine able to move on display only not outside it
>>or how to make it inside a square and can't leave it
------------------------------------
if u can answer Even one of those i will be very thankful
My Courent Scene Code !
code:
addEventListener(Event.ENTER_FRAME, enterFrame);
function enterFrame(e:Event):void
{
var blueRect:Rectangle = carMC.getBounds(this);
var blueOffset:Matrix = carMC.transform.matrix;
blueOffset.tx = carMC.x - blueRect.x;
blueOffset.ty = carMC.y - blueRect.y;
var carMCBmpData = new BitmapData(blueRect.width, blueRect.height, true, 0);
carMCBmpData.draw(carMC, blueOffset);
var redRect:Rectangle = buildings_mc.getBounds(this);
var buildings_mcBmpData = new BitmapData(redRect.width, redRect.height, true, 0);
var redOffset:Matrix = buildings_mc.transform.matrix;
redOffset.tx = buildings_mc.x - redRect.x;
redOffset.ty = buildings_mc.y - redRect.y;
buildings_mcBmpData.draw(buildings_mc, redOffset);
var rLoc:Point = new Point(redRect.x, redRect.y);
var bLoc:Point = new Point(blueRect.x, blueRect.y);
if(buildings_mcBmpData.hitTest(rLoc,
255,
carMCBmpData,
bLoc,
255
))
{
buildings_mc.filters = [new GlowFilter()];
}
else
{
buildings_mc.filters = [];
}
carMCBmpData.dispose();
buildings_mcBmpData.dispose();
}
The Code good Dude Gave me on some Forums
code: var up:Boolean=false;
var down:Boolean=false;
var left:Boolean=false;
var right:Boolean=false;
var total_hurdle:Number=4;
var hitted:Boolean=false;
var currentX:Number=0;
var currentY:Number=0;
stage.addEventListener(KeyboardEvent.KEY_DOWN,key_ pressed);
stage.addEventListener(KeyboardEvent.KEY_UP,key_re leased);
addEventListener(Event.ENTER_FRAME, onStage);
ball_mc.cacheAsBitmap=true;
function key_pressed(e:KeyboardEvent):void {
switch (e.keyCode) {
case Keyboard.UP :
up=true;
break;
case Keyboard.DOWN :
down=true;
break;
case Keyboard.LEFT :
left=true;
break;
case Keyboard.RIGHT :
right=true;
break;
}
}
function key_released(e:KeyboardEvent):void {
switch (e.keyCode) {
case Keyboard.UP :
up=false;
break;
case Keyboard.DOWN :
down=false;
break;
case Keyboard.LEFT :
left=false;
break;
case Keyboard.RIGHT :
right=false;
break;
}
}
function onStage(e:Event):void
{
if (up) {
ball_mc.y-=8;
}
if (down) {
ball_mc.y+=8;
}
if (left) {
ball_mc.x-=8;
}
if (right) {
ball_mc.x+=8;
}
if (ball_mc.x>stage.stageWidth) {
ball_mc.x=0;
}
if (ball_mc.x<0) {
ball_mc.x=stage.stageWidth-1;
}
if (ball_mc.y>stage.stageHeight) {
ball_mc.y=0;
}
if (ball_mc.y<0) {
ball_mc.y=stage.stageHeight-1;
}
if (checkStatus()) {
ball_mc.x=currentX;
ball_mc.y=currentY;
}
currentX=ball_mc.x;
currentY=ball_mc.y;
checkStatus();
}
function checkStatus():Boolean {
for (var i:Number = 1; i <= total_hurdle; i++)
{
var obstracle isplayObject=getChildByName("obstracle"+i+"_mc");
if (ball_mc.hitTestObject(obstracle)) {
hitted=true;
break;
} else {
hitted=false;
}
}
if (hitted)
{
return true;
} else {
return false;
}
}
I tried to Mix those two but OMG i cant take it anymore with those Errors!!!!
i tried to copy .. edit it , " probably i did it wrong but still i tried allooottt , "
Finally i thank you all for reading that , and i reall appreciate if u even thinking about helping me , please if u can , just do it ... i already post this on more than one forums to find the answer as fast as possible
thank you !
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
|