27、游戏开发中的瓦片地图:正交与等距瓦片地图详解

游戏开发中的瓦片地图:正交与等距瓦片地图详解

1. 正交瓦片地图滚动

在游戏开发中,瓦片地图的滚动是一个重要的功能。在Tilemap04项目里,实现滚动的关键在于移动 CCTMXTiledMap 。以下是具体实现步骤:
- 获取触摸点的瓦片坐标 :在 ccTouchesBegan 方法中,先获取触摸位置,再将其转换为瓦片坐标。

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    // ... 
    // Get the position in tile coordinates from the touch location 
    CGPoint touchLocation = [self locationFromTouches:touches]; 
    CGPoint tilePos = [self tilePosFromLocation:touchLocation tileMap:tileMap]; 

    // Move tilemap so that the touched tile is at the center of the screen 
    [self centerTileMapOnTileCoord:tilePos tileMap:tileMap]; 
    // ... 
}
  • 将瓦片地图移动到触摸点的中心
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值