Why doesn't this formula work
colander
Member Posts: 1,610
Using this rule in an actor on the left side of the screen moves the actor right towards the centre as intended. But if I shift the actor to the right side of the screen nothing happens when it should move it left towards the centre.
I've been over and over it with a calculator, I must be missing something. Can somebody explain to me why this doesn't work and offer a solution?
I've been over and over it with a calculator, I must be missing something. Can somebody explain to me why this doesn't work and offer a solution?
Comments
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Hi @colander I've tested out your programming and providing that your actor is more than 512, it moves to the left as expected… so at a guess the problem might lie with your boolean condition… maybe try When game.Screenetc =>1024 perhaps…
Edit: beaten by @Socks… :-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
?
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Placing your actor at x=1000 will move it to X=979.66504, is this is what is happening ?
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Clicked preview there should be four standard size actors on the screen like initial scene 1. Go to the top left and select iPad Landscape from the drop down menu and you should get the result in initial scene 2.
For some reason I can attach png files but not project files. aaaahhh! had to zip it it is attached now.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
If x=1,000
self.Position.X -(( self.Position.X -512)*0.04167)
1,000 -(( self.Position.X -512)*0.04167)
1,000 -(( 1,000 -512)*0.04167)
1,000 -(( 488 )*0.04167)
1,000 -(20.33496)
979.66504 (20.33496 pixels to the left).
. . . . . . . .
Anyhow, your project is 480 pixels wide, so the condition 'if screen width is 1024' is never met . . . . ergo: nothing happens.
. . . . . . . .
Edit, just read your post above - about changing project size, yes when you change the project to iPad Landscape - the boxes move as expected - that is to say the formula seems to be working correctly.
65 -(( 65 -512)*0.04167) = 83.62649
415 -(( 415 -512)*0.04167) = 419.04199
For example if the two actors end up being placed at x100 and x924 (100 px in from each side) after selecting iPad Landscape then it should calculate as follows (I think);
self.Positon.X = 100-((100-512)*0.04167) = 117.16804 this works in the example
self.Positon.X = 924-((924-512)*0.04167) = 906.83196 this doesn't work in the example
I'm no math geniuses but it should work shouldn't it?
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
I am taking an iPhone 4 480x320 and using the viewers iPad Landscape in overscan magnifying it so it should look similar to the one I posted but with the mirror image result you have in your one above.
The original screenshots were taken with the creator and are not to scale for some reason I only just realised this. So I used cmd+shift+4 to take the ones below and show them to scale when opened I hope. I'll check it after I post it. The starting state on the left is 480x320 and the one on the right is 1024x768.
When you said "From what I can see 1,000 should move stuff to the left ? (in fact anything above 512 will move stuff to the left)" I forgot to say in my previous post yes that is correct. Sorry about that.
I have repeated some things here I am just trying to make it all as clear as I can. I am definitely not the best at explaining stuff.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Click on my second image above, it is to size and scale and compare it to your image. You must be doing something different than what I described which might help me figure out what I am doing wrong. What did you do to get that result?
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Changed the project size to iPad Landscape.
Placed a Display Text behaviour (showing X.position) on the actor.
Changed the X positions of the actors to X=100 and X=924.
Hit 'play'
Took a screenshot.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
To: game.Screen.Size.Width* (max(0,min(1,self.Position.X-game.Screen.Size.Width/2)) + max(-1,min(1,game.Screen.Size.Width/2-self.Position.X))*%from edge)
(Note: game.Screen.Size.Width is multiplied by the rest of the expression)
Explanation:
max(0,min(1,self.Position.X-game.Screen.Size.Width/2)) will return 0 if the position of the actor is left of the center of the screen, and 1 if it is on the right of the center of the screen.
Multiplying this value by the width of the screen will return either 0 or the screen width.
(Note the switch between the width and position in this part of the expression)
max(-1,min(1,game.Screen.Size.Width/2-self.Position.X)) will return 1 if it is on the left side of the screen or -1 if it is on the right side.
Multiplying this by the screen width and the %from edge will give either a positive value if on the left side of the screen or negative value if on the right side of the screen.
e.g. if %from edge was 0.04167 on a 1024 screen width it would return 42.67(left) or -42.67(right)
Adding those 2 results together and you should get your positions.
AND this doesn't care what screen size you have.
I noticed you used game.Screen.Size.Width which returns 1024 in iPad size. I am using "OVERSCAN" (Sorry about the caps just making sure this doesn't get missed) which magnifies the image by 2.4 and makes the width appear 1152 wide with the sides cropped to the view size of 1024 but self.Position.X is still calculated as if it were on a 480 wide screen so I don't see how game.Screen.Size.Width can work.
Now that I know Preview is working at 480 size I have adjusted my code. The project I have attached has my code in Actor 1 which now looks to be working but is really basic and I cheated to get the number 14.21052 because I couldn't work out the math. It's close but not right.
Could you put your code in Actor 1 overwriting mine in my attached project so I can see it working and maybe begin to understand it. Actor 1 has my code, Actor 2 is just there to see what happens to them when the view is changed and actor 3 is approximately where I want them to end up.
Thank you and everyone for your help with this and remember when you start Preview select iPad Landscape with Overscan.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Original Ratio is the ratio of the Screen.Width/Screen.Height of the project as you build it. In this case of iPhone Legacy, it is 480/320 = 1.5
Using this, when you use Overscan, any ratio(of the current device screen.width/screen.height) greater or equal to this original ratio will mean the screen will stretch the width to fit the screen and cut off from the top or bottom as needed. Otherwise if the ratio is less than the original ratio, it will stretch the height to fit the screen and cut off from the left and right of the screen.
Given attributes OriginalRatio of 1.5 and OriginalWidth of 480
Rule: If OriginalRatio ≤ game.Screen.Size.Width/game.Screen.Size.Height ---Change Attribute: self.Position.X = self.OriginalWidth*max(0,min(1,self.Position.X-self.OriginalWidth/2))+max(-1,min(1,self.OriginalWidth/2-self.Position.X))*(self.Size.Width*.5) Otherwise: ---Change Attribute: self.Position.X = self.OriginalWidth*max(0,min(1,self.Position.X-self.OriginalWidth/2))+max(-1,min(1,self.OriginalWidth/2-self.Position.X))*(self.Size.Width/2+self.OriginalWidth*(1-game.Screen.Size.Width/(game.Screen.Size.Height*self.OriginalRatio))/2)
You can copy and paste these and replace the attributes as needed. Make sure the extra spaces are removed and parentheses are all accounted for.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
I don't need to change the size of any of my actors for iPhone 5 just the position of the HUD actors. I always new I would have to reduce the size of all my actors by the same factor for iPad and thought it would be the easy part "self.Size.Width/2.4*2". I need it to be to within 0.1 of a pixel for some of my actors so I don't think my simple equation will work.
My game is a vertical scroller so I need to keep the iPad screen height but bring all my actors back on the screen an also in the correct size and positions so everything works. I have a ball rolling across uneven ground actors and all of them have to match up exactly for it to work.
My brain is nearly fried from 3+ months of writing my game and learning GS in the process so I think I will leave it for now and come back to this another time. I have made two submissions iPhone and iPad for my game which is obviously two separate binaries, not ideal but will have to do for now.
If someone else would like to continue this thread feel free to do so.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Where do I start with iPad position.X in Otherwise? I had a look but my brain started sizzling
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Not sure what you want to accomplish with the min(self.Position.X, game.origWidth - max(game.origWidth/2, self.Position.X)) so I can't say either way.
The same problem occurs with the formula for iPad in the Otherwise section of the rule, I will go and have a look at self.Size.Width/2 in it over the next few days. Thanks for your help.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template