R0J0hound's Forum Posts

  • If the framerate dips below 10 fps then dt is capped at 0.1 so time passed won't be accurate. Usually you design your game to run much faster than 10fps so that isn't really an issue.

    If you really must have it be correct with a framerate below 10 then you could use the wallclocktime expression.

    Basically add this to the top of your event sheet, and then use mdt in place of dt everywhere else.

    global number mdt=0

    global number prevTime=0

    every tick:

    set mdt to wallclocktime-prevTime

    set prevTime to wallclockTime

  • "dt" is framerate independent. In a simple example this should give a value around 1 no matter the framerate:

    global number t=0
    
    every tick
    

    add dt to t

    time=1.0 seconds

    text: text=t[/code:c0mzc8r0]

    No idea why you're getting a framerate dependent result. I don't have cvs plugin installed and you use it everywhere so it's essential to your capx. Maybe I'll install it later but I'm lazy.

  • A plugin can't be made to do that since it's something fundamental that the engine controls, and would need to be changed in the engine itself.

    The purpose of moving stuff with events is in C2 only redraws if something moves or changes viually. If nothing visual changes then the runtime doesn't redraw and just reuses the previous frame's image. By controlling when we move stuff we can control when the screen redraws.

  • In what way is it affected by the framerate? Is the result lower than you expect?

  • For the time:

    dt is the time between the last frame and the current one. It's used in cases where this makes sense:

    rate * time = amount

    For example say a car is going 100 pixels per second then the distance it moves in a frame is

    100*dt = distance

    In the same way if your rate of earning money is (Buy1Value*Buy1Stock) and you can find the amount you earn per tick with:

    (Buy1Value*Buy1Stock)*dt

    Now if you want to update the money with a "every x seconds" then "x" is the time you multiply by instead of dt.

    Every 1.0 seconds

    add (Buy1Value*Buy1Stock)*1.0 to money

    Both are framerate independent, and you should get the same amount added per second either way.

    For the text:

    If you want to switch over to spritefonts, which are faster at rendering, you'll have to manually change everything over. You can keep the normal text objects instead and make it a bit faster if you set "webgl" to off, but that may not be an option if you want to use effects.

    And lastly the mouse "bug":

    Mouse.x and mouse.y use the mouse position on the first layer. I haven't opened your capx but I'd assume the first one is the hud which doesn't scroll. You can use the Mouse.x("layer") expression instead to get the mouse on the layer that scrolls instead.

  • In that case the events could look like this. There's no avoiding the "for each", and even if you could it would still be done internally. For example the "pick closest" condition will actually loop through the objects to find the closest.

    global number x=0

    global number y=0

    global number obj=-1

    For each sprite

    set x to sprite.x

    set y to sprite.y

    set obj to sprite.uid

    --- pick all sprite

    --- [inverted] pick sprite instance by uid obj

    --- sprite: pick closest to (x,y)

    --- > do something

  • Zebbi

    You would have to add up dt for the ticks you don't use.

    Here's my idea. It adds dt to mydt every tick. Then every forth tick the "code" group is enabled which moves the objects around using mydt instead of dt. At the end of the group mydt is reset to 0.

    https://dl.dropboxusercontent.com/u/542 ... 15fps.capx

    This could get very tedious to do. You can't use behaviors or animations with sprites, you'll have to do everything with events to ensure objects are only redrawn on that one frame. On a side note as far as the engine is concerned the fps is still 60 fps but we're only redrawing at 15fps.

    LittleStain

    I suppose you could but it wouldn't save on any performance which I assume this would be for.

  • You could add an image point on the animated object and just set the other object's position to the imagepoint every tick. You could also change it so the animated sprite actually is moving so you could use the pin behavior.

  • They do different things so I'm unsure of the comparison.

  • You can't change the refresh rate of the game with C2. I believe a half framerate (30fps) was attempted before but it didn't perform well with html5, the result wasn't smooth. A search could probably give more info.

    That said C2 only redraws if something has changed position. So you possibly could force lower redraw rate by only moving the objects every other tick or something. It wouldn't work if you used any behaviors since they update every tick but with just events it could work. Probably more trouble than it's worth though.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could do it like this. First you pick the object and save it's x, y and uid to some variables. Next you use an inverted "pick by uid" to pick all the instances except the original instance. The you can use the "pick closest" condition as usual.

    global number x=0

    global number y=0

    global number obj=-1

    pick sprite at random

    set x to sprite.x

    set y to sprite.y

    set obj to sprite.uid

    [inverted] pick sprite instance by uid obj

    sprite: pick closest to (x,y)

    do something

  • It looks like you'll need to call this function:

    CollisionPoly_.prototype.cache_poly = function(w, h, a)[/code:1bjeiulg]
    The only catch is it won't update if the width, height or angle haven't changed. So you'll probably need to change one of those first.
    
    I only took a quick look so I didn't investigate where that function is usually called.  You may even be able to change the size or angle of the object to force a update without calling the function if it's called every tick anyways.  Or instead you could change the .cache_width value from the polygon.
  • Waltuo

    It was mainly as an exercise to see how physics is implemented, so I didn't get it to a perfect state. I'm sure the collision detection could be better, maybe using SAT instead of what's currently in place would help.

    As far as adding sleeping I'm sure it could be added but I haven't looked into it. Basically there is a whole lot missing with it so it is mainly for amusement right now.

  • Here's one way

    Every tick

    Sprite: move forward 100*dt pixels

    Sprite: rotate 10*dt degrees clockwise

    Sprite: set X to self.x+50*dt

  • You need to adjust where the origin is on your Sprite. You can do this in the image editor.