Page 1 of 1

Dynamically changing stack dimensions for different devices

Posted: Mon Jul 02, 2012 9:41 pm
by gjtaylor99
I'm still pretty new to all this - haven't yet published an app - so "please bear with", as they say, if I'm asking a dumb question.

I've got a main stack with a sub-stack of 4 cards, each of these cards containing referenced images, identical except that each card is for a different iOS device (iPod/old iPhone, new iPhone, older iPad, new iPad). The main stack will call on the referenced images, depending on which iOS device the stacks are on.

Trying to set up the main stack so that it will dynamically adapt its dimensions to whatever device it's on, I ran into the problem that whatever I did - as I now realise - the original development stack dimensions would always determine the card dimensions in the standalone app if you can get what I mean. There doesn't seem to be any way to change this, and trying to understand what's happening (and get rid of the "black borders") has been driving me crazy.

However, today I discovered that if I set the development stack window to full 1536 x 2048, then whichever device I choose in the iOS simulator, the stack window resizes nicely, and it works too as a stand-alone app on my physical iPhone 4 and iPad 2. At last, now, I can get the background button to resize dynamically to fit each device dimensions in the simulator, and dynamically set the background button's icon to the referenced image in appropriate card of the sub-stack.

All great, but that leaves me wondering if everyone is setting their development stack size to the largest dimensions they'll need. I can't work in iPad Retina size - too big for my monitor. I'm sure I'm missing something basic, but I'm not sure what.

Re: Dynamically changing stack dimensions for different devi

Posted: Sat Jul 07, 2012 12:20 pm
by gjtaylor99
Well, I think I've solved my problem.

Returning to Elanor Buchanan's brilliant tutorials, I see that my mistake seems to be that I forgot/didn't realise that LiveCode will automatically alter main stack dimensions to go full screen on any device without any extra instructions. Looking again at the LiveCode Getting Started Course, at the code in the sample stack in lesson 6 <http://www.runrev.com/developers/docume ... rs-course/> I saw how Elanor had no handlers to change stack dimensions, only handlers to change the dimensions of objects in stacks (controls, images, etc.) triggered by the resizeStack handler.

I copied and tweaked Elanor's code in a small test stack. In the iOS simulator now, whatever dimensions I have set my desktop stack to, the stack automatically changes dimensions to fit whatever device the simulator is set to, and the background image dynamically alters dimensions to fit the stack dimensions without any black border when switching from iPhone to iPad dimensions. It also works perfectly on my physical iPad 2 and iPhone 4. Happy days!

Hopefully now, I'll be able to go on to re-jig the code in my project to dynamically choose suitable images and scale them if/as needed. :)

Digression: Humbling stuff, this, trying to make apps. I heard a researcher saying that any blessed eureka moment requires an extended preliminary period of despair-inducing "writer's block". I do really love LiveCode though: the closest thing to digital magic.

Re: Dynamically changing stack dimensions for different devi

Posted: Fri Jan 18, 2013 3:39 pm
by Tom4c
Geoff,

Many thanks for this post. I was struggling to understand why my mainstack wasn't following instructions! I've come to the same conclusion - that the mainstack for an Android app will automatically size to the tablet's resolution. I haven't tested this with any kind of readout of stack size though (must try that soon). I also assume that card sizes are slave to the mainstack size, so all resizing activity must be applied to the card's objects/controls.

regards,
Tom.