R0J0hound's Recent Forum Activity

  • 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)
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • The actions that call the function are the ones to look at if you want to know how it specifies the uid to use.

    Since c2 functions don’t know what was picked when you called them you often need a way to specify what instance to pick. Passing an object’s uid as a parameter is one way to do that.

    As a minimal example it could look like this:

    On function: “rotate90”
    Sprite: pick by uid function.param(0)
    — Sprite: rotate 90 degrees
    
    Start of layout
    For each sprite
    — call function “rotate90” (sprite.uid)
  • That’s a pretty cool idea. Erase a hole and draw in the hole. I’ll be adding that to my toolset.

    Edit:

    Main limitation of that method is the mask needs to be completely contained within the object's pixels. And it doesn't work on transparent layers with force own texture. Still pretty cool.