How do I pick the center of many random placed instances of the same object?

0 favourites
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • How do I pick the center of many random placed instances of the same object(Spacecraft in the Picture)? The yellow square is the Center that should being set in the middle of the handmade spacecraft.

    Tagged:

  • yellow object from what i see is sitting in the middle of the spacecraft, just the origin point of the yellow object is in the right side middle, change the yellow origin point(origin point is the 0 index image point if u move that u move the origin of the image) to the center of the image.

    the above is for sprite objects, if its a tiledbackground settings menu in left side of projects has a origin option, make sure is set to middle or center forgot how is called.

    if they are already in the middle for the yellow sprite/tiledbackground check ur spacecraft origin point.

  • No, the immage point from the yellow square is in the middle of itsself. I ment how to place the yellow square in the middle of the spacecraft for the Scroll to behavior. Because the spacecraft Is individual buildable of blocks(manny instances of the same object). (Spacecraft should be in the middle of the Screen in game) Thanks for trying to Help! :)

  • I don't know how you doing the creation of the ship but i would create it at a invisible sprite position and use that invisible sprite to center items around it so that the center of the ship will always be that invisible sprite.

    then u can scroll the screen to it or the yellow block but you need to have enough layout size. if the layout is the same size as the viewport size then there won't be nothing to scroll.

  • The ship is made of blocks (mouse clicks) which are pinned on the green frame (position and angle). The green frame has a car behavior for moving. Because blocks can be destroyed and because of the torque i have to get the middle of the ship. Another solution is to pick the middle block of the ship. Then i could set the frame to it.

    Maybe pick the highest and lowest X and Y /2 from the block instances. But I dont know how to do that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you so much! But this is done with the screen size, i think. I have to find the middle of the green frame (which is movable and bound to layout, because Layout is bigger than the screen). Im to stupid to do that ^^. Please help me.

  • I modified Kyatric's capx (which is amazing), to spawn the blocks inside a container at mouse position, and rearrange them in case they go outside border.

    download find.middle.multiple.instances-container.c3p + grid_spawn - C3/R139 required to open the file.

    i added an extra mode for you, in case you wanted a grid lock spawn.

  • Thank you very very much! Your grid is better then my method. ^^ But there is one problem left. When blocks are getting destroyed ingame, and Im not in the Viewport, the cam isn`t able to center farther. Is there a way to center without the viewport?

    Thanks for help!

  • ah that is cause of the local variables we used which are probably changing cause you change the layout size?

    You can redownload it, i patched it for you, and included a overlap creation fault system. So in case you create two blocks on top of each other, we pick the top overlapping one and destroy it.

    The local variables can be put as globals if you want to modify them from any event sheet.

    Just move them above the group.

    find.middle.multiple.instances-container.c3p Patched

    Hope it's gonna work now.

    Edited: Even though i think it still won't work, cause the localvariables need to update based on container position and blocks so the camera can always follow the blocks inside the container.

    Edited2: i patched it again, now the camera follows the position of the container + blocks+ grid. so you will have to keep the container invisible not destroy it after creation of ship. You can redownload from the same link.

    Edit3: made a few more modifications, now you can move the container with arrow keys, however it will eat up a lot of cpu when all objects move, so you might want to destroy the gridBlock_container once the ship was created. so you reduce the amount of items keeping track of the position of the container, therefore lowering the cpu usage.

    you can rerun the grid build up when u enter the editor mode, instead of start of layout you move the grid creation when you have a condition like, editor is enabled Trigger Once.

  • http://www.mediafire.com/file/3mpyah6jz11g769/try.c3p/file

    Thanks for taking your time! Your excellent work helps me really much.

    I try to pin all objects to the green "Pintosprite" and destroy the rest. It has the car behavior. My capx isnt working, but do you know, what i mean? ^^

  • here you go mate :D try-this.c3p i actually i think solved this in last capx, i sent ... i just fixed it later on, you just need to redownload. but the capx that is linked here is basically that same thing.

  • I found a solution under use of your work. Thank you for your help!

    Best regards! :)

  • But There is another thing, what I´m unable to do. How do i save a construction as JSON? It should be possible to load ships on other computers from it. :))

  • You can export a dictionary or an array as JSON.

    For each sprites that compose your ship, create a new dictionary key, or a new index in your array, containing the informations about its position, its texture and anything relevant to the ship structure in your game.

    You also need to create your loading function that will create sprites out of the data structure and the informations you saved in those.

    This is an even more advanced mechanic you are to implement and possibly a new topic altogether.

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