I’m trying to make a simple tile engine because the tutorial site doesn’t go in to collision detection and such which I need. I made a class based off the tutorial to be easier to use but looping through all the tile objects freezes the game and it is irresponsive and i have to kill all haxe processes to stop it. Any tutorials or code? Here’s what I’m using at the moment:
Thanks! I’m definitely going to give it a try. Before I do I want to know why this is slow even though I used a tile sheet. I created an array of tiles and render all of them every frame. Here is the simple tile class: http://pastebin.com/ib7BxUps
Is this a class for one single tile, or just your main class? If it is a single tile, there are some things I will have to explain to you because it looks like you aren’t clear on some of the ideas of tilesheet.
Also, I have noticed one thing: objects in haxe are passed by reference, meaning your ‘this.pos = pos’ will store pos as an reference, and when the old pos changes your pos will change as well. Use ‘this.pos.x = pos.x’ and ‘this.pos.y = pos.y’, or ‘this.pos = new Vec2().copy(pos)’ if your vector class has this functionality.
Alright, looks like this is your class for a single tile. I might not get everything right, so please correct me if I’m wrong.
First, I want to explain a bit on how GPU render things using OpenGL(assuming you are doing stuff for native platform). To draw things using the GPU, you upload the vertex and texture information to the GPU and then you make a draw call. Doing multiple draw calls may involve switching and reuploading informations, therefore is slow.
Now the draw tile function can take all your information in the data array, submit it, and make one draw call. The reason it is very fast, is because 1: you only need one draw call to render many objects. 2: you only need to upload one Single texture to render different tiles(by packing many images into a big one so that you only need to upload once, I recommend using the software TexturePacker for packing). Therefore, the less draw tile calls you make, the more efficient it is.
Now the most efficient method of utilizing the tilesheet class is used by the engine I gave you: use one single sprite as canvas, use tile classes to store some information about position and such, and then call render function to arrange all informations and call draw tile once per frame. DO NOT use sprite as tile class, because OpenFL use one draw call for each sprite: much much slower than tiles.
Now, the tile layer engine can’t have parent transformation. In order to have the same transformation function as the normal sprite, you need to modify the engine to add the matrix multiplication which I have already done for my own engine but might not be efficient enought.
Anyways. I hope that was helpful
It makes a BIG difference. If you pass by reference, when you modify the old position your new position will change - all your tiles are gonna have the same position!
In terms of programming, every variable you make will take up some space in the memory. In haxe, for objects, if you don’t use new Vec2() to make a new object, there will always be just one object sitting in memory, and your reference is just an address of where that object is sitting. Any operation will just be modifying that object: see the problem here? You may have 5 tiles, but there is 1 pos object, all the other ones are just referring to it.
Do you have any other prior knowledge of game developing tho? Before starting on OpenFL I was using flash and AS3. Because flash is still more well known and is older, there are much more tutorials, larger community and more through documentations on AS3 than OpenFL. I recommend looking into them before starting on OpenFL as it is slightly more advanced.
I have most experience in OpenGL and LibGdx. OpenFL/flash is kind of weird for me because I’m used to having a render method where I handle drawing everything. I’ll definatly look into more AS3 as I’ve seen tutorials that look similar to OpenFL.
As for the tile engine tool it throws an error: Uncaught exception - Invalid field access : rect
Umm, the thing is to change the deployment target to “windows -Dlegacy” if you are currently using “Windows”.
The tilesheet API should be very easy for you: it allows you to handle the drawing yourself. Consider each drawtile as a draw call. And you can just look into the engine and find out how it does the drawings.