How do i work out the maths behind what i just did

Get help using Construct 2

» Sun Oct 28, 2012 1:51 pm

ive made my own little parallax system (i find it easier to learn that way )
But i cant work out the maths.

I have a 200 width tile passing through a 100 width layout at 40 pixels a second, and this takes 2.5 seconds.

As youl see in the capx ive managed to get myself into numbers such as 0.828 seconds (when the speed is 60) .

Whats the maths behind this so i can easily calculate this when i need it .
Phew

https://dl.dropbox.com/u/84483952/parallax%20%281%29.capx have
B
15
S
4
G
4
Posts: 179
Reputation: 4,661

» Sun Oct 28, 2012 8:11 pm

You could perhaps use this formula:
speed * time = distance

but solve for time:
time = distance/speed

distance is 100 since you create the tiledBgs with an x of -100
so you get this:
100/40 = 2.5
100/50 = 2
100/60 = 1.666
The last number you had is closer to 50/60 = 0.8333 which also works since the tiledBg texture is 50 pixels wide, you just end up with more overlap.

You can get the same effect without the warmup time by just positioning the tiledBg's in you layout and setting their speed. Then replace all your events with one every tick event:

Every tick
set x to self.x%50-50

Change the 50s to whatever the texture width is.
B
75
S
21
G
48
Posts: 4,663
Reputation: 37,191

» Sun Oct 28, 2012 10:17 pm

Wow!!, i shall study this and try understand it , i get myself in some real messes with this :P

Great response.
I was trying to explain this in church earlier using bricks in the wall lol. Someone thought it was going down half a second for every 10 pixels added or something.

Thanks for the time.
B
15
S
4
G
4
Posts: 179
Reputation: 4,661

» Sun Oct 28, 2012 10:51 pm

Parallax can be a pain to wrap your head around! Good luck!
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,390

» Sun Oct 28, 2012 11:15 pm

im usualy ok, ill make the width of the tile 50000 if i have to , but that has to be effecting performance.

This game here has about 10 layers, all with width of 50000 :P

I know Adam (englishacorn) has a cool way of doing it, but i dont completely get it . Saying that i dont get half my own things.

B
15
S
4
G
4
Posts: 179
Reputation: 4,661

» Sun Oct 28, 2012 11:26 pm

[QUOTE=R0J0hound]

You can get the same effect without the warmup time by just positioning the tiledBg's in you layout and setting their speed. Then replace all your events with one every tick event:

Every tick
set x to self.x%50-50

Change the 50s to whatever the texture width is.[/QUOTE]

working brilliant...
whats does the command self actualy mean though?
B
15
S
4
G
4
Posts: 179
Reputation: 4,661

» Mon Oct 29, 2012 1:50 am

From the manual:
https://www.scirra.com/manual/78/expressions
[quote]The expression Self can be used as a short-cut to refer to the current object. For example, in an action for the Player object, Self.X refers to Player.X.[/quote]
B
75
S
21
G
48
Posts: 4,663
Reputation: 37,191

» Mon Oct 29, 2012 6:36 pm

[QUOTE=R0J0hound]
You can get the same effect without the warmup time by just positioning the tiledBg's in you layout and setting their speed. Then replace all your events with one every tick event:

Every tick
set x to self.x%50-50

Change the 50s to whatever the texture width is.[/QUOTE]

Ive been doing this, but i find that the width/height of the texture doesnt work, just some obscure number i have to take a long time guessing (im sure its related somehow, any idea?)

Here for instance. im doing it with height instead of width and the only number that works seemlessly is 130, which doesnt seem to have anything to do with the height. ?

Here is the capx

https://dl.dropbox.com/u/84483952/130.capxrailslave2012-10-29 19:07:29
B
15
S
4
G
4
Posts: 179
Reputation: 4,661