Jump to content


Photo

How to acomplish this with Game Maker in editor?


  • Please log in to reply
3 replies to this topic

#1 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 30 April 2012 - 02:53 PM

Hi!,

Sorry for not being more specific with the topic title but I did not know how to synthesize my question.

First of all I must say I'm using beta version of GM Studio (Waiting for iphone publishing yay!).

The problem I'm having is the following: My game shows several pieces on a board and users can select, move them, etc... This pieces are made of tiles. For example a 2 tiles horizontal piece is made of 2 little horizontal tiles (if tiles are 32x32 piece will be 64x32). The problem is that I don't know how to add this pieces as a whole to the board. I mean, I can add 2 horizontal tiles, but if player clicks any of this two tiles all the piece must be selected.

Comming from unity, is there anyway to have a relationship between parent/child that I could add to the scene, and parse only parents at runtime to get information about pieces registering their tiles?

If anyone needs more info let me know, being a newbie is a bit hard to explain things in GM terms.

Thanks in advance.

Edited by hexdump, 30 April 2012 - 03:06 PM.

  • 0

#2 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9259 posts
  • Version:Unknown

Posted 01 May 2012 - 12:29 AM

Programming questions should be in one of the two Q&A forums (either Advanced Users or Novice & Intermediate Users). I'll move it to Novice as soon as I'm done posting this reply ;) .

One method that I can think of right now is to have an object (let's call it pieceObj) that's designed just to be the "parent" (it's not really a parent in the programming sense, hence the quotes). When a piece is created, the parent keeps a list of the individual tiles that belong to it, and each tile keeps a reference back to the parent. This way, when a tile is clicked, you can refer back to the parent piece and select all its tiles.

Like this (for a 2-tile horizontal piece):

/* pieceObj CREATE */
mytiles[0] = instance_create(x, y, tileObj);
mytiles[1] = instance_create(x + 32, y, tileObj);
tileCount = 2; // Just to keep track of the number of tiles in this piece.

for (t = 0; t < tileCount; t += 1) { // Use a loop so it'll work for any number of tiles.
  mytiles[t].parent = id;
}

/* tileObj Left Pressed event */
with (parent) { // Change to the parent pieceObj's scope
  for (t = 0; y < tileCount; t += 1) { // Loop through all the tiles in this piece
    mytiles[t].selected = true; // Select each tile
  }
}

-IMP
  • 0

#3 kburkhart84

kburkhart84

    GMC Member

  • GMC Member
  • 1605 posts
  • Version:GM:Studio

Posted 01 May 2012 - 05:41 AM

IMP has this right. I have used this method to create weapons for a space ship, where each weapon "follows" the parent, and responds to input individually. I would have the parent be responsible for creating the children, and using the with statement apply the "pointer" variables that have the id of the parent. Also, each "parent" needs to have a list of its "children." So, I would have a script that handles the action, and if the "click" is done on the parent, call the script. If the "click" is done on a child, use the with statement to call the same script, but from the parent object. In that script, you don't have to care whether it was a child or parent because it is only being called from the parent, even if it originally comes from the child. And so that script can depend on the child list that will be on the parent.
  • 0

#4 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 03 May 2012 - 01:00 PM

Hi!,

This is the idea I had initially.

The thing is that I would like to create this pieces at design time. I mean I must see how much space each piece occupy, etc... I could have some place holder actors and replace them at runtime, but this won't give me visual feedback when editing the level.

Any idea?.

THanks in a dvance.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users