1
\$\begingroup\$

I am thinking of creating a sprite base 2d top down farm simulation game. The game uses tiles and I was wondering (conceptually) what is the best way to handle the farm tiles. Each tiles should have the following list of features.

  • The player should be able to add seeds to each tile

  • The player should be able to plant a variety of vegetables.

  • Plants should have different stages of growth

  • The player should be able to interact with each tile (dig, cover holes, water, add fertilizer, etc).

  • The farm layout can have a variety of shapes (i.e. Not just a square (9 x 9) or rectangle (9 x 15) a shaped farm.)

Currently I have a script that generates a square or rectangle shaped like farm, each tile is a sprite object with a 2D collider. I have come up with a solution for planting and the different stages of growth. However, it isn't the most elegant solution. My current solution is to create prefab for each plant. Then once a seed is planted onto a tile, create a plant object in the location of the tile (using it's vector position), and make the plant a child object to that tile. Each plant will have an age counter that increase when a new day is triggered. To show the growth stage swap the texture depending on the plant's age.

My biggest problem with the implementation is that if the players farm is very large the game will have to create a hundreds object, which seem very taxing. Is that a different way achieve these features without the use of so many objects? If so, how would I implement it (conceptual of course). Thanks!

\$\endgroup\$
  • \$\begingroup\$ Seems very taxing? Are you sure that it actually will be? Have you tried it? Developers are notoriously bad at estimating performance bottlenecks. \$\endgroup\$ – Philipp Apr 27 '16 at 7:49
  • \$\begingroup\$ Your approach is fine. You need to keep coding and determine when it is time for you to look at optimizing. At this point, you will need to profile and determine what to optimize, and then profile again and see how effective your optimizations were. It sounds like you are on the right track for now at least. \$\endgroup\$ – jgallant Apr 27 '16 at 11:13
  • \$\begingroup\$ @Philipp I have tried this and it's actually working fine. But yes your link is very relevant. I am worrying about pre-optimizing too much. \$\endgroup\$ – Pav Dis Apr 27 '16 at 12:28
  • \$\begingroup\$ @Jon Thanks for the feedback. I will definitely keep that in mind while I continue with this project. I suppose I just needed a second opinion on my implementation. I just wanted to make sure I'm not "reinventing the wheel". If there already is a well known solution. \$\endgroup\$ – Pav Dis Apr 27 '16 at 12:32
-3
\$\begingroup\$

I'm going to give you a rather stupid answer but what the heck. First of all hundreds of objects in a game is no problem. Secondly there is this guy called quil 18 that has great tutorials.

Start with the Basics of 2d tile maps and then you can watch this gigantic series about a base building game here

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ First is a generalization which greatly depends on what these 100 objects are doing and how they are doing it. Secondly does not add much value either. \$\endgroup\$ – Philipp Apr 27 '16 at 7:55
  • \$\begingroup\$ They are obviously going to be 2d tiles each with a behavior script and possibly one or two animations or just multiple sprite states. Sorry i did not state that in my answer, because I thought it was made clear by the question itself. And secondly one of my links is to a rather high quality and yet short tutorial on exactly what the OP wants to know. Why should I waste time typing out a 2 page answer. \$\endgroup\$ – Uri Popov Apr 27 '16 at 8:04
  • \$\begingroup\$ You don't really answer anything. This should be a comment on the question. \$\endgroup\$ – nathan Apr 27 '16 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.