|
-
[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 !
-
Señor Member
Generally, this is too much to read, and only very helpful people who are in a good mood will give you a response. Unfortunately, that's not me today. I'll help you out a little, though.
To your remaining problems:
"it wasnt really teaching much because in the function name he keep writing 255 and i dont know what is it"
Whenever you don't know why something is included in a function, check the language reference. In this case, you'll want to look specifically at this. Read up on the function and hopefully you'll understand exactly why those 255s are there.
1) & 2) These are the same thing. It really depends on how realistic you want your collisions to be. You could go full out and build a physics engine (or use a pre-existing one). Or you could make assumptions based on the shapes. For a car hitting something, most people find it satisfactory to have the car reverse its direction (while cars will tend to torque around in real life, they mostly just want to go in the direction their wheels are free to spin). This can lead to more problems if you don't do it quite right, but there are dozens of tutorials available to work through that. Come back when you need help with those.
3) I don't entirely know what you mean by this. I assume you just want to have the screen focused on the player's character. In that case, have everything contained in a sprite, and when the player goes past a certain boundary (if x is greater than 400 or less than 200, for example), find out how much outside of the boundary it is, and shift the sprite in the opposite direction by that much. I'll note that for more complex scenes, this is very processor intensive. Keep that in mind.
Lastly: when your question is answered, even on another forum, mark all of the threads resolved wherever possible (like on flashkit, click on thread tools > mark thread resolved)
Haikus are easy
But sometimes they don't make sense
Refrigerator
-
first i wanna really thank you for replaying and giving me time to read my post , actully in the other fourms i think no one was in a good mood for like 3 weeks or so , but i dont know what to do with that , iam thinking about useing Classes to finish this one , its just that iam not so good in classes , but atleast i dont have to deal with BitmapObject , iam just finishing my lyinda's 7th courcse , iam still new but i learnd alot and i never heard of Bitmap thing , anyway .. i would like to take ur opinion about that , is it better idea to use classes there ? or keep trying to win with bitmap ?
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
|