The center of the screen (central) is positioned to a tile; decoration at the end of a tile map

Source: Internet
Author: User

(a)scrolling the isometric tilemap
With the Tileposfromlocation method updated to work with isometric tilemaps, the
TILEMAP06 Project continues by implementing isometric tilemap scrolling, using the tile
Coordinates returned from the Tileposfromlocation method. Just as in the orthogonal
Tilemap project, this was done by using the Centertilemapontilecoord method, shown in
Listing 11–3. Scrolling the screen to Center on a specific Tile coordinate

Centre (center) of the screen to locate a tile

parameter tilepos, tile coordinates; parameter Tilemap as Map

-(void) Centertilemapontilecoord: (cgpoint) Tilepos Tilemap: (cctmxtiledmap*) tilemap{//Center tilemap on the given tile Poscgsize screensize = [[Ccdirector shareddirector] winsize]; Cgpoint screencenter = Cgpointmake (screensize.width * 0.5f,screensize.height * 0.5f);//Get the ground layercctmxlayer* LA Yer = [Tilemap layernamed:@ "Ground"]; Nsassert (Layer! = nil, @ "Ground layer not found!"); /internally Tile Y coordinates is off by 1tilepos.y-= 1;//Get the pixel coordinates for a tiles at these COORDINATESCGP oint scrollposition = [Layer positionat:tilepos];//negate the position to account for scrollingscrollposition = Ccpmult (s Crollposition,-1);//Add offset to screen centerscrollposition = Ccpadd (scrollposition, screencenter);//Move the Tilemap ccaction* move = [Ccmoveto actionwithduration:0.2f position:scrollposition]; [Tilemap stopallactions]; [Tilemap Runaction:move];}

  

First, the screen center position is determined as before. Then I want to use the convenience method of the layer, Positionat, which returns a screens position for a tile coordinate. To does so, I get the Ground layer and assert that it exists. It doesn ' t matter
Which layer you use, as long as any layers use same size tiles.
Before calling the Positionat method, I has to subtract 1 from the tile Y coordinate to fix a persistent offset problem. Seasoned programmers May is worried that using a tile
Y coordinate of 0 and subtracting 1 from it could leads to an invalid index and thus a
Disastrous crash. Positionat method doesn ' t use the tile
Coordinates as indices, and it works with any tile coordinate, even negative ones.
The Positionat method returns the pixel position of the given tile coordinate within the TILEMAP and stores it in the Scrollposition vari Able. This method isn ' t specific to isometric tilemaps; It works for all Tilemap types:orthogonal, isometric, and hexagonal.
Internally, cocos2d checks which type of TILEMAP is currently being used and then uses the appropriate calculation, since They differ in profound ways. If you is interested in
The specific implementation of each of the these calculations, take a look at the methodspositionfororthoat,positionforisoat, andPositionforhexatIn the CCTMXLAYER.M implementation file.
Because the Tilemap are scrolling, in which case it would have a negative position, the scrollposition was multiplied by -1, negating it.

After that I just add the screencenter position to it and I know where to scroll to.

The move action is the same as before and moves, the tilemap so, the touched tile is centered on screen.

deserves a Better end (world map End decoration)

See P251

Due to the diamond-shaped nature of isometric tilemaps, it's inevitable that the scrolling tilemap would reveal parts Outsi De of the tilemap, as shown in Figure 11–15. Indeed, the Tileposfromlocation method ensures that the returned tile coordinate are always within
Bounds, so you can use that safely even if the player touches outside the Tilemap.

But if you don't want the player to see the end of your isometric tilemap world, you'll have a trickfor use a.

In tiled, use Map ? Resize Map ... To bring up the Resize dialog shown in Figure 11–16. You need to add ten tiles to each side
Of this tilemap to completely fill the border. Depending on the tile size, you'll have the
Experiment to find the minimum number of tiles this need to be appended.

The center of the screen (central) is positioned to a tile; decoration at the end of a tile map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.