Object scope issue?

0 favourites
  • 5 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • If you create a project and import 1 sprite, e.g. crater.

    If you have two layouts, e.g. layout 1 for portrait and layout 2 for landscape.

    Both layouts have the same event sheet (as they are the same game, just different object positions and sizes.)

    We copy the objects from layout 1 to layout 2, and all is good.

    Well not quite.

    For some reason I dont yet understand, when I do System->create object->crater in layout 1s event sheet, it uses the (resized) copied crater object from layout 2, not the existing one from layout 1.

    This goes against what people are telling me about the scope of ojects in C2 - that they are local to the layout.

    Here is a capx which demonstrates the issue - the created crater should be small and square, not the stretched one from layout 2.


    Its just a project with 2 layouts. The crater object was dragged to layout 1 to create a sprite ouside the window area. then it was copied (cut and copy) to layout 2, and resized. Then in layout 1, when we create a crater object, it ignores the crater object in its local layout, and grabs the one from layout 2.

    The issue is that without the ability to copy & resize objects and refer to the correct one in a single event sheet, I cant think of a way to implement portrait and landscape versions of the same game (a requirement for mobile html5 games), without duplicating all the code and renaming the corresponding sprites to get local versions. Any ideas?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You should design everything on one layout. It's perfectly possible to have one layout handle both orientations.

  • Your Layout 2 is setted to be the first in the order of your project.

    So the "Crater" instance in the layout 2 is considered to be the first instance, from which the properties are used when creating a new instance.

    There's nothing preventing you from including another event sheet in your main event sheet according to the orientation, and giving the correct size for the instances accordingly.

    Example capx

    I'm not sure about a landscape/portrait versions, it seemed to me that this was automatically handled by the wrappers.

    At worst, lock the game so that it is used either in portrait or in landscape.

  • Thanks guys, appreciate the feedback. Note, for mobile there is no suitable wrapper - I have to use crop mode with a large background, anchor key elements such as buttons and HUD, and then use my own scaling algorithm for the center game elemnts. Letterbox scaling black bars, especially in landscape where most of the screen becomes black, are not an option.

    Separate portrait and landscape layouts are a must have, as the buttons possitions and other items have to move from the bottom to the side.

    Ashley, how can this be done on one layout? My strategy is that I design for iphone4, then scale layers up or down or not depening on the target platform (e.g. for ipad 2 I dont scale - I use iphone 4 layout as ipad is fatter), and make sure the backgroupd image is large enought (i.e. 1024). For PC i disable the scaling, and export as fixed size and layout.

    If portrait and landscape have differnt item anchor points, I dont think this can be done with a single layout?

    Also, I have to have swipe left and right for settings and info. I have managed to get a prototype of this using a fixed layout 3x the window size, but this wont work if the target device has different resolution so Im still trying to figure this one out.

  • Kyatric, thanks for the capx, just downloaded R102 to try it. What im actually trying to do is to have 2 layouts which create objects which have been sized on the layout (rather than sized dynamically), and one event sheet to handle both (i.e. both objects have to have the same name).

    Im trying to think of a way to do this without parameters and functions. Perhaps an array of object names, indexed by the layout name? Can construct 2 store pointers to objects? You cant seem to create objects by name or similar.

    I really dont want to have to duplicate and maintain the identicle except for object name code for portrait and landscape for 30+ games.

    Ashley suggested an interesting optoin - put both portrait and landscape on one layout, but I cant quite see how this will work in crop mode. Anyone got a handy capx with something like this in? Or perpahs to get round the anchor issue, I create 20+ portrait & landscape versions, on one massive layout, one for each target resolution? Id rather duplicate designs than code.

    Its quite hard working with a screen on a layout without using the dotted window lines and zero offest which would only work for one of the views - for the other views on the same layout you would be designing with no guides. Do people create a large background in photoshop with dotted guide lines on it or similar for multiple layouts on one layout?

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