Corona sdk question (newbie) - sdk

I don't understand how can I add images for order with corona sdk (front, top, middle). I mean like cocos2d I can add example [self addChild:bg z:-1]; [self addChild:nextSprite z:1]; [self addChild:secondSprite z:2]; etc. But there is no z:number value with corona sdk..
All what I have noticed is that when I add newImage it come top with previous newImage..do I have to done that with groups..or what..
I got this problem that when orientation change, background image change as well..but when the image change it hide all buttons..(=come top of screen and hides all other objects under)..

To give a specific answer, I solved this problem by creating initial groups and then adding images to those groups as needed.
local bgGroup = display.newGroup() -- renders first
local midGroup = display.newGroup()
local nearGroup = display.newGroup() -- renders last, over other groups
-- create images/etc
bgGroup:insert(backgroundImage)
midGroup:insert(houseImage)
nearGroup:insert(personImage)

As you found out, Corona does not have explicit z-ordering. Objects are displayed exactly in the order they appear in the group. You can re-insert an object at a particular index if you want to change the order it's drawn, but that's about it.
If you have a specific problem you're having trouble solving, I would recommend you post it as a separate question along with some sample source code. But in general, if you're adding a new image and you want it to go in back of existing images, simply use group:insert specifying an index of 1.

group:insert(1,backimage)
group:insert(2,middleimage)
group:insert(3,fontimage)
hope you got my point.

There are a few ways to solve zindex's in Corona SDK
1) The method you suggested where everything is in separate groups.
2) group:insert([int],displayObject) where [int] is the position you want the display object to render in the group. So 1 is on the bottom, 2 would be in the middle, and 3 would be on top.
3) You can use functions like displayObject:toFront() or displayObject:toBack() to re-position display objects. You can also re-insert the object into the same group to add it to the top, or even a new position (see method 2).

i would check out
Object.alpha = 0.8 (or whatever number you choose below 1.0)
basically you can make it appear in front of other objects it works fairly well.

Related

Customized UISlider with one more view

I need to create a subclass of UISlider in swift so that it has 3 bar views & 1 thumb image. Currently iOS Provides only 2 bar views & 1 thumb image.
The two bar views are minimumTrackImage & maximumTrackImage.
I need one more bar view on right hand side which is permissible limit of UISlider. i.e if slider has current value 50 max allowed value value is 100. I can able to set Permissible limit to 80 and slider will look like as below.
Could anyone please help...
Here is an example I quickly put together that hopefully shows what you need (see github-link below)....
Link to the example "permissibleLimitSlider" on GitHub
(The solution is done with Swift-3.1, Xcode-8.3.3 and iOS-Simulator-10.0)
The trick was:
A) to create a new maximumTrackImage (called "slider-track" in my example). I created that image in photoshop (but you can use a different graphics-program).
B) to add an IBAction (with Event "ValueChanged") from your Storyboard-Slider into the MyViewController. And in this method you simply observe the sender.value and limit it to 0.8
That's how it looks like in my github example:
Feel free to change colors by changing the Asses-images in the project!
Hope this static limit (of 0.8) is what you need. If you need a dynamic limit (settable in code), I suggest you provide something like 10 images, make the Slider a "discrete slider" and set your maximumTrackImage to one or the other image whenever you need to...
More examples on how to make your slider a discrete-slider can be found here
A very good tutorial on how to make custom-sliders can be found here

How to draw an editable line in iOS app?

I am developing an app which enable users to draw a connection between different components, I tried to use CGPath to draw a line. But the problem is, the line is not an object which I can not reference it later or edit it.
Since I want to enable the app to create a line when two points in screen is touched, and can delete it if need by touching the line, do you have any good ideas to implement this?
Thanks very much!
I think you're looking for CAShapeLayer. You can change its path property after it's been added to the layer hierarchy and it will update accordingly.

Simulate 360 degree object rotation using multiple images on iOS

I would like to show a swipe-able 360 degree view of a product along a single axis by using multiple images stitched together to make it animated.
I'm new to iOS development, and am hoping to get pointed in the right direction to find libraries or built-in methods that could help me achieve this. I'm guessing this is a fairly common task, but I'm not even sure of the correct terminology. (I'm dabbling in RubyMotion as well, so that would be a bonus if it could work using that approach.)
how i might do it:
get an image showing up in the ui, running on the phone, base case :)
make a 'ThreeSixtyImageView' (subclass of UIView) that contains a big UIImageView.
keep an NSArray of UIImages in your ThreeSixtyImageView class; load up all your UIImages into that array.
keep a number that's an index into that array. when it changes, set the UIImageView image to the UIImage at that array index! hook up a button that increments the index (and show that image) to make sure that works.
add a UIPanGestureRecognizer to track touch state
when the pan gesture begins, remember which image you're on, and where they tapped (as an anchor point)
when the pan gesture updates, subtract the anchor and divide by something that feels nice to get 'how much user wants images to rotate'. this gives you a new image index value.
update your main UIImage with that new image index (into your array)
if there's a step here you don't understand, look in the examples included in the xcode/iOS documentation, and copy their code! the sample code is pretty good, and helped me a lot with editing XIB documents, and learning about GestureRecognizers.
good luck!

Move an overlay Google Maps iOS SDK

I'm basically trying to move an overlay along a path as time moves along. This is how I'm doing it right now:
Imagine that this is all in an NSTimer with new values for position each time.
circle.position = (some moved position)
[overlay remove];
overlay = [smallMap addGroundOverlayWithOptions:circle];
And it basically works but introduces some flickering sometimes, which makes sense because one overlay is being deleted and a new one is added. Is there a function to actually change the position of an overlay without having to remove the old one and add a new one?
At the bottom of the this page it says:
If you wish to make modifications to an overlay after you've added it
to the map, ensure that you assign the overlay to an
id object when it is added.
So could you save the return value of addGroundOverlayWithOptions, and then update its position property later, instead of removing and adding the overlay again?
I haven't tried this, but it seems like it should work.

Modifying Cocos2D Sliding Menu Grid adding an extra BUY ME button

I am trying to use SlidingMenuGrid code inside my app and changing a bit the beahaviour. The thing is I am a bit stuck. In Brandon Reynolds's blog you can find a sample project with the menu which is great. I am very greatful to him for sharing his useful code.
What I want to achieve is a sliding menu where not only the image item can be touched but also an image representing a button with the option to buy the product (or more buttons - example BUY/SELL - USE/STOP USING etc.. RPG Style). In the image below I used a menu item with text but in the final version I will want to use a Menu item with sprite.
SlidingMenuGrid works by accepting an array of CCMenuItemSprite and the API allows to set the display type, nr of columns and rows.
I have tried adding a CCMenu with a selector in the CCLayer where I also add the SlidingMenuGrid instance but unfortunately, even if I enable touches, the selector is never called when clicking on it.
I think that what is happening is that SlidingMenuGrid swallows all touches. I tried to modify it but I don't really understand the code and I was trying to find a simpler and easier solution (e.g. by adding a menu item on the Layer instead of playing with SlidingMenuGrid).
Any ideas or suggestions?
Some previous users have mentioned that they have added a "Back" button to the system by placing it on another layer and setting the menugrid to not swallow touches. I have not tested this but I would think it should work..
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:NO]
See the rest of the comments on the post on my blog for maybe some further information.
-Brandon Reynolds

Resources