R0J0hound's Forum Posts

  • Is it all the odd numbers from 1 to 100?

    int(random(50))*2+1

    Or is it a different set of odd numbers?

  • Can’t open the project, but filtering can be done by looping over each entry in the array, checking its length and removing it if needed. The only catch is you’ll want to loop over it in reverse.

    Array: for each x
    Compare: len(array.at(array.width-1-array.curx) >3
    — array: remove at array.width-1-array.curx
  • Skimming over it it doesn’t look like there’s anything preventing it from being ported over.

    The vertex shader portion doesn’t do anything, which is good since construct doesn’t let you modify that anyways.

    The fragment shader has a bunch of uniforms: floats and vec2s which can be two floats.

    The rest would depend on if GLSL is the same for webgl and OpenGL. So there may be a need for some fiddling.

  • That’s kinda what I meant with calculating. You’d effectively be just doing all the math that mouse.x/y does behind the scene. Which would work but I don’t think it provides much benefit.

    As for the lagging of the sprite behind the actual mouse cursor. I thought that was just because of latency between code and the drawn frames or 1/60th of a second.

    An alternative is the to set the mouse cursor from a sprite, which doesn’t lag behind but it’s on top of everything as it’s not truly a sprite then. That reason that doesn’t lag is the operating system is drawing it then which is more input event based instead of frame based.

    Anyways unless the lag you’re seeing is something different. In which case I’m all for tightening it up if possible.

    Edit:

    It just occurred to me that when you scroll some stuff doesn’t get recalculated till the end of the tick. For example viewportLeft(). It possibly could be the same for the mouse(layer).x expression. That could be lag you’re getting which is different than the other one I mentioned.

    You’ll have to test it but assuming that that setting the scroll position causes mouse.x to update till the next tick you can order your events like this.

    Basically before scrolling, save the scroll position to variables. Then after the scroll correct the position.

    Set sprite x to mouse.x

    Set oldScrollx to scrollx

    Set scroll position

    Set sprite x to self.x-oldScrollx+scrollx

  • Best I can tell construct only provides the viewport* expressions to find the width of the view in layout coordinates.

    The browser object, in the c2 docs at least, mention screenWidth and screenHeight as values too.

    With js you can also get the width/height of the html canvas if you really want to handle it from scratch.

    There’s also the system expressions layertocanvasx/y and canvastolayerx/y expressions that may be useful.

    Does it only happen in full screen?

    Honestly for positioning things don’t use absolutex/y. You can use it to see if the mouse moved.

    Otherwise as an exercise in math you can map the absolute mouse position to the layout position in a correct way.

    ///////////

    Intuitively you should be able to put your cursor sprite on any layer and position the sprite with

    Set position to mouse(self.layer).x, mouse(self.layer).y

    And it’ll just work, full screen or not. If it doesn’t then it’s a bug I say.

    You can still utilize absolutex/y to check if there was mouse motion. Like

    Global number oldx = 0
    Global number oldy = 0
    
    Compare oldx <> mouse.absolutex
    Compare oldy <> mouse.absolutey
    — do something because the mouse moved
    
    Every tick
    — set oldx to mouse.absolutex
    — set oldy to mouse.absolutey
  • I mean, absolutex/y doesn’t take into account scaling or parallax at all. That’s why the position will differ from the actual mouse.

    Setting the sprite’s position to mouse.x/y will put it right at the mouse, but i don’t know what layer it uses by default. If you need the mouse position on a certain layer you can use mouse(layer).x/y.

    Or if you’re set on using absolutex/y you can adjust it to match with some trial and error:

    X = mouse.absolutex*scale+offset

    Just by eyeballing it it looks like you could start with a scale of 2 and an offset of 0. But any scale or resolution changes could through that off I’d imagine.

  • I never use parallax but not using it with a cursor would make sense.

  • I’m pretty sure that’s what he meant. But no worries. It’s early and I may be reading it wrong.

  • I don’t see how it’s a bad idea. Providing automatic focus on a new pop up window seems like what always should happen.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No that looks right. It would be going 1pixel/sec though. Instead of going forward and back by 1 you can move forward and back by the speed you want it to move.

    If that still doesn’t work then I’m misunderstanding something with how c3 does 3D.

  • Oh I see now.

    You could still use mouse.x instead.

    I mean mouse.x-scrollx which would be relative to the scroll position. Aka even if the screen scrolled that relative position wouldn’t change.

    So it should just be a matter of replacing mouse.absolutex and y

    With

    Mouse.x-scrollx and mouse.y-scrolly

  • Oh strange. I didn’t test it but that sounds like a bug then.

    Guess you could move the camera forward by one, save it’s position to variables. Then move back one and subtract the position from the same variables. That would give you a forward vector xyz.

  • Mouse.AbsoluteX gives the number of screen pixels from the left of the canvas.

    Mouse.X does more. It basically maps where the cursor is to the games coordinates.

    Probably something like

    Mouse.x = (mouse.absoluteX/windowWidth+0.5)*originalWindowWidth*scale+scrollx

    I guess I’m not seeing how absolutex is more useful. Guess I need to try that use case you mention.

  • do you want to shoot the bullet in the direction the camera is facing or do you want to shoot towards the enemy no matter what?

    For both first you need to add three instance variables to the bullet sprite for the velocity. I like to use vx,vy and vz.

    Then to make the sprite move you'd add an event like this:

    every tick
    -- sprite: set x to self.x+self.vx*dt 
    -- sprite: set y to self.y+self.vy*dt 
    -- sprite: set zelevation to self.zelevation+self.vz*dt 

    Now to shoot forward you'd set the velocities like this when you create the bullet:

    on click
    -- create sprite at (3dcamera.cameraX, 3dcamera.cameraY)
    -- sprite: set zelevation to 3dcamera.cameraZ
    -- sprite: set vx to 100*3dcamera.forwardX
    -- sprite: set vy to 100*3dcamera.forwardY
    -- sprite: set vz to 100*3dcamera.forwardZ 

    The 100 is the speed.

    To just shoot toward the enemy you'd do this:

    global number factor=0
    
    on click
    -- create sprite at (3dcamera.cameraX, 3dcamera.cameraY)
    -- sprite: set zelevation to 3dcamera.cameraZ
    -- sprite: set vx to enemy.x-3dcamera.cameraX
    -- sprite: set vy to enemy.y-3dcamera.cameraY
    -- sprite: set vz to enemy.zelevation-3dcamera.cameraZ
    -- set factor to 100/sqrt(sprite.vx^2+sprite.vy^2+sprite.vz^2)
    -- sprite: set vx to self.vx*factor
    -- sprite: set vy to self.vy*factor
    -- sprite: set vz to self.vz*factor
  • So you want to see if two object bounding boxes overlap?

    You can do that with two compares

    Compare: (sprite.bboxright>tilemap.bboxleft) & (sprite.bboxleft<tilemap.bboxright) =1

    Compare: (sprite.bboxbottom>tilemap.bboxtop) & (sprite.bboxtop<tilemap.bboxbottom) =1