masc030686
February 12th, 2009, 05:16 AM
hey i'am programing a game at the moment, but i have a problem, i can't find out how to use bitmapdata.hittest, is there someone that can explain me how to use it.
i 'am coding in a fla. file
pantas
February 12th, 2009, 09:35 AM
i 'am coding in a fla. file
thank god!
while you are at flash, why not copy that "bitmapdata.hittest", paste it in the help files and see what happens?
;)
cheers
masc030686
February 12th, 2009, 10:35 AM
this is only a little part of the code, to give you the feeling of that i'am doing.
bur it is the last 11 lines.
thank you for the help
import fl.transitions.Tween;
import fl.transitions.easing.*;
stop();
var ballc:BallC = new BallC();
var bg:BG = new BG();
var PlayerHitCentar = player1.PlayerHitCentar;
var bgmask:BGmask = new BGmask();
var MinRota:Number = 165;
var MaxRota:Number = 180;
var MaxSpeed:Number = 18;
var Deceleration:Number = .0625;
var Acceleration:Number = .125;
var DecelerationTime:Number = 2;
var RotationSpeedProperty:Number = 15;
var xMaxF:Number = 645;
var xMinF:Number = 85;
var yMaxF:Number = 280;
var yMinF:Number = 62;
var xMaxB:Number = 655;
var xMinB:Number = 75;
var yMaxB:Number = 280;
var yMinB:Number = 62;
ballc.x = 100;
ballc.y = 100;
bg.x = 0;
bg.y = 0;
player1.StoreRotation = 0;
player2.StoreRotation = 0;
player1._KeyPlayer1 = [38,40,37,39];
player2._KeyPlayer2 = [119,115,97,100];
player1.nextx=player1.x;
player1.nexty=player1.y;
player2.nextx=player2.x;
player2.nexty=player2.y;
player1.Rota = 180;
player2.Rota = 180;
player1.CurrentPic = 24;
player2.CurrentPic = 24;
player1.gotoAndStop(24);
player2.gotoAndStop(24);
player1.x = 100;
Player1HitCenter.x = 100;
player2.x = 300;
Player1HitCenter.y = 200;
player1.y = 200;
player2.y = 200;
player1.SpeedPropertyF = 0;
player2.SpeedPropertyF = 0;
player1.SpeedPropertyB = 0;
player2.SpeedPropertyB = 0;
iuint();
function iuint():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
// addChild(bg);
NewPlayer(player1);
NewPlayer(player2);
addChild(ballc);
stage.addEventListener(KeyboardEvent.KEY_DOWN, CheckKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, CheckKeyUp);
}
function NewPlayer(ref:DisplayObject):void
{
addChild(ref);
// addChild(bgmask);
}
function CheckKeyDown(e:KeyboardEvent):void
{
MovePlayer(player1,e.keyCode,player1._KeyPlayer1,p layer1.Rota,player1.CurrentPic,player1.SpeedProper tyF,player1.SpeedPropertyB,player1.onhitwallF,play er1.onhitwallB);
MovePlayer(player2,e.charCode,player2._KeyPlayer2, player2.Rota,player2.CurrentPic,player2.SpeedPrope rtyF,player1.SpeedPropertyB,player2.onhitwallF,pla yer2.onhitwallB);
}
function CheckKeyUp(e:KeyboardEvent):void
{
StopPlayer(player1,e.keyCode,player1._KeyPlayer1,p layer1.Rota,player1.CurrentPic,player1._SpeedPrope rty);
StopPlayer(player2,e.charCode,player2._KeyPlayer2, player2.Rota,player2.CurrentPic,player2._SpeedProp erty);
}
function MovePlayer(ref:DisplayObject,_CurrentKeyNumber:Num ber,_KeySet:Array,Rota:Number,CurrentPic:Number,Sp eedPropertyF:Number,SpeedPropertyB:Number,onhitwal lF:Boolean,onhitwallB:Boolean):void
{
}
function StopPlayer(ref:DisplayObject,_CurrentKeyNumber:Num ber,_KeySet:Array,Rota:Number,CurrentPic:Number,_S peedProperty:Number):void
{
}
function BallMove(e:Event):void
{
if(ballc.bitmapData.hitTest(Player1HitCenter))
{
trace("hej");
}
}
function checkCollisions():void
{
if (ref.bitmapData.hitTest(new Point(ref.nextx-player.bitmapHitOffset,ref.nexty-player.bitmapHitOffset),255,screenBitmap.bitmapDat a,new Point(screenBitmap.x,screenBitmap.y)))
{
trace("ball hit");
ref.nextx=player.x;
ref.nexty=player.y;
}
}
scottc
February 13th, 2009, 05:29 AM
Just pasting the relevant function would have been enough, also wrap your code in [ as ][ /as ] tags.
i can't find out how to use bitmapdata.hittest, is there someone that can explain me how to use it.
Do as pantas said, and look it up on livedocs.
if you have trouble understanding something in particular, then we can help you.
masc030686
February 14th, 2009, 02:51 PM
okey here is an example, of what i wan't to do, i need ball to detect when it hit ball2, i have read that when you use bitmapdata, it will detect when hit, so you don't need to, create multiple points, but just one.
the problem is that i don't now how it works, i have read, a lot, but i just can't get it to work, will you still help me thank you
stage.addEventListener(MouseEvent.MOUSE_DOWN, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, up);
function drag(e:MouseEvent)
{
ball2.startDrag();
ball2.bitmapData.hitTest(ball,0,ball,ball2,0);
}
function up(e:MouseEvent)
{
ball2.stopDrag();
}
bluemagica
February 15th, 2009, 06:31 AM
http://algorithmist.wordpress.com/2007/05/06/bitmapdatahittest/
i got that on the very first search on google...try googling a bit more and you will find more info!
masc030686
February 15th, 2009, 06:56 AM
i'am coding in as3, not as2
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.