R0J0hound's Forum Posts

  • That said, if everything is 2d facing the camera then you could still use the perspective camera and adjust the size and position of the objects with different z so they are visually unmoving. Even some 3d stuff can be distorted to look unchanged.

    edit:

    Here's how:

    Set camera to Perspective, and add the 3dcamera object to your project.

    Then any object you to undo the perspective scaling to add three instance variables: xx, yy, and s.

    Start of layout:
    -- sprite: set xx to self.x
    -- sprite: set yy to self.y
    
    every tick
    -- sprite: set s to 1-Self.Z/3DCamera.DefaultCameraZ
    -- sprite: set scale to self.s
    -- sprite: set x to (Self.xx-scrollx)*Self.s+scrollx
    -- sprite: set y to (Self.yy-scrolly)*Self.s+scrolly

    or if you want to use arbitrary sized sprites:

    Start of layout:
    -- sprite: set xx to self.x
    -- sprite: set yy to self.y
    -- sprite: set ww to self.width
    -- sprite: set hh to self.height
    
    every tick
    -- sprite: set s to 1-Self.Z/3DCamera.DefaultCameraZ
    -- sprite: set size to (self.ww*self.s, self.hh*self.s)
    -- sprite: set x to (Self.xx-scrollx)*Self.s+scrollx
    -- sprite: set y to (Self.yy-scrolly)*Self.s+scrolly

    You just need to update xx and yy whenever you move the sprite.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It seems to be a bug. Made a simple c3p with an ortho camera that alternates the scaling mode and found the bigger the window the more it zooms with low quality. Can't find a way to compensate since you can't set the layout/layer scale with a ortho camera.

    dropbox.com/scl/fi/a0dhqhrhgkla73jruvowx/ortho_camera_low_high_fullscreen_scaling_bug.c3p

  • You could look into hierarchies, and just set the child/parent relationship with an action when you create child objects. Then drawing lines would be simple as looping over children, picking parent, and drawing lines. It supposedly would look like this:

    start of layout
    -- create pup at (100,100)
    -- adult: add child: pup
    
    every tick
    -- canvas: clear to rgb(0,0,0,0)
    
    for each pup
    pup: pick own parent adult
    -- canvas: draw line from (pup.x, pup.y) to (adult.x, adult.y)

    If you don't need the positioning that hierarchies provide you could use a "parent" variable on the child objects. Make the default value of that instance variable -1. That would look like this:

    start of layout
    -- create pup at (100,100)
    -- pup: set parent to adult.uid
    
    every tick
    -- canvas: clear to rgb(0,0,0,0)
    
    for each pup
    adult: pick by uid: pup.parent
    -- canvas: draw line from (pup.x, pup.y) to (adult.x, adult.y)

    Either way would be fine as long as the parent and child sprites were not the same type or family.

    If you wanted the parent and child to be the same type or family then it would be tricker. In general that type of thing is trickier with the picking system, but one strategy is to pick one, save values to variables, then pick the other.

    For example, if you had a family "dog" with types ("pup", and "adult"), and the family had an instance variable "parent" with a default value of -1.

    start of layout
    -- create pup at (100,100)
    -- pup: set parent to adult.uid
    
    every tick
    -- canvas: clear to rgb(0,0,0,0)
    
    var puid=-1
    var x=0
    var y=0
    
    for each dog
    -- set x to dog.x
    -- set y to dog.y
    -- set puid to dog.parent
    -- pick all dog
    -- pick dog by uid puid
    -- -- canvas: draw line from (x, y) to (dog.x, dog.y)

    Observe that the last event should have a sub-event starting with "pick all" (sub-events are harder to depict with text).

    Anyways, just some ideas.

  • So the drawing of the lines between the children and parents is what you’re having issues with?

    Sounds as simple as looping over each object and if it has a parent, draw a line between the two object positions.

    Or are you having issues of a different part of it?

  • So I had a go at trying to distort a mesh to give collisions that match the polygons and it works pretty well. I'm not sure if juggling a separate object from a different plugin is feasible though.

    dropbox.com/scl/fi/9ynvheoi016450691vt86/poly_plugin_collisions.c3p

    It only works with the exterior polygon though. Unless there is a easy way to merge the holes with the outside so it's one polygon like this:

    Anyways, some feedback:

    Maybe you could make the Polygon.PointWorldX expression work with numbers as well as strings? I had to use Polygon.PointWorldX(str(loopindex)) instead of Polygon.PointWorldX(loopindex) to access point locations. Nothing major, but thought I'd bring it up.

    I see that you can set the scale of an svg when you load it, but are there any plans to be able to scale polygons after they are created?

    Other than that, pretty cool plugin.

  • Ok, I made an example for both snapshotting an area and pasting to the drawing canvas. I don't think I like either now, but they do both work.

    First this example just snapshots a section of the game canvas. Needed to use device coordinates, so had to convert layout coordinates to that. Had to erase a hole into the layout behind the objects before snapshotting to make it transparent. However, what I like the least about this is the resulting image is bigger. Oh well.

    dropbox.com/scl/fi/7e8itd97brskrcyujro1k/snapshot_to_image.c3p

    Second is drawing canvas method. Requires all pasted objects to be the same type or in a family. Pastes them in order of layer then zindex. It can also control the image size with the fixed resolution property of the canvas, which is useful.

    dropbox.com/scl/fi/jbhgyrodyy6oxhzvbs7at/drawingcanvas_to_image.c3p

    Pasting different types in order would need more work, probably inserting the layer,zindex and uid of everything into an array, sorting it, them looping over that. Pasting layers with blend modes or effects would need even more work, but I don't think that's really worth it.

  • All containers do is when you pick/create/destroy one object in a container the other objects in it get picked/created/destroyed.

    Hierarchies connect objects together so you can move/scale/rotate objects together as one. Lets you destroy the whole lineage if you destroy the parent too. It doesn’t provide any automatic picking of related objects.

    Templates let you recreate an object or hierarchy of objects later with the same setup. They do nothing with picking.

    Families are mostly to reduce the amount of events. If you find you’re doing the same events for multiple types, you could instead add all those types to a family and just do the events once with the family.

    The picking system is the main thing that makes the event sheet differ from other coding languages. But you only really have to deal with it if there are multiple instances of something.

  • Bear in mind that pasting and snapshotting are asynchronous so you have to wait for them to finish before you can get the result. So if using expressions to get a canvases imageurl or the imageurl of a snapshot are returning empty strings then those things weren’t done yet.

    If you wanted to store them in an array you’d save the imageUrls which are text. There is an expression for that, but in canvas I think you have to request it first. Snapshotting gives you that when it finishes by default. I’d suggest just loading them as frames in a sprite though. You can add frames to a sprite at runtime.

    I just assumed all the parts were on the same layer, but having multiple are no worries. Change the “for each” expression from “partFamily.zorder” to “partFamily.layerNumber*10000+partFamily.zorder”. Read that as order by layers and then zorder per layer. Although if you’re using sublayers with force own texture, and effects and blend modes on the layers then the pasting mode could be trickier.

    I can make an example later

  • Add wid_switch to the container WID_SUPPLY is part of. You probably should add all the related stuff to the container too.

    Then just remove the pick by uid stuff. That will solve your current picking issues. Without that fix, event 3 in prefabs wouldn't know which supply the switch relates to, so the first one is picked.

  • Oh it ate my message…

    Anyways, the two ways I know of to render to a texture is with a drawing canvas or with the snapshot canvas action.

    For the drawing canvas way and the amount of parts it would simplify things a lot to add all the part sprites to a family (say partFamily). Then to paste them by zorder it would be something like:

    for each partFamily ordered by partFamily.zorder ascending
    — drawingCanvas: paste partFamily

    That would use the blend modes just fine and the background would be transparent as long as the canvas started transparent before pasting.

    The second way would be to make the background transparent, snapshot the canvas, then wait till that finishes before changing anything back. That would capture things exactly as it’s rendered. To make the background transparent you’d basically have to make a transparent hole all the way down through the bottom layer. Easy way to do that could be to have all the parts on a transparent layer and make all the other layers invisible before snapshotting the canvas. Main con with that method is it will make a flicker since it has to render like that for at least a frame to snapshot.

    As to the other scaling stuff, it could be a non issue if you just render the cars at normal scale and then just scaling the image after. Or when placing parts just multiply the offsets and sizes by a scale when placing stuff. Third way would be to place everything at normal scale, then picking all the parts and scaling that. The part family would help with that. Scaling would just take a center position to scale around, a scale factor, and a few actions:

    Set x to (self.x-centerX)*scale+centerX
    Set y to (self.y-centerY)*scale+centerY
    Set size to (self.width*scale, self.height*scale)
  • Collisions could be possible by using a mesh distort on a separate invisible object. For example for a polygon with N points you’d need a mesh of size (N/2, 2). Then (0…N/2, 0) would be set to the first half of the points and (N/2…0,1) would be the second half (note the index order is reversed). I say invisible because while it won’t render nicely, it will have a correct collision polygon.

    Just an idea at least. You already provide expressions for getting points so it’s something users could do.

  • You can limit the slider's position with the clamp expression with the height of the slider and the height of the slider's slot. Actually scrolling an area depends on the height of the scrollbox height and the height of the area inside it. Masking it requires some blend mode juggling.

    frame: destination-out
    spritefont: detination-over
    slot: normal
    slider: normal
    frameOverlay: destination-over

    Then events could look like this:

    You'd just need to update the height of the spritefont if you added more lines.

    c3p example here:

    dropbox.com/scl/fi/ela3v0bemybwdwzamyows/scrollbox.c3p

    The amount of vertical scrolling is semi arbitrary, but you could calculate it to only be a few lines at a time instead of a percentage.

  • Maybe something like

    Every tick

    —sprite: set frame to self.framecount-1-(time*self.animationSpeed)%self.framecount

    The speed has to be a positive value but that would play the animation in reverse order.

  • Probably the closest C3 feature is "custom actions" which are like functions that are attached to an object type. It's just as easy to add as an actual function. Right click on the event sheet and select "add function" or "add custom action".

    Besides that, you could probably implement the logic in some different ways that work better with C3 events. For example, You could skip functions entirely, or only use them to not have duplicate stuff.

  • If the squares are sprites it’s just a matter of looping over them in order. You can use “for each ordered” to do that or if you placed the instances in a specific order then a normal “for each” could work.

    One way to do the events could look like this:

    Var out=“”
    Var x=0
    Var y=0
    
    On button clicked
    — set out to “”
    
    On button clicked
    For each sprite ordered by 1000*sprite.y+sprite.y ascending
    — set x to loopindex%8
    — set y to int(loopindex/8)
    — add (x=0)?”BITMAP “””:”” to out
    — add sprite.animationFrame=0?”.”:”#” to out
    — add (x=7)?””””&newline:”” to out

    Or basically loop over the squares a row at a time and output a . Or a # depending on the frame. Then, as citron mentioned, just add the Bitmap, quotes and newline when at the start or end of a row.