# math

Get help using Construct 2

### » Tue Aug 14, 2012 2:54 am

is there a way to learn the math on the games or these stuffs couldn't be learned??? i'm talking about math of sprites , layouts , window , ... see this example made by @kyatric
Example capx in the capx you will see something like that :
Sprite2.X - (Sprite2.Width/2) ?? so what does this mean? and how did you know this kind of math ? are there some common Equation like that or they are uncountable? also if it uncountable ... is there a math book that can help us on that? i know this one of the weirdest thing you ever hear but in my country they doesn't focus in shapes on math only one term of shapes on secondary school with only basics like get square meters and so on..

B
52
S
16
G
7
Posts: 795
Reputation: 12,870

### » Tue Aug 14, 2012 3:48 am

You learn by practicing, and examining examples.

Sprite2.X - (Sprite2.Width/2)

It means exactly what it says: The X position of the sprite, minus half of its width. It's completely logical, just think about it.
B
49
S
10
G
9
Posts: 1,224
Reputation: 8,480

### » Tue Aug 14, 2012 4:14 am

@Davioware
yes i know its what it what it looks like.
see the example has an equation looks like this :
Sprite2.X - (Sprite2.Width/2) >= Sprite.X - (Sprite.Width / 2)
so the question is why he didn't use this :
Sprite2.X >= Sprite.X
what's the differences? also is there something that can help me in some other equations?
...how can i keep exam examples if i don't know what i'm looking for? that why i'm asking if there is some common examples that i can try to check the differences.
B
52
S
16
G
7
Posts: 795
Reputation: 12,870

### » Tue Aug 14, 2012 4:26 am

The width of Sprite and Sprite2 are different, so it can't be shortened.

In addition to what Davioware said it often helps to draw a diagram out to visualize. Also if you know what you are trying to calculate you can find a formula for it with google most of the time.
B
97
S
36
G
131
Posts: 5,514
Reputation: 83,466

### » Tue Aug 14, 2012 5:06 am

@R0J0hound
ok lets say i have 3 kind of enemies and i want them to with this order:
-enemy1,(space = the enemy2 width),enemy2,(space = enemy3 width),enemy3
-in math ways lets say enemy1.width = 20 and enemy2.width = 40 , enemy3.width = 60 so it will be like this :
enemy1 then space = 40 then enemy2 then space = 60 then enemy3 so it will be a row with 3 enemies with this kind of stuffs .

another example lets say i have a sprite 5x5 then i scaled to fit 1000x3000 and i want in the start of layout to have another sprite to have a position on every 50 in width so it will be a line with about 20 sprite... and so many other examples so how can i search them on google? because i never tried to search equations on google
B
52
S
16
G
7
Posts: 795
Reputation: 12,870

### » Tue Aug 14, 2012 6:54 am

I would suggest you to check Khan Academy since it has some very good video lessons on almost all math related subjects, from the very basic to more advanced ones.

As of your examples, I think you need some understand of basic programming as well, maybe how a loop works. Besides that, tackle a problem one step at a time, asking yourself each basic question that will form the big answer you are looking for. If you can't find it by "googling" it, probably you are asking the wrong questions.

If I understand your example right, you have 20 "cubes" that you need to be put side by side, for a start. Since you know the amount, you can just spawn the right quantity with a "repeat 20 times" loop and a "create" action.

So, if you want to put a cube next to other, from the left to the right, how would you do? The first one needs to be at 0 distance from the left side, so it is right at the side. The second one needs to be at 1 times the width of one cube, so it it right next to the first. The third one at 2 times the width of one cube, so it gives space for the first two. The forth at 3 times the width... As you may have noticed there is pattern here:

next X position = number of cubes * width of one cube.

As an addendum, the repeat has an index, called "loopindex", that returns the number of the current repetition, starting from 0. Back to the repeat loop, you need to fill in the X of it (next X position) with that expression, so, we know now that the repeat has a loopindex that returns a number, if we are creating cubes at each repeat, that loopindex tells us the number of cubes it had created. The width of a cube is a basic expression, you can see it at the expressions help.
So, into the "Create object" action, in the X position, you can translate our "equation" to:

X = loopindex * cube.width

But if you need to add a space between each one, so it it not all side by side? Well, like it is said, you need to add. So to keep the layout divided by 50, so you have 20 cubes evenly spaced, you must add 45 pixels of space to the 5 pixel cube.

X = loopindex * (cube.width + 45)

and that is it, if I understand you right. 20 cubes, 5 pixels wide, evenly distributed on a 1000pixels layout.

The only real tricky part here is the loopindex, but it is part of the sintax of construct "language", you will need to learn it. Construct is very forgiving in that area, with not much to learn, but you will need basic programming knowledge and basic math knowledge, no way around it.
B
16
S
7
G
4
Posts: 29
Reputation: 4,957

### » Tue Aug 14, 2012 2:20 pm

@dEspadas thanks for your help , i have a question in khan academy what should i learn? math? or what?? also which lessons should i study that has some math on shapes and these kind of stuffs.

also someone told me to learn the basics of game design is that true? or it is completely different?
B
52
S
16
G
7
Posts: 795
Reputation: 12,870

### » Tue Aug 14, 2012 3:45 pm

if your making games then you cant go wrong to read ANYTHING related to game design. Theres no reason not to read and learn from everything you can
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

### » Tue Aug 14, 2012 3:52 pm

@aridale ,
yes but there is alot of books of that kind of subject which one will be the most helpful for construct2 users?

and should i read it all or just the part that i'm stick with it?
B
52
S
16
G
7
Posts: 795
Reputation: 12,870

### » Tue Aug 14, 2012 4:23 pm

Wolfire made a interesting series of blogposts about the subject:
http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-1
B
39
S
8
G
3
Posts: 440
Reputation: 6,903

Next