R0J0hound's Forum Posts

  • Well, in general the file (png/jpg) is loaded into memory an uncompressed and finally copied into video memory as a texture. In the browser/construct world the image file is loaded into an html img element before it's copied over to a webgl/webgpu texture. Presumably the browser may also load the image to a different texture too if it were to display the image onto the page outside of construct's renderer. However, the exact details of the browser renderer and even construct's renderer are a black box.

    But we can still calculate how much video memory an image would take up. For example, if a 4k image is 4096x2160 then the uncompressed size would be approximately 34mb. (width*height*4/1024/1024).

    1. Seems reasonable that loading three images instead of one would use more memory. For the html image to display it has to load into vram before the browser can render it. The question as to why the amount of vram usage is bigger than we calculate is largely due to the black box nature of the browser and construct's renderer. Maybe they need more textures to composite stuff or whatever.

    2. Yes, when you clone the object types it duplicates the images. Guess you could make a request to have construct check to see if images are duplicated to save memory but that would slow down export times a lot.

    3. Yes, but you could have tested that. Instances of the same type will share textures.

    4. Presumably it loads a new texture.

    5. It's likely more performant to just render everything onto the canvas instead of layering the canvas with html images. Also, you can't do the same things with html images as you can do with sprites. But luckily, you can do whatever you like.

  • Motion is an illusion on computers where objects will jump from one position to another. So yeah, if you move very fast the jump in position can pass over objects so collisions are missed.

    In general in don’t think it’s possible to make events run faster than the refresh rate without a lot of additional logic. Maybe a loop that checks in between positions between the previous and current frame.

    Another idea is to have an invisible sprite that you stretch between the previous and current mouse position and check for overlap with that instead of the mouse.

  • To do the masking one way would be to have a few sprites stacked bottom to top with different blend modes:

    1. TubeInterior - destination-out

    2. Fluid1- destination atop

    3. Fluid2- destination atop

    4. Back (solid color rect that covers tube) - destination atop

    5. TubeOutline - normal

    Effectively you’re erasing a hole and drawing in that. Lets you mask a lot of things at once.

  • It’s probably not a true fluid simulation. Ignoring the ripples you can probably get most of the way there by using blend modes to mask the colored rectangles inside the test tubes. If you calculate the areas that the fluid makes in the tube you probably can adjust the height of the rectangles to make it more convincing, but you may be able to get by without that.

    The pouring mostly just would involve checking if the top of a rectangle was higher than the lip of the tube, then placing a vertical column for the pouting into the tube below. Then just gradually lowering and raising the two rectangle heights. You could adjust the column width based on the rate or whatnot.

    The ripples could be added later. They probably are just looping animations, but I guess you could use mesh distort to move the top edge of the sprite in a since wave. Seems fiddly though.

    Considering the behavior of the pouring is very consistent in those games I’d imagine they mostly just reuse a bunch or premade animations instead of something technical.

    Four animations for pouring out of a test tube at the four levels, and four for pouring in for the four levels. Probably less if they are clever.

  • Well, say you have 52 card instances on the layout. They are all the same type and each has a different animation frame. It's probably easier to create all the instances with events, just make sure you have a "card" sprite with an animation with images for all 52 card images, and the animation speed is 0. Then the events to create all the cards would be:

    start of layout
    -- card: destroy
    
    start of layout
    repeat 52 times
    -- create card at (-1000, 0)
    -- card: set animation frame to loopindex

    We place them at -1000 to just get then off screen, but you could put them anywhere.

    Next we want to setup the player's deck of 8 cards. You likely have some way you want to have the player select them but we will just pick 8 random ones to use. Add an instance vaariable to card called "playerDeck" with a default value of 0, then add an event like this:

    start of layout
    for each card ordered by random(1) ascending
    compare: loopindex<8
    -- card: set playerDeck to 1

    Now we want to pick four random cards from the players deck to put in the player's hand. Add an instance variable to card called "playerHand" with a default value of 0, and add an event like this:

    start of layout
    card: playerDeck=1
    for each card ordered by random(1) ascending
    compare: loopindex<4
    -- card: set playerHand to 1

    Then picking a random card from the player's hand is just a matter of two conditions:

    card: playerHand=1
    system: pick random card instance

    To remove a card from the player's hand you'd just set playerHand back to 0.

    Anyways, that covers the picking of the cards. It's up to you how you'd move them around.

    It's one idea at least.

  • Setting the camera location in the "look at" action would make the camera angle to the standard 22.5 degree view. For 45 you'd remove the /2. That 1.125 was a correction to make the tile diamond exactly 2:1.

    player.x+1000
    player.y+1000
    player.z+1000*sqrt(2)/2*1.125

    Anyways, that will still have perspective, so to remove that you need to change the layout property "projection" to "orthogonal". However, with orthogonal you lose the ability to zoom in and out.

    To keep the ability to zoom in and out you could keep the projection as perspective and make the "field of view" to be very small to make it nearly orthogonal. The smaller FOV will zoom in more so you'll need to move the camera further back so you may end up needing to increase the advanced project property "far distance" if things disappear. Increasing that will also increase z-fighting artifacts, so you may be able to increase the "near distance" as well to reduce that just as long as things don't disappear.

    You may also be able to counter that near/far fiddling by scaling things in other ways, but I haven't tested that.

  • The instance variable idea sounds like it would work.

    If all the cards were just one object type and had different animation frames and variable values and all the cards were created. then just picking 8 from that and in turn four from that would be fairly easy with events.

    Some like having different cards be separate object types. In which case putting all those types in a family would be an option. But again to make it easy to pick you’d want all the instances created beforehand.

    Some like the idea of not having to have a card instance for every card in the deck, so instead you could instead create/destroy the cards on the fly. Simple to do but it will throw a slight inconvenience with picking events. Namely there has to be a so called delay after creating instances so they can be picked normally.

    The closest point is at the next “top level event” but I’m not sure anyone else has utilized that.

    The next closest would be at the end of the frame. Using a wait 0 action defers to the end of the frame.

    Others have tried the next frame or waiting some longer period of time.

    Anyways, I’ve found it cleaner to avoid that altogether and just create the instances beforehand or at the start of the layout. With the cards being a single object type you can just change one card into another by changing its properties instead of creating/destroying.

    Personally I’d be inclined to do the first idea. One object type for all cards. Create each card on the layout and customize each of their animation frames and variables. Some of the variables could be deck=0 and hand=0. You’d just set any to 1 that you’d want to hold. It’s easy to pick them by variable in events. You could just move the other instances off screen.

    The second iteration could be to do the same thing but instead of creating all the cards I’d just create all the ones in your deck. Then I’d have an array or json with all the specs or each possible card and then change the created instances from that.

  • Looks like your requirements were simpler than I thought after looking at your c3p.

    Updated and tested this as working in events. Adapting it to js will require you to convert the fov of 45 to radians.

    It takes the height of the viewport, 45 which is the fov, and the center of the screen which can be the scroll center or just half the viewport size if there is no scrolling.

    zplane = -100
    scale = 1-zplane*tan(45/2)/(Height/2)
    
    x = (mouse.x - center.x)*scale + center.x
    y = (mouse.y - center.y)*scale + center.x
    z = zplane
  • So it’s mostly just a matter of calculating the intersection of the mouse ray (camera to mouse) and the plane at z=-100.

    So the long way of calculating the mouse ray would be to consider the mouse position on a 2d layer and make a vector from the center of the screen and camera eye distance ( can be calculated from screen size and fov) to the mouse position. Then you’d need to rotate that by the camera’s orientation matrix and adding the camera position.

    The simpler way to get the mouse ray could be to leverage existing c3 features. If you get the mouse position on a 3d layer it will give you the xy of the mouse projected on the z=0 plane. So the ray would be from the camera to that.

    So, anyways the generic formulas for a line and plane are:

    P=p1+u*(p2-p1)

    N dot (P-p3)=0

    And the intersection can be found by combining the two formulas and solving for u:

    U= (N dot (p3-p1))/(N dot (p2-p1))

    And finally plugging that back into the line equation to get the actual point.

    However in your case it all can be simplified at lot.

    P1 = camera.pos

    P2 = vec(mouse.x, mouse.y, 0)

    P3 = vec(0,0,-100)

    N = vec(0,0,1)

    So barring any errors the final equations should be:

    PlaneZ =-100

    X = lerp(camera.x, mouse.x, -planeZ/camera.z+1)

    y = lerp(camera.y, mouse.y, -planeZ/camera.z+1)

    Z = planeZ

    Just make sure the mouse coordinates are from a 3d layer. You can specify the layer you get the mouse coordinates from with mouse.X(layer)

  • Looks cool as always.

    Is there a particular project that you're making to utilize this? Or is there any end goal feature set you want to have?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • One way could be to have a dummy 3d object that you rotate (since you said you have been able to do that).

    Then just set the 3dcamera’s orientation from that object’s orientation.

    The main issue is there are three ways to specify 3d orientation: Euler, quaternion, and 3x3matrix. Most objects let you use Euler and quaternion, but with the camera you can only set the orientation in a general way with the look at action which basically takes a 3x3matrix.

    You can convert between the different orientation representations with some math that you can find online. For example:

    euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/index.htm

    So say you have an object’s orientation as a quaternion (qx,qy,qz,qw) which there are expressions for. Then you can convert it to a 3x3 matrix. In the matrix the second row would be the up vector, and the third row would be the forward or basically the look at vector if you add the camera position.

    So the parameters for the look at action should be:

    Camera x = self.x
    Camera y = self.y
    Camera z = self.z
    Look x = 2*qx*qz - 2*qy*qw +self.x
    Look y = 2*qy*qz + 2*qx*qw +self.y
    Look z = 1 - 2*qx^2 - 2*qy^2 +self.z
    Up x = 2*qx*qy + 2*qz*qw
    Up y = 1 - 2*qx^2 - 2*qz^2
    Up z = 2*qy*qz - 2*qx*qw

    The qx means 3dobject.QuaternionX In those expressions if that’s not clear. Same for qy, qz and qw.

    Anyways, barring any typos on my part or some oddity in c3 then that should work.

    You could also convert between Euler and matrix instead. But you’d have to try different rotation orders if c3 rotates xyz in different orders than the formulas.

    Maybe c3 will hide the complexity at a later date and just let you set the camera’s orientation from another object, or just give everything the same rotation tools. But short term things seem to look more and more cluttered to me.

  • You need to edit the function and specify the return value type there.

    Just using the return action isn’t enough.

  • I think most missing things are usually an oversight that a quick feature request could probably remedy.

    So apart from agreeing that such a feature sounds like it could be useful, I don’t have much to add.

  • Maybe you could set an instance variable in the timeline that’s normally a different value. Or if you specify the instance at runtime with the “set instance” action you could try to keep track of it then too.

    If you don’t mind a multiple build step approach you could make a tool to parses the timeline information out of the c3p file and sets a json file in the project you can access. Or maybe you could access the exported data file directly and parse out the timeline info from that.

    Scripting wise it may be easier to just request a method to be able to access it from the api.

  • Short of access to the actual project and someone taking time to look through it it won’t be possible to debug.

    That said areas you could focus your attention on is the “or” blocks and “trigger once” conditions. Or blocks tend to bite me often so I carefully ensure they are doing what I intend when I use them.

    Maybe putting a for each in the custom actions may help too. In general many find it simpler to use “for each” in any place that there may be multiple picked instances to make the logic more clear to them.