Hide / show code on sim or device

I don’t know if this is possible but can you wrap certain code with keywords so that certain logic gets called in the simulator and other on devices

Specifically Im thinking of Corona Remote code which obviously when on a device doesn’t work and I then need to revert back to the vent handler for accelerometer. Of course the technique isn’t just limited to this scenario though

Any thoughts or direction please [import]uid: 103970 topic_id: 19582 reply_id: 319582[/import]

You can use this API http://developer.anscamobile.com/reference/index/systemgetinfo - if it’s running on a simulator it will tell you so. (So you could set a flag in your functions of the like.)

Peach :slight_smile: [import]uid: 52491 topic_id: 19582 reply_id: 75670[/import]

Thanks Peach

So from what I can glean I would do something like this:

[lua]if(system.getInfo(“environment”) == “simulator”) then
Runtime:addEventListener( “enterFrame” , updateAccelerometer )
else
Runtime:addEventListener (“accelerometer”, onAccelerate)
end[/lua]

the simulator as it always has done works fine with the Corona Remote but the alternative onAccelerate method (which is taken from your tutorial peach with the landscape fix) doesn’t seem to work.

Similarly I have applied a scale fix to the settings page as follows:

[lua]settings =
{
orientation =
{
default = “landscapeRight”,
supported =
{
“landscapeRight”,
},
},

content =
{
scale = “zoomEven”,
fps = 60,
},

iphone =
{
plist =
{
UIStatusBarHidden=true,
UIPrerenderedIcon = false

},
}

}[/lua]

But when tested on the iphone 4 (retina) the scaling seems to have no effect as right proportions on the simulator but doesn’t scale up to the resolution of the iphone 4 so everything is very small.

The reason I posted both scenarios here is that is there something wrong with my build to a device or can you see two issues with the code I have posted is it isn’t having the desired effect

Thanks in advance
[import]uid: 103970 topic_id: 19582 reply_id: 75798[/import]

Right sorted both issues and will document in case anyone else has similar challenges

The first regarding the perceived lack of accelerometer movement on device was because I was working out the bounding area (so main actor couldn’t go above or below the scree boundary) which was hard coded to an iphone resolution i.e. 300 and setting to this if ever higher. Because I was also testing on the iPhone 4 with a much greater resolution the start in the middle was already at 300 so was getting into a loop of never moving. So a change to display.contentHeight resolved this issue. This is particularly important when supporting multiple devices / resolutions

The content scaling issue was a newbie error on my part. I thought this was going into the build,settings file and had misread some instructions somewhere and that it had to go into the config.lua file. Also important was the ensure that I specified the main .default resolution (height and width in portrait) so it knows what it is scaling from. As a result the config.lua file had to look like this:

[lua]application =
{
content =
{
width = 320,
height = 480,
scale = “zoomEven”,
fps = 60,
},
}[/lua]

Worth reading the runtime configuration api (http://developer.anscamobile.com/content/configuring-projects#Runtime_Configuration:_config.lua) page a couple of times for it all to sink in. Also make sure you follow this:

**The basic idea behind dynamic content scaling is that you can tell Corona that your content was originally authored for a particular screen size. Then you can choose how your app should be scaled if it runs on a device whose physical screen size is different from the original.

Note
If you are building an application to run on a single device then it is not necessary to specify any content height, width, or scaling options.

If your application does support running on devices with different screen dimensions, the width and height MUST be the value of the target device in portrait orientation. These values are not dependent on the orientation mode of your application. If your app runs in landscape mode, you still set these values to the portrait width and height. Use the “orientation” setting in the build.settings file to define the orientation modes supported by the application.**

Hope this helps someone [import]uid: 103970 topic_id: 19582 reply_id: 75848[/import]

… and if you want to have a switch between simulator specific code and device specfic i.e. switching Corona Remote on or off do something like the following as Peach suggested:

[lua]if(system.getInfo(“environment”) == “simulator”) then
Runtime:addEventListener( “enterFrame” , updateAccelerometer )
print(“Simulator”)
else
Runtime:addEventListener (“accelerometer”, onAccelerate)
print(“Device”)
end[/lua] [import]uid: 103970 topic_id: 19582 reply_id: 75849[/import]

Glad you solved this, sorry I didn’t get back here sooner.

Thank you for posting such a thorough follow-up, I’m sure it will be incredibly useful for others in the future :slight_smile:

Peach [import]uid: 52491 topic_id: 19582 reply_id: 75904[/import]