Generating a world from a bitmap?

Get help using Construct 2

Post » Tue Apr 30, 2013 2:35 pm

I'm trying to figure out if this is possible with C2:
Take an image file, get the color of the pixel at a particular x,y coordinate for use as a basis for a map that then is procedurally generated.
Basically, each pixel of the map represents an area in the game. If it is, say, a specific green color, then the map area generated is grassland. If it's a certain blue color, it's water, etc.
It would seem that C2 is limited due to the HTML5 security and other whatsits I don't fully understand, to where I couldn't directly read in raw file data. However, I saw in the forums for C1 that someone had made a photoshop style color picker example. I could use something like that to get a pixel color from an image that's been loaded normally. Is something similar possible with C2? I would really like to avoid having to create a huge world map tile by tile directly in a C2 layout, if possible.
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Tue Apr 30, 2013 2:57 pm

@Yttermayn

Hi,

you could do something similar using the Canvas plugin. It allows you to check the colour of any pixel in the canvas. This could then be translated into specific sprites for your world.
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Tue Apr 30, 2013 5:36 pm

@spongehammer that's really interesting, I didn't know Canvas could do that!
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,390

Post » Tue Apr 30, 2013 6:53 pm

I used this method a few times in Construct Classics canvas, and it works quite well.
It also works ok with Rojo's Canvas, however there was an issue with what was returned with Fire Fox.
I reported the bug, but you never know if or when they will fix that kind of thing.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Apr 30, 2013 7:49 pm

Thanks for the response, Spongehammer! I assume this is the canvas plugin you're talking about? http://www.scirra.com/forum/plugin-canvas_topic46006.htmlYttermayn2013-04-30 19:50:35
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Tue Apr 30, 2013 9:46 pm

@Yttermayn @sqiddster

thats the one.

Here is an example, not overly efficient but it works.

canvas example
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Wed May 08, 2013 3:41 am

Spongehammer: I've set up the canvas plugin and created a map.png image that loads onto a canvas. How do I get the color of a pixel on the canvas? I loaded your example up and it doesn't make any sense to me how that's supposed to get a color from an image.
In particular, I'm unsure of what this part is: "rgba(0,255,0,1)" What is rgba()? Some function with four parameters? Stands for RedGreenBlueArray? I don't see one set up anywhere.

I get that you're filling up an array with different colored pixels, but I don't understand how this helps.
Please enlighten me, oh wise one.
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Fri May 10, 2013 8:41 am

@Yttermayn

The code is set up to pick up only 100% RGB colours so Red is 255,0,0 Blue is 0,255,0 and so on.

rgba() just means Red, Blue, Green, Alpha which is the transparency of the pixel.

Hope this helps.

If you need any more info then make sure you put the @ symbol in front of my name
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Fri May 10, 2013 3:59 pm

@spongehammer
Ok, I didn't know what the @ was all about, thanks, and thanks for the reply. So rgba()is a function that will pick a specific target color and alpha combination from the canvas? So does it return a 1 or 0 or true/false or something depending on which pixel it's checking? When I get home I'll view it in this frame of mind and see if your example makes more sense.
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Fri May 10, 2013 5:37 pm

@Yttermayn

This reads the colour data from the canvas into the array

Canvas2.rgbaAt(loopindex("xloop"), loopindex("yloop"))


In each map group this is simply comparing the data at any given location in the array with a set colour.

"rgba(0,255,0,1)"

Green in this case.

Hope that helps
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Next

Return to How do I....?

Who is online

Users browsing this forum: mercuryus, mystazsea and 17 guests