@@ -1082,7 +1082,7 @@ class FlxTilemap extends FlxObject
1082
1082
}
1083
1083
1084
1084
/**
1085
- * Returns a new Flash Array full of every map index of the requested tile type.
1085
+ * Returns a new array full of every map index of the requested tile type.
1086
1086
*
1087
1087
* @param Index The requested tile type.
1088
1088
* @return An Array with a list of all map indices of that tile type.
@@ -1111,7 +1111,7 @@ class FlxTilemap extends FlxObject
1111
1111
}
1112
1112
1113
1113
/**
1114
- * Returns a new Flash Array full of every coordinate of the requested tile type.
1114
+ * Returns a new array full of every coordinate of the requested tile type.
1115
1115
*
1116
1116
* @param Index The requested tile type.
1117
1117
* @param Midpoint Whether to return the coordinates of the tile midpoint, or upper left corner. Default is true, return midpoint.
@@ -1297,9 +1297,9 @@ class FlxTilemap extends FlxObject
1297
1297
*
1298
1298
* @param Start The world coordinates of the start of the ray.
1299
1299
* @param End The world coordinates of the end of the ray.
1300
- * @param Result A Point object containing the first wall impact.
1300
+ * @param Result An optional point containing the first wall impact if there was one. Null otherwise .
1301
1301
* @param Resolution Defaults to 1, meaning check every tile or so. Higher means more checks!
1302
- * @return Returns true if the ray made it from Start to End without hitting anything. Returns false and fills Result if a tile was hit.
1302
+ * @return Returns true if the ray made it from Start to End without hitting anything. Returns false and fills Result if a tile was hit.
1303
1303
*/
1304
1304
public function ray (Start : FlxPoint , End : FlxPoint , ? Result : FlxPoint , Resolution : Float = 1 ): Bool
1305
1305
{
@@ -1323,6 +1323,9 @@ class FlxTilemap extends FlxObject
1323
1323
var tileY : Int ;
1324
1324
var i : Int = 0 ;
1325
1325
1326
+ Start .putWeak ();
1327
+ End .putWeak ();
1328
+
1326
1329
while (i < steps )
1327
1330
{
1328
1331
curX + = stepX ;
@@ -1361,12 +1364,14 @@ class FlxTilemap extends FlxObject
1361
1364
1362
1365
if ((ry > tileY ) && (ry < tileY + _scaledTileHeight ))
1363
1366
{
1364
- if (Result ! = null )
1367
+ if (Result = = null )
1365
1368
{
1366
- Result .x = rx ;
1367
- Result .y = ry ;
1369
+ Result = FlxPoint .get ();
1368
1370
}
1369
1371
1372
+ Result .x = rx ;
1373
+ Result .y = ry ;
1374
+
1370
1375
return false ;
1371
1376
}
1372
1377
@@ -1401,120 +1406,6 @@ class FlxTilemap extends FlxObject
1401
1406
return true ;
1402
1407
}
1403
1408
1404
- /**
1405
- * Works exactly like ray() except it explicitly returns the hit result. Shoots a ray from the start point to the end point.
1406
- * If/when it passes through a tile, it returns that point. If it does not, it returns null.
1407
- * Usage:
1408
- * var hit:FlxPoint = tilemap.rayHit(startPoint, endPoint);
1409
- * if (hit != null) //code ;
1410
- *
1411
- * @param Start The world coordinates of the start of the ray.
1412
- * @param End The world coordinates of the end of the ray.
1413
- * @param Resolution Defaults to 1, meaning check every tile or so. Higher means more checks!
1414
- * @return Returns null if the ray made it from Start to End without hitting anything. Returns FlxPoint if a tile was hit.
1415
- */
1416
- public function rayHit (Start : FlxPoint , End : FlxPoint , Resolution : Float = 1 ): FlxPoint
1417
- {
1418
- var Result : FlxPoint = null ;
1419
- var step : Float = _scaledTileWidth ;
1420
-
1421
- if (_scaledTileHeight < _scaledTileWidth )
1422
- {
1423
- step = _scaledTileHeight ;
1424
- }
1425
-
1426
- step / = Resolution ;
1427
- var deltaX : Float = End .x - Start .x ;
1428
- var deltaY : Float = End .y - Start .y ;
1429
- var distance : Float = Math .sqrt (deltaX * deltaX + deltaY * deltaY );
1430
- var steps : Int = Math .ceil (distance / step );
1431
- var stepX : Float = deltaX / steps ;
1432
- var stepY : Float = deltaY / steps ;
1433
- var curX : Float = Start .x - stepX - x ;
1434
- var curY : Float = Start .y - stepY - y ;
1435
- var tileX : Int ;
1436
- var tileY : Int ;
1437
- var i : Int = 0 ;
1438
-
1439
- Start .putWeak ();
1440
- End .putWeak ();
1441
-
1442
- while (i < steps )
1443
- {
1444
- curX + = stepX ;
1445
- curY + = stepY ;
1446
-
1447
- if ((curX < 0 ) || (curX > width ) || (curY < 0 ) || (curY > height ))
1448
- {
1449
- i ++ ;
1450
- continue ;
1451
- }
1452
-
1453
- tileX = Math .floor (curX / _scaledTileWidth );
1454
- tileY = Math .floor (curY / _scaledTileHeight );
1455
-
1456
- if (_tileObjects [_data [tileY * widthInTiles + tileX ]].allowCollisions != 0 )
1457
- {
1458
- // Some basic helper stuff
1459
- tileX * = Std .int (_scaledTileWidth );
1460
- tileY * = Std .int (_scaledTileHeight );
1461
- var rx : Float = 0 ;
1462
- var ry : Float = 0 ;
1463
- var q : Float ;
1464
- var lx : Float = curX - stepX ;
1465
- var ly : Float = curY - stepY ;
1466
-
1467
- // Figure out if it crosses the X boundary
1468
- q = tileX ;
1469
-
1470
- if (deltaX < 0 )
1471
- {
1472
- q + = _scaledTileWidth ;
1473
- }
1474
-
1475
- rx = q ;
1476
- ry = ly + stepY * ((q - lx ) / stepX );
1477
-
1478
- if ((ry > tileY ) && (ry < tileY + _scaledTileHeight ))
1479
- {
1480
- if (Result == null )
1481
- {
1482
- Result = FlxPoint .get ();
1483
- }
1484
-
1485
- return Result .set (rx , ry );
1486
- }
1487
-
1488
- // Else, figure out if it crosses the Y boundary
1489
- q = tileY ;
1490
-
1491
- if (deltaY < 0 )
1492
- {
1493
- q + = _scaledTileHeight ;
1494
- }
1495
-
1496
- rx = lx + stepX * ((q - ly ) / stepY );
1497
- ry = q ;
1498
-
1499
- if ((rx > tileX ) && (rx < tileX + _scaledTileWidth ))
1500
- {
1501
- if (Result == null )
1502
- {
1503
- Result = FlxPoint .get ();
1504
- }
1505
-
1506
- return Result .set (rx , ry );
1507
- }
1508
-
1509
- return null ;
1510
- }
1511
-
1512
- i ++ ;
1513
- }
1514
-
1515
- return null ;
1516
- }
1517
-
1518
1409
/**
1519
1410
* Use this method for creating tileSheet for FlxTilemap. Must be called after loadMap() method.
1520
1411
* If you forget to call it then you will not see this FlxTilemap on c++ target
0 commit comments