Separating events from framerate, and font issues.

Get help using Construct 2

Post » Mon Dec 07, 2015 5:37 pm

Hi there,

I have an issue with a few things that are all related.
I'm making an Incremental/Idle game to learn C2 along the way.

The income is tied to tick rate, which is affected by framerate. It seems that deltatime is a better option, but there's not many tutorials and I'm still confused about where to put it.
Currently income from one unit works like this:I think to use deltatime it needs to be something like ((Buy1Value*Buy1Stock)/60)/(dt*60), that works but is still effected by framerate.
The /60 can be removed, it's just to update the income quickly.
I've heard I can use Every x Seconds but that seemed to be affected by framerate too.

Using a font and updating text every tick is lagging the game (and income).
I'm trying to use a webfont but it isn't loading on people's browsers, only people who have the font locally.
I've heard I should swap over to a sprite font, I've added one but not sure how to actually use it without replacing loads of text objects, will be a lot of work unless there's an easier way.

Last thing is a small bug, I'm using Scroll To when user presses a button, when it changes the view, the mouse no longer created particles on click. Not a big thing but it's confusing me.

Any help appreciated.

Download of file:
dl.dropboxusercontent.com/u/4044336/Game_NoPlugins.capx
If you download the project file, my example picture of the income is in the Buy1 event group (which is building 1 within the game).
Last edited by Oos on Mon Dec 07, 2015 6:05 pm, edited 1 time in total.
B
5
Posts: 13
Reputation: 251

Post » Mon Dec 07, 2015 5:43 pm

If you'd like people to be able to help, it's not a good idea to have third party plugins..

yours has:

Spritefont+
Csv

Both not used by many users and as such the capx can't be opened by them..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Dec 07, 2015 6:05 pm

I've updated the download link to remove them. I just deleted the events/spritefont+ object, so I'm not 100% sure if that worked.

dl.dropboxusercontent.com/u/4044336/Game_NoPlugins.capx
B
5
Posts: 13
Reputation: 251

Post » Mon Dec 07, 2015 6:15 pm

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.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Mon Dec 07, 2015 6:25 pm

Ah R0J0hound, thanks, the mouse thing was correct, was drawing them to a hud layer.

Just fixing the time now, ty.
B
5
Posts: 13
Reputation: 251

Post » Mon Dec 07, 2015 6:38 pm

i.imgur.com/pahoFYs.png
That works, but when I go in debug mode and lower the frame rate, it seems affected by frame rate and I have no idea why,

i.imgur.com/BuGddtM.png
This is the same, works but affected by frame rate still.
B
5
Posts: 13
Reputation: 251

Post » Mon Dec 07, 2015 6:47 pm

In what way is it affected by the framerate? Is the result lower than you expect?
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Mon Dec 07, 2015 6:49 pm

For some reason debug mode lags for me, but it makes testing this easier.

Normal preview is 60fps, adds +1 money per second.
Debug preview is around 20fps, adds +1 money every 3 seconds roughly.

Is the dt command supposed to be in a tick event? or separate.
B
5
Posts: 13
Reputation: 251

Post » Mon Dec 07, 2015 7:10 pm

"dt" is framerate independent. In a simple example this should give a value around 1 no matter the framerate:
Code: Select all
global number t=0

every tick
> add dt to t

time=1.0 seconds
> text: text=t


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.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Mon Dec 07, 2015 7:25 pm

Pretty sure this version has no plugins:
dl.dropboxusercontent.com/u/4044336/Game_NoPlugin.capx
I use the csv for an array for cleaning up large numbers, but that version above should show the total money, if you buy 1 of the first building you will see it increases differently depending on frame rate.

And thanks for stuff earlier, helped a lot.
B
5
Posts: 13
Reputation: 251

Next

Return to How do I....?

Who is online

Users browsing this forum: BackendFreak, farsen, kellehk, lahbach, MadSpy, newt, R0J0hound, TRMG and 21 guests