开发者

CALayer obstacles?

I am pu开发者_如何学编程tting together a 2d RPG in Cocoa just for learning and for fun.

I've got the sprite moving around and animating just fine... but not sure how to approach making obstacles. Take for example Mt. Zozo here. I don't want Setzer falling off a cliff, or climbing up on those dangerous looking rocks!

CALayer obstacles?

I was thinking that I might have to draw in some layers where I don't want him to move and put some code in my move keydown methods that test that the resulting position doesn't contain a point that is also contained by an 'obstacle' layer. But that seems really not generic and a lot of work.

Any thoughts?

Thanks!


In the end, pretty simple.

Remember that I am using a 32x32 px grid for sprite movement.

Just put down layers wherever you don't want the character to move, and then when adding possible the movement tiles, test if the position of the movement tile is the same as the obstacle.

    if (upOne.position.x == obstacle.position.x && upOne.position.y == obstacle.position.y)
    upOne.hidden = YES;

I tried using contains point but that was problematic. Anyways, this worked :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜