<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Topic: TMXTileMap isometric zOrder ad-hoc sprite issue</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/4348</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 02:14:25 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/topic/4348" rel="self" type="application/rss+xml" />

		<item>
			<title>huika on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55464</link>
			<pubDate>Fri, 17 Sep 2010 00:58:18 +0000</pubDate>
			<dc:creator>huika</dc:creator>
			<guid isPermaLink="false">55464@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Ok thanks :)
</p></description>
		</item>
		<item>
			<title>itlgames on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55460</link>
			<pubDate>Fri, 17 Sep 2010 00:09:01 +0000</pubDate>
			<dc:creator>itlgames</dc:creator>
			<guid isPermaLink="false">55460@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>For vertical speed you mean like jumping or going up right? In that case yes, I have vertical speed half the horizontal speed.
</p></description>
		</item>
		<item>
			<title>huika on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55455</link>
			<pubDate>Thu, 16 Sep 2010 23:34:50 +0000</pubDate>
			<dc:creator>huika</dc:creator>
			<guid isPermaLink="false">55455@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/7055'>itlgames</a><br />
Thank you : )<br />
I'll begin posting youtube videos of the development process soon.</p>
<p>I would like to ask something:<br />
When moving a character in a isometric map, the vertical speed is half the horizontal one?<br />
I'm asking this because as the height of a tile is half of it's width in many cases, it would make sense to give the illusion of depth to make the character has less speed moving vertically, do you agree?
</p></description>
		</item>
		<item>
			<title>itlgames on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55451</link>
			<pubDate>Thu, 16 Sep 2010 22:52:15 +0000</pubDate>
			<dc:creator>itlgames</dc:creator>
			<guid isPermaLink="false">55451@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>That looks great! Good luck with your game, let us know once is done!
</p></description>
		</item>
		<item>
			<title>huika on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55446</link>
			<pubDate>Thu, 16 Sep 2010 21:38:25 +0000</pubDate>
			<dc:creator>huika</dc:creator>
			<guid isPermaLink="false">55446@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>This is a game I've done a long time ago, it was made using Game maker Lol :)</p>
<p><a href="http://www.youtube.com/watch?v=paa_3VBJvFI" rel="nofollow">http://www.youtube.com/watch?v=paa_3VBJvFI</a></p>
<p>It's that kind of game I'll try to develop in Cocos2d.<br />
The tile system can handle this, and using box2d I'm able to handle collision and that sort of things.
</p></description>
		</item>
		<item>
			<title>itlgames on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55443</link>
			<pubDate>Thu, 16 Sep 2010 21:06:12 +0000</pubDate>
			<dc:creator>itlgames</dc:creator>
			<guid isPermaLink="false">55443@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Yeah, I've seen that example before, note the character when jumps from behind a block, you see the glitch? To be honest I have spent sooo much time working on the perfect isometric ordering algorithm to realise it's impossible to get something perfect, so it will really depend of your game, where it is noticeable those glitchs or not, and what you can compromise.</p>
<p>In my case was very obvious and I needed something good enough, what I do is, first order all elements assuming all are in same height (or altitude), using the y screen position, then I order by altitude all objects that collide when in same height, that kind of works but it's pretty CPU intensive if you have lot of objects in different altitudes.</p>
<p>See this guy:</p>
<p><a href="http://www.youtube.com/watch?v=fonxgvz35Y4" rel="nofollow">http://www.youtube.com/watch?v=fonxgvz35Y4</a></p>
<p>It seems to work pretty good, but I guess he is using same tile size for all objects, something I wanted to avoid.</p>
<p>For the interaction on my game I didn't use box2d so again had to do from scratch, works fine, to be honest all interaction/physics/collisions... I do is in map coordinates, not screen coordinates, for example all objects are suppose to be enclosed in a 3d rectangle, so they all have a rectangle base, if you project that on a map coordinates, it's all 90 degrees, so it's easy to calculate collision between two rectangles.
</p></description>
		</item>
		<item>
			<title>huika on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55442</link>
			<pubDate>Thu, 16 Sep 2010 20:39:08 +0000</pubDate>
			<dc:creator>huika</dc:creator>
			<guid isPermaLink="false">55442@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/7055'>itlgames</a><br />
Hy there! I've been following your work for some time by now! :) What most impresses me in your game is the interaction of the character with the objects in different height levels :)</p>
<p>About the z sorting using height, i'm thinking on using something like:<br />
<pre><code>[myActor setVertexZ: (-(myActor.position.y))/32];</code></pre>
<p>and with the "myActor" position itself, something like: </p>
<pre><code>myActor.sprite.position.y = myActor.position.y + myActor.fakez;</code></pre>
<p>Do you think it works?</p>
<p>The worst case scenario we can get is using sprites with x much bigger than y (in iso) like the purple block in your example, because it's zdepth center wont be precise in all cases, know what I mean?</p>
<p>For now what I'll try to reach is a game like diablo, something more click 'n kill Lol :) and wont be considering height variation in character movement.</p>
<p>This example really amazed me: <a href="http://www.youtube.com/watch?v=Fli3725M7UE&#038;feature=related" rel="nofollow">http://www.youtube.com/watch?v=Fli3725M7UE&#038;feature=related</a><br />
I've seen it's possible to use a buffer to access height map of the tiles to simulate character getting in high places, but I don't believe it's gonna be a accessible road for me. I'm a 3d generalist, learned programming not too long ago, so I'm just beginning.
</p></description>
		</item>
		<item>
			<title>itlgames on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55439</link>
			<pubDate>Thu, 16 Sep 2010 20:19:26 +0000</pubDate>
			<dc:creator>itlgames</dc:creator>
			<guid isPermaLink="false">55439@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/18328'>huika</a> that looks good, I have some experience with isometric games and I can tell that ordering iso tiles/objects all in same level (so no heights) and with same tile size, it's fairly easy. I found the best way is to use the screen y position (not iso map position), so the close to the bottom of the screen, the close to the camera. You can also use the x and y map position (so iso coordinates) but I found the other way more easy.</p>
<p>But if you start using map heights, so objects can be in different altitudes, objects on top of another... that gets tricky, there is no perfect ordering algorithm. On my game, I don't even have all objects with same tile size and that complicates the thing, I can have any sort of sizes, objects in any altitude, objects piled, and it looks nearly perfect, but still there are some situations where it's impossible to do the ordering, like this one, where it is impossible to order:</p>
<p><img src="http://www.itlgames.com/2d_isometric_issue.gif" alt="" /></p>
<p>Here a sample of my working engine:</p>
<p><img src="http://www.itlgames.com/demo1.jpg" alt="" /></p>
<p>I have to say I didn't use tile map cocos2d support as I started my game before Riq introduced this featured. Also have to say my ordering algorithm is rather complex, works in mostly all situations, but it has a CPU cost, but still, I can have a few dozen objects on screen with decent fps.
</p></description>
		</item>
		<item>
			<title>huika on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-55424</link>
			<pubDate>Thu, 16 Sep 2010 17:22:47 +0000</pubDate>
			<dc:creator>huika</dc:creator>
			<guid isPermaLink="false">55424@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi there!<br />
Just wanted to post some tests I've been doing following all the info we can get access from this post.</p>
<p>All those are captures from my iPad, the first two scaling to 0.5 the layer, and the last ones are in 100% scale.</p>
<p>As you can see, the ordering is working very well and is even possible to combine "walls" using this method. Also the performance is really good, considering that all the 100 spheres have box2d physics affected by accelerometer and all the 200 walls ( most are not on screen )  have  static colliders.</p>
<p><a href="http://h.imagehost.org/view/0459/Screenshot01"><img src="http://h.imagehost.org/t/0459/Screenshot01.jpg" alt="Screenshot01.jpg (127 KB)" /></a></p>
<p><a href="http://i.imagehost.org/view/0470/Screenshot02"><img src="http://i.imagehost.org/t/0470/Screenshot02.jpg" alt="Screenshot02.jpg (163 KB)" /></a></p>
<p><a href="http://a.imagehost.org/view/0770/Screenshot03"><img src="http://a.imagehost.org/t/0770/Screenshot03.jpg" alt="Screenshot03.jpg (194 KB)" /></a></p>
<p><a href="http://i.imagehost.org/view/0575/Screenshot04"><img src="http://i.imagehost.org/t/0575/Screenshot04.jpg" alt="Screenshot04.jpg (190 KB)" /></a></p>
<p>Hope it's a good new for people still wondering to create isometric games :)<br />
See ya!
</p></description>
		</item>
		<item>
			<title>huika on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-54883</link>
			<pubDate>Mon, 13 Sep 2010 03:48:06 +0000</pubDate>
			<dc:creator>huika</dc:creator>
			<guid isPermaLink="false">54883@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi there! First I would like to thank everyone, you already helped me a lot with all the posts about isometric tiles and z ordering.</p>
<p>I have 2 questions that I still didn't found an answer:</p>
<p>In my tests I've subclassed a CCLayer and in this subclass I've included an CCSpriteSheet using this in implementation (just posted the important part)</p>
<pre><code>@implementation characterLayer

- (id) init

{

	self = [super init];

	if (self != nil)
	{

		//CGSize winSize = [[CCDirector sharedDirector] winSize];

		// Create a SpriteSheet -- just a big image which is prepared to
        // be carved up into smaller images as needed
        CCSpriteSheet *BastSheet = [CCSpriteSheet spriteSheetWithFile:@&#34;BastRotation.pvr&#34; capacity:20];

        // Add sprite sheet to parent (it won&#39;t draw anything itself, but
        // needs to be there so that it&#39;s in the rendering pipeline)
        [self addChild:BastSheet];

		// Load sprite frames, which are just a bunch of named rectangle
        // definitions that go along with the image in a sprite sheet
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@&#34;BastRotation.plist&#34;];

		// Finally, create a sprite, using the name of a frame in our frame cache.
        BastSprite = [CCSprite spriteWithSpriteFrameName:@&#34;defend_0.png&#34;];
		//BastSprite.position = ccp(winSize.width/2, winSize.height/2);

        // Add the sprite as a child of the sheet, so that it knows where to get its image data.
        [BastSheet addChild:BastSprite];

		NSMutableArray *walkAnimFrames = [NSMutableArray array];
		for(int i = 0; i &#60;= 7; ++i)
		{
			[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@&#34;defend_%d.png&#34;, i]]];
		}

		CCAnimation *walkAnim = [CCAnimation animationWithName:@&#34;walk&#34; delay:0.1f frames:walkAnimFrames];
		CCAction *walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
		[BastSprite runAction:walkAction];

	}

	return self;

}

-(void)dealloc
{

	//[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
	[super dealloc];
}

@end</code></pre>
<p>after that, in the main gameScene I'm working on, I'm instantiating the new class I've created.<br />
Everything is working fine, I'm being able to use</p>
<pre><code>characterLayer *bastChar = [characterLayer node];
bastChar.position = ccp(0,-100);
[self addChild:bastChar];
[bastChar setVertexZ: (-bastChar.position.y + 80)/32];</code></pre>
<p>Even the Z depth is working, but I would like to ask:<br />
1 - The fact that I'm using the SpriteSheet inside an "CCLayer" subclass, and then instancing this CCLayer subclass is going to break down the performance of one draw call, or I still get this benefit?</p>
<p>2 - using " CCSpriteSheet *BastSheet = [CCSpriteSheet spriteSheetWithFile:@"BastRotation.pvr" capacity:20]; " inside the subclass is going to generate one spriteSheet for each instance of this subclass I create, or all of them are going to reuse the same one?</p>
<p>Thanks a lot for all the help!</p>
<p>I really looked in many topics, but still wasn't abe to get those 2 questions answered.
</p></description>
		</item>
		<item>
			<title>Nat Weiss on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-30568</link>
			<pubDate>Wed, 17 Mar 2010 21:20:57 +0000</pubDate>
			<dc:creator>Nat Weiss</dc:creator>
			<guid isPermaLink="false">30568@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq: Tried your idea of subclassing CCSprite with fresh copies of 0.99.1-rc and r1866 and it works great! Here's the subclass:</p>
<pre><code>@implementation CCZSprite

	-(void) draw
	{
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.0f);

		[super draw];

		glDisable(GL_ALPHA_TEST);
	}

@end</code></pre>
<p>Notes:<br />
 * Am no longer calling <code>[[CCDirector sharedDirector] setDepthTest:YES];</code><br />
 * Appropriate foreground layers use <code>cc_vertexz=automatic</code> set in Tiled<br />
 * Other background layers get a <code>vertexZ</code> manually like this:<br />
<pre><code>if(![[layer propertyNamed:@&#34;cc_vertexz&#34;] isEqualToString:@&#34;automatic&#34;])
			[layer setVertexZ:-1000.0f + layerCount];</code></pre>
<p>@<a href='http://www.cocos2d-iphone.org/forum/profile/6781'>matsebc</a>: A solution to the edge pixels of your sprites is to create an empty layer in Tiled below everything else. That way the edge pixels are blended with black and it looks ok. You can try playing with the <code>glAlphaFunc(GL_GREATER, 0.0f)</code> value if you don't like black edge pixels.
</p></description>
		</item>
		<item>
			<title>riq on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-29188</link>
			<pubDate>Mon, 08 Mar 2010 13:12:56 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">29188@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/6781'>matsebc</a>: Are you using a custom alpha test function ? or did you modify the the alpha blend func ? which SVN revision are you using ?
</p></description>
		</item>
		<item>
			<title>matsebc on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-29142</link>
			<pubDate>Mon, 08 Mar 2010 05:26:06 +0000</pubDate>
			<dc:creator>matsebc</dc:creator>
			<guid isPermaLink="false">29142@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Following Riqs recomendation I am posting a screenshot of the issue I am having, as you can see the character that has a dynamic vertexZ order shows a small hallo of the actual lowest layer around it, I am not sure why the sprite is blending with the lowest layer instead of doing so with the layer right below it, any tips, appreciated!<br />
BTW I am not sure how to embed an image.</p>
<p><img src="http://i50.tinypic.com/111umqg.png" />
</p></description>
		</item>
		<item>
			<title>matsebc on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28399</link>
			<pubDate>Mon, 01 Mar 2010 19:33:50 +0000</pubDate>
			<dc:creator>matsebc</dc:creator>
			<guid isPermaLink="false">28399@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey guys just to chim in, things are working fine here as well with the settings I managed to recoup from this post, also worth notting that I am getting as well a bottom layer silouette around my hero (and other bugs as well as those are vertexz enabled).<br />
bullets, have you found any solution to that?
</p></description>
		</item>
		<item>
			<title>Nat Weiss on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28261</link>
			<pubDate>Sun, 28 Feb 2010 01:02:57 +0000</pubDate>
			<dc:creator>Nat Weiss</dc:creator>
			<guid isPermaLink="false">28261@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq: it works!</p>
<p>Will try re-getting the latest codebase (to clean out anything I did), subclassing the draw methods, and post the results.
</p></description>
		</item>
		<item>
			<title>Metric on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28251</link>
			<pubDate>Sat, 27 Feb 2010 21:42:32 +0000</pubDate>
			<dc:creator>Metric</dc:creator>
			<guid isPermaLink="false">28251@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq: Ah yeah, I see what you mean about the semi transparent issue. I have a feeling that you are right about bullets issue. Most likely, he wasn't enabling GL_ALPHA_TEST on his character sprite and thus it wasn't rendering properly with the tiles.</p>
<p>Also, like riq said it probably would be best to subclass CCSprite and override the draw, to include the GL_ALPHA_TEST. That way you can enable GL_ALPHA_TEST only on the sprites / objects / layers that need it.
</p></description>
		</item>
		<item>
			<title>riq on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28227</link>
			<pubDate>Sat, 27 Feb 2010 17:22:18 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">28227@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/26'>Metric</a>: I tried with your solution, but it is not working for the "TMX iso vertexz" example.</p>
<p>This is how it looks following your suggestions:<br />
<img src="http://lh5.ggpht.com/_7Tp7oCOlWFE/S4lPR2z8iPI/AAAAAAAAZ6c/4gJeqm6G0a0/s288/Screen%20shot%202010-02-27%20at%2008.36.14.png" /></p>
<p>This is how it looks following your suggestions, but instead of using GL_GREATER=0, it uses GL_GREATER=0.5<br />
<img src="http://lh6.ggpht.com/_7Tp7oCOlWFE/S4lPUJXgKWI/AAAAAAAAZ6k/__yu_RLIXcY/s288/Screen%20shot%202010-02-27%20at%2013.21.53.png" /></p>
<p>This is happening because some tiles (like the trees) have semi-transparent parts.</p>
<p>@<a href='http://www.cocos2d-iphone.org/forum/profile/6224'>bulletsburning</a>: Could you try removing the glBlend() functions from the director.</p>
<p>Instead of this:<br />
<pre><code>// makes vertexZ work {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.0f);
		// }</code></pre>
<p>Just add this:<br />
<pre><code>// makes vertexZ work {
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.0f);
		// }</code></pre>
<p>If it works, then I think that I know why it wasn't working for you.<br />
If it doesn't, then I'm totally lost.</p>
<p>Explanation:<br />
<code>GL_ALPHA_TEST</code> was only enabled on the <code>TMXLayer</code> but since your sprite wasn't part of the <code>TMXLayer</code>, it wasn't rendered using <code>GL_ALPHA_TEST</code>.  Since you are enabling GL_ALPHA_TEST globally, then everything you draw uses GL_ALPHA_TEST, including your sprite and the tmxlayer.</p>
<p>Possible solutions:<br />
 - You could leave the GL_ALPHA_TEST on the director, but this will slow down a little bit your game. GL_TEST_ALPHA should only be used when it is strictly needed (well, at least according the the iPhone guidelines).<br />
 - The other alternative is to only draw the images that needs GL_TEST_ALPHA. For example, the HUD doesn't need the GL_TEST_ALPHA. To do so, you can subclass sprite and override draw (see TMXLayer), and also, the TMXLayer#<a href='http://www.cocos2d-iphone.org/forum/tags/draw'>draw</a> should be uncommented.
</p></description>
		</item>
		<item>
			<title>Metric on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28219</link>
			<pubDate>Sat, 27 Feb 2010 16:08:53 +0000</pubDate>
			<dc:creator>Metric</dc:creator>
			<guid isPermaLink="false">28219@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@bullet: Great! I had a feeling that would work, because that is what eventually worked for me in the IsoTileMapTest project that I created.
</p></description>
		</item>
		<item>
			<title>Nat Weiss on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28192</link>
			<pubDate>Sat, 27 Feb 2010 04:11:40 +0000</pubDate>
			<dc:creator>Nat Weiss</dc:creator>
			<guid isPermaLink="false">28192@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/26'>Metric</a>: it works like a charm!</p>
<p><img src="http://nmw.fm/wp-content/uploads/2010/03/5.png" /><br />
High five to Metric</p>
<p>Interesting note. The edge pixels of the hero character now show the bottom-most TMX layer.<br />
<img src="http://nmw.fm/wp-content/uploads/2010/03/6.png" /><br />
Border pixels showing a few black empty tiles and a bit of sand tiles</p>
<p>I tried messing with the <code>glAphaFunc(GL_GREATER, ...)</code> function's 2nd argument with <code>0.01f</code> and <code>0.5f</code>. Kind of made it worse. Then I realized an easy fix: just create a black empty layer as the bottom-most layer. If any pixels "show through" they will just be black. This actually creates a pleasant "cartooney" feel.</p>
<p>Notes:<br />
1. Only change necessary to the app delegate code was: <code>[[CCDirector sharedDirector] setDepthTest:YES];</code><br />
2. The projection is <code>CCDirectorProjection2D</code> (set after attaching to window). The alpha pixel format can be <code>kTexture2DPixelFormat_RGBA4444</code> or <code>kTexture2DPixelFormat_RGBA8888</code>.<br />
2. The CCDirector's <code>setDepthTest</code> looks like this:<br />
<pre><code>- (void) setDepthTest: (BOOL) on
{
	if (on) {
		glClearDepthf(1.0f);
		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LEQUAL);

		// makes vertexZ work {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.0f);
		// }

		glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	} else
		glDisable( GL_DEPTH_TEST );
}</code></pre>
<p>3. The draw method of <code>CCTMXLayer</code> is commented out now.<br />
4. It works beautifully with my existing levels that have around 8 or 9 layers. I just add a bottom black layer.<br />
5. It works fine even for setting the vertexZ of a CCNode-derived Player object which is a child of the CCTMXTiledMap and has a child "hero" sprite and a life-bar sub-sprite which fades in and out. So all of the player's effects are drawn behind or in front of the world at once.
</p></description>
		</item>
		<item>
			<title>Metric on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28190</link>
			<pubDate>Sat, 27 Feb 2010 03:31:10 +0000</pubDate>
			<dc:creator>Metric</dc:creator>
			<guid isPermaLink="false">28190@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@bullet: could you please try this and see if it does anything different:</p>
<p>remove the following from the draw in CCTMXLayer.m for right now:</p>
<pre><code>if( useAutomaticVertexZ_ ) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glEnable(GL_ALPHA_TEST);
		if( CCRANDOM_0_1() &#60; 0.2f )
		{
			NSLog(@&#34;Trying %.3f&#34;, __f);
			__f = CCRANDOM_0_1();
		}
		glAlphaFunc(GL_GREATER, __f);
	}</code></pre>
<p>Then go into CCDirector.m and go down to the method setDepthTest.</p>
<p>Between glDepthFunc() and glHint() in setDepthTest put:</p>
<pre><code>glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

                glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.0f);</code></pre>
<p>Next in your appdelegate where you initialize the cocos2d engine add these in this order or modify your code to have these settings:</p>
<p>`<br />
	// Use RGBA_8888 buffers<br />
	// Default is: RGB_565 buffers<br />
	[[CCDirector sharedDirector] setPixelFormat:kPixelFormatRGBA8888];</p>
<p>	// Default texture format for PNG/BMP/TIFF/JPEG/GIF images<br />
	// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565<br />
	// You can change anytime.<br />
	[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];</p>
<p>[[CCDirector sharedDirector] setProjection:CCDirectorProjection3D];<br />
[[CCDirector sharedDirector] setDepthBufferFormat:kDepthBuffer24];<br />
[[CCDirector sharedDirector] setDepthTest:YES];
</p></description>
		</item>
		<item>
			<title>Nat Weiss on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28186</link>
			<pubDate>Sat, 27 Feb 2010 03:05:14 +0000</pubDate>
			<dc:creator>Nat Weiss</dc:creator>
			<guid isPermaLink="false">28186@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq: Can I solve it for now using a custom ALPHA_TEST value? If so, how?</p>
<p>I tried the following code for CCTMXLayer's draw:<br />
<pre><code>static float __f = 0.0f;

-(void) draw
{
	if( useAutomaticVertexZ_ ) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glEnable(GL_ALPHA_TEST);
		if( CCRANDOM_0_1() &#60; 0.2f )
		{
			NSLog(@&#34;Trying %.3f&#34;, __f);
			__f = CCRANDOM_0_1();
		}
		glAlphaFunc(GL_GREATER, __f);
	}

	[super draw];

	if( useAutomaticVertexZ_ )
		glDisable(GL_ALPHA_TEST);
}</code></pre>
<p>It still shows the bottom most layer no matter what the value of glAlphaFunc(GL_GREATER, ...). Also tried setting it to 1.0f, 0.5f, and 0.999f manually.</p>
<p><img src="http://nmw.fm/wp-content/uploads/2010/03/4.png" /><br />
Screenshot with a bottom most layer like a checkerboard of empty and sand tiles.</p>
<p>Interesting to note it does make some of the edge pixels flicker on the rock layer (the one with cc_vertexz automatic). Does this have anything to do with the format of my PNG files? I'm using 8-bit PNGs exported with Adobe Photoshop CS4's "Save for Web &#38; Devices" command for both the hero and the tilesets. I'm using RGBA_4444 as the Texture2D pixel format.
</p></description>
		</item>
		<item>
			<title>riq on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28171</link>
			<pubDate>Sat, 27 Feb 2010 00:27:43 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">28171@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/26'>metric</a>: alpha blending is enabled by default in cocos2d. The default blend func is GL_ONE, GL_ONE_MINUS_SRC_ALPHA.<br />
If the image is not premultiplied, then it uses GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA.</p>
<p>I guess @bullets has the same issue that can be triggered in example #<a href='http://www.cocos2d-iphone.org/forum/tags/4'>4</a>: "TMX Ortho Vertex Z" (test/TileMapTest.m)<br />
I tried using forcing GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA, but I obtained the same results.</p>
<p>The problem seems to be when the tiles have an alpha value between 0 and 1, like 0.5. If the tiles are either 100% opaque or 0% opaque, then it works OK, but if tiles are 50% opaque, then you can trigger this issue.</p>
<p>I solved it using a custom ALPHA_TEST value. It might not be the best solution... I'm rather new with GL_ALPHA_TEST, but it worked for this particular case.</p>
<p>What do you suggest ?
</p></description>
		</item>
		<item>
			<title>Metric on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/3#post-28167</link>
			<pubDate>Fri, 26 Feb 2010 23:15:51 +0000</pubDate>
			<dc:creator>Metric</dc:creator>
			<guid isPermaLink="false">28167@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq and bullets: It isn't the glAlphaFunc causing the issue, but instead a blending issue of alpha transparency.</p>
<p>If you notice in my TileMapTest project in CCDirector.m under setDepthTest I enable GL_BLEND first and set the glBlendFunc. Basically the following:</p>
<p>glEnable(GL_BLEND);<br />
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);</p>
<p>Then I enable the glAlpha with:</p>
<p>glEnable(GL_ALPHA_TEST);<br />
glAlphaFunc(GL_GREATER, 0.0f);</p>
<p>Enabling both the glBlend with the above and the glAlpha with the above settings fixes the alpha and blending clipping issue when using the depth buffer. Even opengl documents recommend you use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) for proper blending of alpha transparencies.</p>
<p>Thus just goto the same file riq mentioned above and add:<br />
glEnable(GL_BLEND);<br />
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);</p>
<p>Before glAlphaFunc / enable.</p>
<p>That should fix the issue, at least it did for me when testing the IsoMap layering with a hero object.
</p></description>
		</item>
		<item>
			<title>riq on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/2#post-28154</link>
			<pubDate>Fri, 26 Feb 2010 20:27:11 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">28154@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@bullterburning:<br />
Look at CCTMXLayer.m, line #628.</p>
<pre><code>// line 628
		glAlphaFunc(GL_GREATER, 0.0f);</code></pre>
<p>and modify it with:<br />
<pre><code>glAlphaFunc(GL_GREATER, 0.5f);</code></pre>
<p>If it doesn't work, try with different values from 0 to 0.999.<br />
Let me know if it works.
</p></description>
		</item>
		<item>
			<title>Nat Weiss on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/2#post-28137</link>
			<pubDate>Fri, 26 Feb 2010 18:01:41 +0000</pubDate>
			<dc:creator>Nat Weiss</dc:creator>
			<guid isPermaLink="false">28137@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks to @<a href='http://www.cocos2d-iphone.org/forum/profile/26'>metric</a> and @riq for their work on getting the vertexZ solution rolling. I am running into a transparency issue using r1828.</p>
<p>Whenever my hero character gets close to a tile with cc_vertexz automatic his "transparent" pixels override the correct tile and show the bottom-most TMX layer. Screenshots:</p>
<p><img src="http://nmw.fm/wp-content/uploads/2010/03/1.png" /><br />
Working ok.</p>
<p><img src="http://nmw.fm/wp-content/uploads/2010/03/2.png" /><br />
In the above screenshot the hero's vertexZ is -6.44 and the vertexZ of the rock directly above him is -7. There are only two tile layers in the orthogonal TMX, the ground "grass" layer with cc_vertexz -1000 and the rock layer with cc_vertexz automatic. There is an object layer with the player's start position above the rock layer.</p>
<p>Why am I getting this transparency issue?</p>
<p>I've tried it in the simulator, on the device, with different depth buffer bit sizes, using different alpha pixel formats, and using different PNG file bit depths for my hero character, but I always get this transparency issue. By the way, yes, my hero character's sprite is a child of the TMX map object.</p>
<p>I remember @riq saying something about how this wouldn't work with sprites that are not completely opaque. Does this mean we can't use vertexZ with partially transparent sprites? Or is there something I am doing wrong in the code? Please point me in the right direction to solving this.</p>
<p>Note that the pixels that are displayed in the hero's transparent areas are always the bottom-most TMX layer, regardless of cc_vertexz value. For example, if I create one more empty layer below the ground/grass layer it will look like this:</p>
<p><img src="http://nmw.fm/wp-content/uploads/2010/03/3.png" />
</p></description>
		</item>
		<item>
			<title>riq on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/2#post-27752</link>
			<pubDate>Tue, 23 Feb 2010 18:28:45 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">27752@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>There were a few (but horrible) bugs in the samples. Fixed in r1815</p>
<p>I've also updated the programming guide regarding how to use vertexZ in the maps:<br />
<a href="http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps#z_order_and_depth_buffer" rel="nofollow">http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps#z_order_and_depth_buffer</a></p>
<p>Feel free to correct any syntax/grammar error that you might find. thanks.
</p></description>
		</item>
		<item>
			<title>riq on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/2#post-27614</link>
			<pubDate>Mon, 22 Feb 2010 15:26:52 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">27614@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/6781'>matsebc</a>: no problem. If you have any doubt with TMX, don't hesitate in opening a new thread.
</p></description>
		</item>
		<item>
			<title>matsebc on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/2#post-27574</link>
			<pubDate>Mon, 22 Feb 2010 00:01:23 +0000</pubDate>
			<dc:creator>matsebc</dc:creator>
			<guid isPermaLink="false">27574@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@riq, apologies I wasn't trying to highjack the thread, cheers.
</p></description>
		</item>
		<item>
			<title>riq on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/2#post-27558</link>
			<pubDate>Sun, 21 Feb 2010 21:11:36 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">27558@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>r1808 includes examples that uses both z-order (multiple layers) and vertexZ (uses depth buffer).</p>
<p>According to my tests, everything is working correctly. If something is not working Ok, please post an screenshot of the test,  detailing what's wrong with the screenshot. </p>
<p><strong>I'll ignore</strong> reports that doesn't have the screenshot with the expected behavior. In this particular case, it's much easier for me to understand a bug report with an screenshot.
</p></description>
		</item>
		<item>
			<title>riq on "TMXTileMap isometric zOrder ad-hoc sprite issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4348/page/2#post-27556</link>
			<pubDate>Sun, 21 Feb 2010 21:06:30 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">27556@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/6781'>matsebc</a>: I'm not sure what you are trying to do, but it is possible to modify the maps in runtime. Please see the examples. If you have further questions regarding how to do it, please open a new thread. This threads is about how to use z-order correctly.
</p></description>
		</item>

	</channel>
</rss>

