Problem with canvas and getting correct coordinates

0 favourites
  • 3 posts
From the Asset Store
Pixel Destruction like in "Worms" (Drawing Canvas based)
  • I need help, I'm making a children's game for vision restoration and have been struggling with the function for a long time. please help.

    I have two color blocks: red and blue, I transfer each block to a separate canvas and then, moving the touch or mouse, I transfer the color from the block to the variable for the FallingBlock and StaticBlock objects.

    I want to make a universal thing that will work fine on the web and mobile and support responsive width (from smartphones to PCs).

    I make the layout size 720 (width) by 1280 (height), my game looks good on smartphones and is displayed in the middle of the screen on a PC s.mail.ru/y9yg/V7FUfV7eC - it's okay.

    In order for the game to be displayed in the middle of the screen I have to set the layout parallax to 0%. But because my real screen width on PC is 1920, and the layout is 720 in Construct, the system misunderstands my touch when I touch a colored block. Wheel pickers are incorrectly positioned and pass the wrong value to the variable s.mail.ru/qT4r/msycGCc3q

    If I set parallax to 100% 100% for all layers, then everything works correctly, but then the game elements stick to the left side of the screen (from 0 to 720 pixels of the real screen size) s.mail.ru/QLWo/kGoxdZUdH - this does not suit me.

    How can I make it so that regardless of the screen width and when the screen width changes (for example, the user drags the browser window with the mouse), I can use touch or mouse to get the correct values ​​​​of the colored blocks and so that the wheel pickers take the value of the coordinates of my touch? . Thank you for any help! C3P example on the link drive.google.com/file/d/1KqfnL9MCWvyJ_PxEBA7QLnfSOkc1ZEC9/view

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Use the expressions:

    Touch.X("BG")
    Touch.Y("BG")
    

    To get the current position of a touch in layer Co-ordinates:

    This takes into account the (Parallax, scaling and rotation) for the provided layer, in this case, is the BG Layer.

    This solves your misconfiguration issue as you have "layer 1" with (Parallax = 0)

    You can hard code the Layer-Name but if in the future you change the layer names, or the object layers to a different layer you will always need to update the layer names on all those events that reference them. So in this case, I would target the "objects.layerName" expression to make it easier for you and less work to do in the future. This way you can change layer names or the object's layer placement without the need to worry about constantly updating the events.

    Set WheelPicker Position to:

    Touch.X(WheelFalling.LayerName)
    Touch.Y(WheelFalling.LayerName)
    
    

    Set Color to:

    Functions.pickColor(Touch.X(WheelFalling.LayerName), Touch.Y(WheelFalling.LayerName), WheelCanvas.UID)
    

    Set WheelPickerStatic Position to:

    Touch.X(WheelStatic.LayerName)
    Touch.Y(WheelStatic.LayerName)
    

    Set Color2 to:

    Functions.pickColor(Touch.X(WheelStatic.LayerName), Touch.Y(WheelStatic.LayerName), WheelCanvas2.UID)
    
  • Bro, it's amazing!

    Thank you, it works!

    I leave the link with my test.c3p with correct solution for others

    drive.google.com/file/d/1KqfnL9MCWvyJ_PxEBA7QLnfSOkc1ZEC9/view

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