The Daily Click ::. Forums ::. Klik Coding Help ::. Overcoming layering issues?
 

Post Reply  Post Oekaki 
 

Posted By Message

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
26th April, 2012 at 26/04/2012 15:02:36 -

I'm making an isometric Sim City-Styled game and I've ran into a couple of problems, both regarding the way objects are overlapping each other in the frame.

First of all, I have two different buildings. When you click on them they become 'selected' (flag is switched on, animation is changed). When you click somewhere else they become 'deselected' and return to their original state.

The problem is when these buildings are overlapping slightly and both buildings are clicked at the point they overlap. They both will become 'selected and everything gets screwed up. I'd like it if it only selected the building on top but I can't seem to come up with a method to do this.


Second problem isn't really a problem... yet, but I need to make it that objects to the back of the isometric grid are layered behind the objects at the front of the isometric grid. Any simple way of doing this?

 

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
26th April, 2012 at 26/04/2012 15:12:46 -

There is an extension I believe that will help very much, I think it's called Select Object, Sort Object or something.
It can sort actives based on values, X/Y and stuff.

What I would do for the layering issue is run a loop for the amount of buildings, then start with the building at the topleft-most X/Y-pos, bring it to front, and repeat the process working in rows toward the rightbottom-most object. You need to do this loop each time a building is added or otherwise layer-interacted.

For the pick frontmost object problem I'd use the Sort/Select Object and make it pick the object whose bottomY is the greatest, that should pick the object in front.

Hope that helps!

Cheers
//EE


 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
26th April, 2012 at 26/04/2012 17:28:09 -

Like EternalMan says, the "Select Object" is the way to go.

For the first problem, you just say:

+ Player clicks on Building
+ Select Object: Reselect all "Building"
-> Building: Set Flag to OFF

+ Player clicks on Building
+ Select Object: Select frontmost "Building"
-> Building: Set Flag to ON

For the second problem, you'll have to use a loop - there is the "Layer" extension, which has a "sort by Y" action, but it sucks.

 
n/a

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
27th April, 2012 at 27/04/2012 18:27:30 -

Thanks for your help guys. I was planning to release this for iOS, and I know there is only a small handful of extensions that are compatible with the exporter so this could be an issue!

 

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
28th April, 2012 at 28/04/2012 02:21:35 -

It shouldn't be,it's perfectly doable without extensions.

A rough example on how to do it; (mind you this is not the most efficient way)

For layering correctly:
I assume there is a grid and for this example I assume that each building's hotspot is in the middle x max y coordinate(down-center). Make an active 1x1 pixels. Each time buildings have interacted in a way that would change the layering order run a loop for the amount of tiles your grid has. Now, have the 1x1 object start at the tile whose Y is the lowest(positioned down-center in the tile so it would overlap a buildings hotspot), make a comparison if a building's hotspot is equal to the 1x1 object's, if so move it to front.
In the next loopstep move the 1x1 object half a tilewidth to the right and half a tileheight down i.e position it at the next tile in the row, do comparison etc.
When the 1x1 object is done with the first row, move it half a tilewidth to the left times the amount of tiles in a row plus one to position it's X for the next row. The object shall also be moved up half a tileheight times the amount of tiles in a row minus one, et voíla, it's ready for the next row.
Rinse and repeat.

For the overlapping issue when clicking:
Use a 1x1 object again, for this example I assume only two buildings can overlap at any given time(you can make it for more though). Have the object positioned at the mouse cursor. Make an event that says something along the lines of "if building is overlapping object + building flag 0 + user clicks = Set flag 0 on, set value A to building Y".
Now, the bruteforce magic of it all, make an exact same event below the previous.
Now you have two buildings with flag 0 on (we'll use flag 0 as "active"), and two Value A holding the buildings' Y values. The building in front will automatically have the higher Y value, so now it's simply a matter of deactivating the building with the lower Y value.
A blunt way of doing it would be to subtract 1 from value A, setting flag 0 off when value A is 0, until only one building has flag 0 on.

These aren't in any way the best ways of doing it, you should use an array and use that to loop through each tile for the layering issue. You could also save height data in each cell and use that to determine if a building is in front of the one above.

Anyways, it's very doable. There was a way before extensions.

Cheers!
//EE

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
28th April, 2012 at 28/04/2012 14:22:55 -

Thanks for that, Eternal Man! It's very much appreciated. I think I understand except for one part.

You said to "subtract 1 from value A, setting flag 0 off when value A is 0, until only one building has flag 0 on."
How do I detect when only just 1 of the building's flag is on and prevent the last building's flag from turning off?

 

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
28th April, 2012 at 28/04/2012 19:36:11 -

It can be done in several ways, but an easy way to fix would be to make another counter named "Flag 0's on" or something

Above the two identical events, make an "always = Set "Flag 0's on" to 0" event.
In the two identical events, stick a "add 1 to "Flag 0's on"" action.

Now, make the subtraction loop repeat only if "Flag 0's on" is greater than 1, and to the "Value A is 0 = Set Flag 0 off" event add a "subtract 1 from "Flag 0's on"" action. That should have the loop subtract until only one building's flag 0 is on.

By the by, everything I've written is from the top of my head, so I can't guarantee that it'll work, but I believe it should. If you encounter any problems with getting the loops right don't hesitate to ask!

Cheers
//EE

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
29th April, 2012 at 29/04/2012 14:21:43 -

Thanks for your help but I'm still struggling to get this to work I did not anticipate running in to all these problems! I really thought this type of game would be easy to make!

 

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
29th April, 2012 at 29/04/2012 18:33:20 -

Isometric games inherently tend to be a little more complex in getting the basics done right. What is your main concern at the moment?
The main issue is to not give up because of complexity, but rather get an understanding of it bit by bit, that's a good way of progressing your creative skills in this matter.
If you want to though, I could probably whip up an example of what I've said in my replys.

Cheers
//EE

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
30th April, 2012 at 30/04/2012 05:28:39 -

I just did not expect to run into all these problems with layering. I am determined to finish this game! I have been around for a long time but have not really been able to produce anything worth sharing because I always get discouraged when I run into problems I can't seem to fix, like these.

I'm pretty sure it's the fast loop parts I'm messing up. I'm fairly inexperienced when it comes to using these.
If you made me an example file, I would be eternally greatful! That would be awesome. I'd like to get a better understanding of fastloops, they are proving to be quite useful.

 

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
30th April, 2012 at 30/04/2012 11:08:25 -

MMF processes your events one at a time from top to bottom. After the last event, the screen is updated and the process repeated. If your game is set at 50 frames per second, MMF will loop through your code 50 times each second.

When you call a fast loop, MMF will stop processing your main code and run the fast loop as many times as you told it to. Once the fast loop is complete, MMF will resume your code from the next action after the fast loop was called.

Each iteration of a fast loop can be referenced via the loop index and all loop indexes begin at 0.

I suggest running some experiment fast loops to see for yourself. Good luck comrade!

 
n/a

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
1st May, 2012 at 01/05/2012 12:43:21 -

Thanks Chris, I'm playing around with fast loops now. I'm still a bit confused about loop indexes. Could you give me an example of what/how you would use these for?

 

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
1st May, 2012 at 01/05/2012 14:29:00 -

The "loopindex" is simply a variable that tells you how many times a loop has been run already that frame.

For example, if you want to instantly load a 10x10 tile-based map from an array (with 32x32 size tiles).

+ Start of frame
-> Start fastloop "Load" 100 times -10 rows x 10 columns = 100 tiles
-> Tile: Destroy -This event doesn't run until after the "Load" events have all repeated 100 times

+ On loop "Load" -This event will only run when triggered by a "start fastloop" action
-> Set GridX to LoopIndex("Load") mod 10 -This calculates a column from the loop index
-> Set GridY to LoopIndex("Load") / 10 -This calculates a row from the loop index
-> Tile: Set X position to GridX * 32
-> Tile: Set Y position to GridY * 32

+ On loop "Load"
-> Tile: Set animation frame to ValueAtXY("Array", GridX, GridY)
-> Tile: Add to backdrop

note: If you have several conditions, the "on loop" condition always has to go at the top (it will be highlighted in red).

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
1st May, 2012 at 01/05/2012 14:43:08 -

Here is a terribly rushed example in which things happen with loop indexes.

http://www.whenthereisnoroominhellthedeadwalktheearth.com/MMF/loop.mfa

 
n/a

Chris Burrows



Registered
  14/09/2002
Points
  2396

GOTW WINNER OCT. 2011
1st May, 2012 at 01/05/2012 14:51:45 -

Ah ya beat me to it Sketchy.

You've been quite active on both forums this last week compared to usual. It may possibly be all in my head, but it seems you are replying to threads you usually wouldn't, giving more detailed responses and as much as a person can tell from reading short pieces of writing about computer programming from a person they otherwise know nothing about, seeming happier than usual.

Haha that came out very creepy.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
1st May, 2012 at 01/05/2012 15:27:55 -

Okaaay...
Actually, I just have *tons* of chores I should be doing at the moment, so as usual, I'm procrastinating instead...

 
n/a

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
1st May, 2012 at 01/05/2012 17:51:57 -

Thanks Chris, I think I have a much better understanding of fast loops although I am still struggling to get this to work. I've uploaded my little practice file regardless of how embarrassing as my attempt is... Perhaps you guys can take a look at it

http://www.craigeatscrayons.com/BuildingTest.mfa
(hopefully that link works, ive never really used my webspace before! )

 

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
2nd May, 2012 at 02/05/2012 15:17:42 -

Hi, sorry for not replying yet!
I'll use your base engine and make a working example of it.

Cheers
//EE

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

Buster

BLING COMMANDER

Registered
  03/06/2002
Points
  1545

VIP Member
3rd May, 2012 at 03/05/2012 12:54:41 -

Thanks EE, I really appreciate you taking a look at it. I should probably mention that I did try a lot more than what you see in that file haha! I deleted some events that I thought were incorrect.

 

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
4th May, 2012 at 04/05/2012 23:59:29 -

Hey Buster, sorry for the radio silence lately, the entire family's down with a pretty bad cold, so I don't get to much computer time. But I'll pm you when I've got something.

Cheers
//EE

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image
   

Post Reply



 



Advertisement

Worth A Click