Level Creator with Mouse

Get help using Construct 2

Post » Wed Jan 09, 2013 9:25 am

Hi guys,

1) I'm trying to set up a level editor which will allow me to build a level using an array and my mouse. It'll start off with a black screen, and provide me with tiles to select on the right hand side of the screen. I will then pick a tile and start painting my level.

Once this is done, I then want to be able to save the level I have made into an array, save it, and call it later.

Please see my CAPX so far. CLICK HERE

This is based on this video, and I have looked through the FAQs and searched quite a few times. My brain is telling me that the basic editor that I have set up is correct, but for some reason it isn't working (my brain or the software ).

2) In any case, I wish to be able to expand on this at a later point, and eventually have a level randomly generate itself, but in a clever way with transitions, for example, water will not just be a square - the system will recognise water tiles, and surround it with edges, or gem blocks and bleed off into the surrounding dirt. This data will then be stored indefinitely until it's needed.

3) Finally, the idea is to be able to use the path finder to have units navigate the terrain even as it's being changed.

I wish to have a better understanding of arrays, and see how the system knows which tile correlates to which point in the array.AnD4D2013-01-09 09:26:11
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Wed Jan 09, 2013 9:33 am

Move action 'set size to (levelheight, width)' below the actions where you set values to levelheight and width. Right now the array size is not setting up properly as you set those values AFTER you set the height/width variables. :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Jan 09, 2013 10:00 am

OK, I've changed that... but when I click on tiles to change their colour (for now to just a red square) it's jumping all over the place and changing different squares. This leads me to believe the array isn't correctly linking to the tiles.AnD4D2013-01-09 10:25:18
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Wed Jan 09, 2013 10:41 am

I made a couple of changes, tried to comment them into the events. Take a look :)

http://dl.dropbox.com/u/19921470/Main.capx

For printing the arrays (which is good idea to figure out what is going on) I'd recommend using some custom plugins like these:

http://www.scirra.com/forum/log-text-objects-to-chrome-console_topic47859.html
http://www.scirra.com/forum/plugin-debug-panel_topic48052.html

I use the chrome plugin myself, works great!
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Jan 09, 2013 11:09 am

Thanks @vee41, very impressive. Still trying to get my head around the changes, but from what I'm gathering, there doesn't appear to be a method of saving or loading.

The line which you removed - "SetAnimationFrame to Shop.At((Tile.IID)%LevelWidth,(Tile.IID)/LevelWidth)" was designed to refresh the tile sprite frame to reflect that of the array, meaning that if the array x.10,y.20 = 1, it would set the corresponding tile to play frame 1. This means that the array can be saved as a string, and then loaded on startup.

Does this make sense?
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Wed Jan 09, 2013 11:37 am

[QUOTE=AnD4D]The line which you removed - "SetAnimationFrame to Shop.At((Tile.IID)%LevelWidth,(Tile.IID)/LevelWidth)" was designed to refresh the tile sprite frame to reflect that of the array, meaning that if the array x.10,y.20 = 1, it would set the corresponding tile to play frame 1. This means that the array can be saved as a string, and then loaded on startup.

Does this make sense?[/QUOTE]

Ahh, gotcha. Thought it was meant to do something like that but couldn't really figure it out. :)

At the moment way I restructured it, painted values are saved into array. So if you paint few tiles as animation frame 2 value '2' is saved to corresponding location at the array. As of now, there isn't anyway to change frame you are painting, but this would be a simple variable you can change via button or something.

What this array makes possible is that you can save/load levels. Right now there is no level generation from array, which should not be too hard to implement. Saving arrays as strings and loading them at startup is a good idea, there are some good examples of that around here :)

Saving and loading could be implemented with arrays 'load' and 'asJson' functions, think I removed one of them as it wasn't really doing anything :) What you'd need is a save/load buttons which trigger these functions, and multiple arrays to save/load levels to/from.

This is not really the simplest stuff, but once you get some basic principles down it should clear up nicely! :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Jan 09, 2013 11:51 am

Great! I've read up on a few examples, but I can not figure out how to save and load. At the moment I'm just playing with keyboard commands to trigger these, and I'll have the mouse wheel choose the frame number, just to start things off...

I'll give it a go. Hopefully it'll just click into my mind on what I'm doing :)

Thanks a lot for your help!
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Wed Jan 09, 2013 12:14 pm

Good luck, I added few features to this that could be basis for saving and loading: http://dl.dropbox.com/u/19921470/Main%20(1).capx

Right now you are 'loading' and 'saving' map simple by pressing a button, if you wish to actually save data to a disk I recommend you take a look at the webstorage plugin. What you'd need to do is set the initial array values at the start of the layout, this way your map would load when the game starts. :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Wed Jan 09, 2013 12:16 pm

I have removed the command "Tile set animation frame to 1" and have tried to re-introduce the code that will set the frame based on the underlying array number, but I'm not having much luck. Either the system appears to be painting the surrounding tiles, painting an ever changing pattern (somehow) or painting the entire board the same colour.

I like what you've done with the Mouse.x and y positions coordinating with the array, but I'm not sure how I can re-use that data elsewhere.

I am simply saving over the link in the first post. I feel I'm 1 line away from making this work as expected.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Post » Wed Jan 09, 2013 12:21 pm

Oh, @vee41... you did it. I was way off!!!

Alright, I'll have a decent read of that, and figure out what I can do to swap, save, and load :)

Thanks again!
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
68
S
8
G
6
Posts: 930
Reputation: 9,358

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Braus, supreme676 and 7 guests