How to reduce amount of layers & 'duplicate' objects

  • Hello,

    I am making a small tycoon game, where you can buy land and build homes on them. Also, you can sell or rent out the homes. Now I was wondering how does one handle all this? Forgive me for asking such a broad question, but what I have for example is this (which appears to be totally futile);

    [attachment=0:2roqsvx3][/attachment:2roqsvx3]

    Problem is that I am getting the idea that I will need to be creating dozens of layers, since each lot could potentially have a different type of home and will each need a unique menu to set the rent and sale price.

    If anyone could point me in the right direction, perhaps even to relevant assets on the Scirra store, or tutorials or otherwise help me out, that'd be fantastic. I finished all of the artwork for the game, now I just need to get the back end working.

    Thanks in advance for any help.

  • Different homes:

    create a sprite with all the homes: each frame being a different home, instead of layering, refer to the correct frame for the home needed to be displayed.

    And for menus, just create them when needed and destroy when done

  • Thanks for your reply.

    I've put the homes in one animation, but am running into problems creating and destroying buttons. See, I have an event where I create a buy button when a vacant lot is clicked. However, if you click the vacant lot twice in a row, it'll create two buy buttons overlapping eachother. How do create only one buy button when the lot is clicked? Or some other way.

    I tried for each, but that doesn't work for the game, I'd like the player to be able to go back to the vacant lot and click it again, only without creating the buy button over and over again.

  • Add a boolean check, created, to the clikcable vacant lot.

    event

    On clicked vacant lot

    boolean vacant.created (inverted)

    action

    vacant.created = true

    and rest of your actions

  • Thanks for your reply, I wasn't familiar with booleans yet, it worked real nicely!

    Now I'm just facing the issue where I am selecting between different lots. For example, if I click on vacant lot 1 and then vacant lot 2, the buttons stack from each lot. If you press the buy button they both disappear and two times the appropriate amount of cash is subtracted. So what I need is only one lot to be 'selected' at the same time. I suppose I could destroy all buttons but that one, but even with families seems like a heck of a task which I can't really figure out how to handle.

    Or, perhaps use variables to check whether a lot is selected, but it seems like one will end up with 30 (amount of lots) variables per event.

    Here's what I got:

    [attachment=0:3btcnlgd][/attachment:3btcnlgd]

  • nah, not 30, just a couple.

    I would use an instance var to determine which, and use systems pick by comparison to pick the needed one.

  • read in the manual about: function()

  • lennaert Allright so I add for example 'Selected' as an instance variable to two lots. Then add as a condition pick by comparison to Lot1?, 'Lot1.Selected', but what do I enter as the value? I'm trying to figure out how to implement this in the code I have above, but am unable to figure it out, how would you structure the code?

    And do I also still need to use global variables with this?

    @edwardr Yeah I read about functions, and wanted to apply it, but Lot1 and Lot2 need to do everything differently (using the next number in line every time) so I don't see how I could use functions to overcome duplicating groups and replacing the objects with the next number in line.

    I searched the web and Scirra's store for examples of simulating menus/selections, but didn't find anything that resembles what I want to make. Would be great also if someone could point me in the direction of learning what I'm trying to make!

    In any case, thanks for your help so far.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I would use as many instance variables to objects as possible.

    The names can be whatever you want ...

    example

    sprite Slots

    slots.active = false

    slots.slotnum = 1

    slots.item = url

    slots.active = false

    slots.slotnum = 2

    slots.item = url

    event

    on click slots

    sub

    slots.active false (inverted)

    action

    set slots.active true

    sub (to slots active false)

    slots.slotnum = 1

    create button on x,y

    sub (to slots active false)

    slots.slotnum = 2

    create button on x,y

  • ok not knowing the program, I programmed a small sample.

    here a small description:

    I add the images into a family, add a family variable (right click), click each image in the family and name it.

    Now you know which image/lot will be clicked.

    I include 3 version (put you also can do this in one function, but this will be more difficult to understand):

    a.) showing the image name (the ID)

    the command function.param(0) use the variable within the function. It is passed when you call it (you can add several param and use it with function.param(1)

    b.) compare variables

    when this variable is clicked do this,.... when this clicked do this...

    c.) calculation

    you can also calculate or do other stuff. Not just showing text

    you can also combine it

  • lenneart Thanks for that, although I don't really know what to do with the information you provided. I mean I don't know how to implement that in my game. I'm thinking this stuff is just too advanced for me. What I wonder most, is how you guys manage to understand all that information you provide. Do you guys have a programming background?

    @edwardr You have only 55 posts on the forum, so you seem to be kinda new to Construct (2), yet you are understanding all that math and coding. What's your background? I checked your .capx but am simply unable to integrate it with what I currently have going.

  • lenneart Thanks for that, although I don't really know what to do with the information you provided. I mean I don't know how to implement that in my game. I'm thinking this stuff is just too advanced for me. What I wonder most, is how you guys manage to understand all that information you provide. Do you guys have a programming background?

    I do have a software development background, most here on Scirra do not or just a little.

    The use of construct 2 gets easier with experience.

    The information I provided is pretty much basic, just some instance vars and some booleans.

    They picture an event setup and how the flow goes.

    From what your saying I would suggest doing some more tutorials, and just follow the examples creating the events needed, soon you will be comfortable applying various of the aspects mentioned.

  • I'm one of the few who try to program a Tycoon / strategy game, so function(), families and variables are the first thing what I learned.

    integration:

    for example (very simple):

    function: set text "Buy vacant " & Family.ID

    (complicate)

    function:

    cash >10000

    subtract 10000 from cash

    set text "You own " & Family.ID

    compare Family.ID = Lot1

    BuyVacantLot1 Destroy

    Lot1Sold to 1

    compare Family.ID = Lot2

    BuyVacantLot2 Destroy

    Lot2Sold to 1

    -> on mouseclick on FamilyBuyVacantLot call function(Family.ID)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)