How do I draw shape and fill itself if unfinished?

0 favourites
  • 10 posts
From the Asset Store
Glow Creatures
$1.50 USD
50% off
5 glow creatures with size, shape and color variations.
  • I am a begginer (complete newbie btw), wanting to make a game were you draw a shape with limited use of ammount of area per total shapes ingame and after the shape is drawn by mouse input it is filled and closed automaticaly and falls into ground. I know its a hard one, but this question is driving me nuts finding a game engine that makes this easier, tried gamesalad and stencyl... Any clues guys?

    oh, i tried the polygon plugin! nope, its not like that what I want.

  • this brings me back to my old days of Amstrad coding... anyway

    if the shape is regular (ie a box) then you could build a filling routine where you fill it up with predefined polygons (say a 1x1 image, or even better a 1x1 image that you can stretch to a width). what you do is a bit like a path-finding algorithm... you figure which side of the line is your box... and then you move left and right to find an edge (c2 can do that) and then you can move up and down. or you can travel along an edge and infill. It begins to fail with complicated shapes, and it will not be fast as writing it natively.

    it's not easy but it is doable. I suspect it's beyond a beginner

    PS: as an early newbie, I never got my fill algorithms to work correctly.

  • ok guys, its as I suspected, but say I wanna simplify things and want to just create a square by making the diagonal (dragging like in photoshop or illustrator and create and fill the square) is it possible with the help of a plugin? I just need to make a good function for this game and easing the process with a plugin would be more doable... thanks for the answers anyway!

  • Why not use the polygon object? It makes it very easy to draw a polygon. For example:

    on mouse left click
    --- polygon: clear polygon
    
    left mouse button is down
    --- polygon: add vertex at (Mouse.x, Mouse.y) -world-space
    
    on left mouse button released
    --- polygon: draw polygon ...
    [/code:2x63fnpc]
    It doesn't play well with the physics behavior but at least the collision polygon will match the drawn polygon.
    
    You could also draw the polygon using the canvas plugin but it has no collision polygon.
    
    So drawing it isn't what's hard.
    
    For just a box no third party plugin is needed.  Only the mouse and a sprite with the origin centered.
    [code:2x63fnpc]global number startx=0
    global number starty=0
    
    on left mouse click
    --- set startx to mouse.x
    --- set starty to mouse.y
    --- create Sprite at 0,0
    
    left mouse button is down
    -or-
    on left mouse released
    --- Sprite: set position to ((startx+mouse.x)/2, (starty+mouse.y)/2)
    --- Sprite: set size to (abs(startx-mouse.x), abs(starty-mouse.y))
    [/code:2x63fnpc]
    If you want it to fall afterwards you could use the physics behavior, only be sure to disable it until the mouse button is released.
    
    If you want a box then no plugin is needed
  • thanks R0J0hound, managed to do it by making the secnd option: generating the sprite, two questions now... my sprite should be with limited use in my game, like, I just could use 3/4 of them, but what is happening is that the old sprite disapears when i click other area and generates a new one ( the same but in other position). That is a thing I wish this game to have, the other one is: Im not managing to get it to fall, I disable the behaviour of phisics, then what? I aplied that to the sprite.

  • Here's a capx. I used "pick top instance" to pick only the last box created

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • sorry that is for version 192, and I have the latest free version wich is 190. how to bypass this? I just clicked the capx to ope, am I doin it wrong?

  • thanks korbaach

  • how would you set this up for the phone touch system? I set it all up for touch and it works great in preview, but once on the phone it does not draw the box

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