I was searching for some code sample showing this effect in action. Has it been shared on the forums in the past? How hard would it be to achieve that effect? (Would like to use it for a storybook)
Well, easy to achieve, just setting a layer's position(or even each sprite) with a certain multiplier, in fact we did it for our game even before iOS 7 done that, but then we drop it, since our game is side-scrolling action game, and it made the player feel dizzy. Totally worsen the game.
For story book, i've seen plenty use it even before iOS 7 also.
Well, i deleted the code since i think i won't use it. But it's just like obtaining from accelerometer, then do something like: aGroup:setPosition(x,y) bGroup:setPosition(x * 1.2,y * 1.2) cGroup:setPosition(x * 0.5,y * 0.5)
Edit: forgot to say that you of course need to process x&y obtained from accelero a little bit. And yes, there is a better thing to do this, so it would be smoother. Like giving a target of transition instead of setting it directly.
@Mells sorry but I still don't understand the effect. I watched the video, he is rotating screen, but nothing really changes? :-/ should there be something specific to look for? What should I see?
Ok here is the code. And I've also attached the sample project, hope that helps
application:setKeepAwake(true)--just to keep it awake--paralax speed settings--just to make it really visible--you will probably want to use smaller valueslocal speedX =100local speedY =100local speedRatio =0.5--how many times slower should move the foregoundlocal filter =0.5-- the filtering constant, 1.0 means no filtering, lower values mean more filtering--background imagelocal bg = Bitmap.new(Texture.new("ios7_bg.png", true))
bg:setAnchorPoint(0.5, 0.5)
bg:setPosition(application:getContentWidth()/2, application:getContentHeight()/2)
stage:addChild(bg)--foreground imagelocal fg = Bitmap.new(Texture.new("ios7_icons.png", true))
fg:setScale(0.8)
fg:setAnchorPoint(0.5, 0.5)
fg:setPosition(application:getContentWidth()/2, application:getContentHeight()/2)
stage:addChild(fg)--ACCELEROMETER STUFFlocal accelerometer = Accelerometer.new()
accelerometer:start()local fx, fy, fz =0, 0, 0localfunction onEnterFrame()-- get accelerometer valueslocal x, y, z = accelerometer:getAcceleration()-- do the low-pass filtering
fx = x * filter + fx *(1 - filter)
fy = y * filter + fy *(1 - filter)
fz = z * filter + fz *(1 - filter)--moving background
bg:setPosition(speedX + fx * speedX, speedY + fy * speedY)--moving fore ground
fg:setPosition(speedX*speedRatio + fx * speedX*speedRatio, speedY*speedRatio + fy * speedY*speedRatio)--we can even try to scale them a bit to achieve 3d effect--bg:setScale(1-fx*0.5, 1-fy*0.5) -- but it did not seem to work for me <img class="emoji" src="https://forum.gideros.rocks/resources/emoji/smile.png" title=":)" alt=":)" height="20" />end
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
@ar2rsawseen Wow thank you, I certainly didn't want to reinvent the wheel but didn't expect you to provide a solution. I have modified the script a little bit (it seems to be bg:setPosition(speedX ##-## fx * speedX (...) by looking at the videos, for example).
1. Would you know how to take the natural position of the phone (when holding it naturally) instead of having it flat as a reference point? It should be a matter of applying an offset, I'm going to try too.. Or anyone? Arturs already kindly helped
2. On an iPod 5 the bg is totally offset. Don't need to work on it, you probably have better things to do.
thanks again
Edit : there is also a perspective effect. I don't know how to use Matrices (skew is not the right effect) but I believe it's the way to do it.
@ar2rsawseen Mmm how is Apple doing it with ios7? It seems that they decided arbitrarily the position in which people are using their phone the most (unless they allow users to calibrate which I think won't happen).
From that position (instead of using the raw accelerometer datas when the phone is on a flat surface) they detect the tilt movement, I think.
Well theoretically, currently I'm using x and y coordinates which probably are more meant for the position of the phone where it is in parallel to the ground, like when you put it on the table. if you want to hold it in your hand vertically so it faces your face with screen, you can try replace y value from accelerometer with z value
While you are viewing the iOS 7 home screen, perhaps the front-facing camera is monitoring the offset of your face from the centre of the field of view!
Kate's Catalogue of Travelling Theatre Centres : Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour. She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
I will play more with it and experiment, thanks for showing a way to get started @ar2rsawseen.
If you use some really small values of movement, then you can use it in any orientation, a person has to really move the phone to an angle to see a tilt. Small values of movement would work best (in my opinion)
3D Perspective rendering in iOS also add to that sense of realism, maybe bhWax could help. However you will have to set up additional code to include the Transforms, etc into WAX as it is not included at the moment.
Comments
but then we drop it, since our game is side-scrolling action game, and it made the player feel dizzy. Totally worsen the game.
For story book, i've seen plenty use it even before iOS 7 also.
Yes I do acknowledge the fact that's it's been used way before iOS7 already :
Which I thought would increase the chances that a code sample would have been shared in the forums maybe?
Maybe you have some code sample to share?
But it's just like obtaining from accelerometer, then do something like:
aGroup:setPosition(x,y)
bGroup:setPosition(x * 1.2,y * 1.2)
cGroup:setPosition(x * 0.5,y * 0.5)
Edit: forgot to say that you of course need to process x&y obtained from accelero a little bit.
And yes, there is a better thing to do this, so it would be smoother.
Like giving a target of transition instead of setting it directly.
Do you see what is happening here?
or there :
I don't know well how to explain, all layers don't tilt with the same factor (depending on their virtual distance from the screen).
And I've also attached the sample project, hope that helps
Likes: fxone, Mells
https://play.google.com/store/apps/developer?id=My+name+is+Originality
Wow thank you, I certainly didn't want to reinvent the wheel but didn't expect you to provide a solution.
I have modified the script a little bit (it seems to be bg:setPosition(speedX ##-## fx * speedX (...) by looking at the videos, for example).
1. Would you know how to take the natural position of the phone (when holding it naturally) instead of having it flat as a reference point?
It should be a matter of applying an offset, I'm going to try too..
Or anyone? Arturs already kindly helped
2. On an iPod 5 the bg is totally offset. Don't need to work on it, you probably have better things to do.
thanks again
Edit : there is also a perspective effect. I don't know how to use Matrices (skew is not the right effect) but I believe it's the way to do it.
And by taking reference point, you mean in the state phone launched the app, and then go relatively from there?
Mmm how is Apple doing it with ios7?
It seems that they decided arbitrarily the position in which people are using their phone the most (unless they allow users to calibrate which I think won't happen).
From that position (instead of using the raw accelerometer datas when the phone is on a flat surface) they detect the tilt movement, I think.
if you want to hold it in your hand vertically so it faces your face with screen, you can try replace y value from accelerometer with z value
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
3D Perspective rendering in iOS also add to that sense of realism, maybe bhWax could help. However you will have to set up additional code to include the Transforms, etc into WAX as it is not included at the moment.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps