Trying to Autotile [Solved]

@Ric - nothing clever from me, it just kind of fell out of how it works.

but your enthusiasm wins you the grand prize of my shader collection, here

https://gist.github.com/dermotbalson/5868211

(long press on Add New Project to put it into tabs)

It’s like Christmas! I especially like your study with transparent pixels. Excellent work, as always Mr. @Ignatz.

So who is ready for another question? Well make it two cause that first one wasn’t the real deal :stuck_out_tongue:

I now have floors and objects being generated correctly, however, the player is either always above or always below the objects, depending on which I draw first. Some objects I need the player to be able to go behind and others I want the player to be able to walk over or up to and appear partially over. How can I go about achieving this?

I was thinking of drawing the objects the original, but I fear the lag, lol. A weak table would probably do it, but I was hoping to stick with the meshes since they are working out very well.

Thanks @ignatz.
Works fine on ipad1 too.

At the end of drawing walls and such, check if the tile above the player is something solid the player cannot walk into, and if so, redraw the player in the same spot, after it’s drawn the walls to overlap it. When you first draw the player, though, have it draw before the walls, so it could be overlapped by something below it.

I had this problem with my 3D tabletop scene. The only solution I found was to sort the meshes by distance from the player and draw from furthest to nearest. I have code if you want it.

This is because if you draw a pixel on top of one that is already drawn, OpenGL will only do so if the new pixel is closer to the camera than the old pixel. This includes transparent pixels, ie OpenGL treats them as solid, and won’t draw anything behind them. There is a workaround if you are having trouble with transparent pixels, and that is to use a shader to discard them altogether, then it shouldn’t matter so much if your image is in the right order. It’s shader number 5 in my pack just above here.

The main problem with the sorting solution is if you have a mesh that is big, then what x,y do you use to sort on? It really works best with lots of small meshes, so the sorting is as accurate as possible.

I’m happy to help if you need it. I also have code for drawing players on top of terrain, if you need to calculate an interpolated terrain height.

@skythecoder,
That worked like a charm, thanks for the quick and easy fix.

@ignatz,
Time to look into those shader samples you provided. I have a feeling these will come in very handy for the rpg I have in mind.

Thanks everyone. Now to continue coding and work towards my next question, hehe.

After checking and rechecking my floor auto-tile algorithm I finally figured out that the algorithm is perfect and it was the tileset I am using that has the graphical errors. Found a better tileset to use and now it looks flawless. :smiley:

Here are some screenshots. I have one map set to 32x32 tiles and one set to 64x64 tiles.









I will add some detailed documentation to my code and then release it to everyone. Hopefully I will have this done sometime in the next few days.

Very neat idea, have you considered making a full blown editer for this? Shopuldnt be to hard. Load a spritesheet then have the ability to drag tiles to the screen then save the export to a tab which could be coppied into a project and run.

@Briarfox, yep that’s the plan for future. I plan to turn this into the Codea RPG Maker essentially. I will most likely need help when it comes to making the GUI for it since my mind tends to be more logical than artistic, lol.



I forgot to post the link to the code in this discussion. Check it out here:


http://twolivesleft.com/Codea/Talk/discussion/3058/

@Slashin8r would you consider putting the code up on github? Easier to pull it into existing project, instead of delete and re creation when there’s an update.

@Briarfox, yeah I will do that when I make it home. Have been on vacation for 10 days and am currently in the car enjoying a 15 hour drive, lol.



Anyone know a good free app to publish to github? If I could do it from my iPad I will get it up there sooner.

Well, (shameless self plug) you could use my autogist app. It version controls to github. can greate an installer and can create an update button to let users update when you release a new version :slight_smile:

You can find it under utilities on the wiki.

@Briarfox, wow thank you so much. That app is awesome and fast. I have uploaded my project and created and auto installer. Links will be available in my other discussion mentioned above.