AS3 - Finding the highest y-coordinate for a given x-coordinate in BitmapData?

和自甴很熟 提交于 2020-01-06 02:59:07

问题


I'm making a platformer. Here is what I have so far: http://megaswf.com/s/2486396 (move around and jump with arrowkeys).

I'm using the ground's bitmap data to test collisions with the player's coordinates, and the player is sinking into the ground a few pixels (especially when walking uphill). To prevent this, I want the player's y coordinate to instantly change so that the player is sitting on top of the ground. Here is what I'm working on:

    if (groundClipBmpData.hitTest(rLoc, 255, bLocFuture)) {
        playerClip.y = ???
    }

I want the player's y-coordinate to change to become the highest pixel of the groundClipBmpData at the player's x coordinate.

How can I do this?


回答1:


Like I said in the other question:

Use while instead of if

Like this:

while(groundClipBmpData.hitTest(rLoc, 255, playerClipBmpData, bLocFuture, 255))
{
        playerClip.y--;
}
playerClip.y++;

The fastest way would be to calculate and store the highest coordinate values in advance inside an array and then use the 'x' position of the player to determine the 'y' of the ground.



来源:https://stackoverflow.com/questions/12757708/as3-finding-the-highest-y-coordinate-for-a-given-x-coordinate-in-bitmapdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!