How do I create an object to cover an irregular area?

0 favourites
  • 13 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • In the picture you have the red area and the blue sprite. How I do cover the red area on runtime creating blue sprites on it so to cover the whole red area and just it, not outside it? Should I make the blue object smaller, maybe 1 pixel square?

    i64.tinypic.com/v3lvrd.png

  • Why do you want to do this? If you need to change the color of red area, there are much easier ways - you can use "Set color" effect or blend modes.

  • No, actually that's just an exaple: my idea is to do something like cover a specific area with another object during run time after an event, like mapping that object onto that area. Do you think it's not possible? :-(

  • And why do you need to do that?

    If the red area consists of 3 rectangular sprites, it's farily easy.

    If it's one sprite, you will need to define its collision polygon, and then it will be possible to fill it with small sprites or tilemap.

    If you can't change the collision polygon (for example for images loaded at runtime), then you will need to use Canvas plugin to detect pixels.

    .

    Having thousands of 1*1px sprites is a bad idea, it's better to use tilemap, see examples in this post:

    construct.net/en/forum/construct-2/how-do-i-18/simple-scorched-earth-worms-ga-129595

  • So I should open the red object as cavans and then do an event such as

    -compare two variable: canvas."rgbaat"("red") = 1?

    how does the syntax work exactly?

  • You need to paste the red image to canvas object. And then use alphaAt or redAt expressions to detect the shape of red image.

    See this demo (you need to install Canvas addon for it):

    dropbox.com/s/u95o1fwrdcz7if7/CustomShapeObjectWithCanvas.capx

    .

    Note that this method is quite slow and only suitable for small images. To improve performance, use bigger tile size (2x2, 4x4 etc.)

  • I guess I’m having trouble following what is being asked.

    The op asks how to cover one object with another and the latest solution looks to be tracing the image of the red object to create a tilemap for collisions.

    Visually all that would change by covering one object by the other would be color. I’d think a different colored animation frame, or a color effect, or even a blend mode would work fine.

    If you do actually want that area replicated with blue rectangles, and that area is already made up of rectangles. Then you could also create a blue sprite for each red one and set the size and position to be the same.

    Any of those would be cheap instead of looping over the pixels to create a tilemap.

    In short I guess I’d want more details of what you want to do. You have a simple example, how about a deluxe one too. It would prolly better show what you want.

  • R0J0hound, well, OP never explained what he needed this for. Based on his question if he could use 1px sprites, I assumed he wants to generate something like a solid terrain from custom images.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000: I tried your capx but the screen turns totally black. don't know why.

    rojohound: I want to trace over a complex layout to have another layout to set as invisible and to use as collision box during the game.

    I know that you can use Tiled to design a tilemap with irregular or complex shapes and then save it as tmx to have the collision boxes preserved but I'm more comfortable using Photoshop or Gimp, both of them have more functions and tools than Tiled.

  • Ah ok. Seems like image tracing is what you want to do. Carry on.

    beguinner

    It's black because reading pixels with the canvas plugin takes so long. Give it a little bit.

    dop2000

    I made this a while back, It's much faster at reading the pixels, and avoids using the canvas plugin. It can't get the image from a sprite though.

    dropbox.com/s/soijvpnt8vjkcka/read_alpha_js.capx

    Even faster would be to save the tilemap to a file and load that later. At least as far as loading times go.

  • I changed canvas.redat on the dop2000 capx with canvas.alphaat to see if it tiled only the transparent area but the result is the same as before. :-(

    Shouldn't have it tiled only the transparent area discarding the red part?

  • Maybe the area you think is transparent is not really transparent. (maybe it's white or black or semi-transparent)

    Use "Browser Log canvas.alphaat(x,y)" to check alpha value in different points.

  • I tried with a maze but it doesn't work. What's the glitch?

    onedrive.live.com

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