I am a novice coder, I used to use ActionScript 3.0 like 10 years ago and im trying to recode my game into javascript format. in my AS3.0 game, I had a little playable “ship” that was controlled by arrowkeys and was confined to “rivers”. The rivers were an image and AS3 had a neat function using HittestPoint to detect collisions between the player ship and the irregularly shapred rivers and I would keep the player ship confined to the rivers.
Im surprised to find out that there is no equivalently easy way to do this in javascript. My map/rivers are too irregularly shaped to use tile based collision detection and I attempted to do a pixel perfect collision detection to test if player ship overlaps the map png. but it didnt work well. Anyone have good tutorials?
function HitTest(gameObject, x, y, minAlpha = 255) {
const { texture } = gameObject;
const localPoint = gameObject.getLocalPoint(x, y);
return (
texture.manager.getPixelAlpha(
Math.floor(localPoint.x),
Math.floor(localPoint.y),
texture.key
) >= minAlpha
);
}