Scrolling Scene in cocos2d - objective-c

I have a sprite which moves across the screen.so i want to switch between the scenes.how can i do that.i am not interested in using Tile Map.I want just like angry birds scene scrolling.
Any Idea,
Thanks

If i understand what your asking you could just add everything to a cclayer and have everything as a child of it and move the full layer left or right to scroll

As glogic says, create a CCLayer and then add a CCSprite to it with an image much larger than the screen size.
Now in your touch handling code, do something like this...
OnTouchBegin - store position of the touch
OnTouchMoved - calculate distance from stored position where touch started and move the whole layer by that much.
OnTouchEnd - If your sprite has move too far and you have gone off the edge of the sprite, slide it back to the edge

Related

Simple wipe animation for image view

I've scoured the internet and I cannot seem to find any help on this. I want to have an image perform a wipe animation. By that I mean I would like the image itself to fade in from the left to right (not move from left to right, but fade, like reveal itself. I hope that's not a terrible description) I've found material on how to transition the image with a wipe, but it's outdated and I don't want to transition the image, I want to straight up fade it in. If anybody could help me on this I would be incredible grateful. Thank you so much, let me know if I can help clarify anything!
First thing that came to my mind is to have a separate UIImageView, with image something like this: http://www.creativecow.net/articles/ahearn_luke/creating_clouds/images/gradient.jpg (but transparent-to-white).
So - once You want to fade out Your image, You add as a subview a new UIImageView, which has frame like 3 times the width of the original image You want to hide. Once You add it as a subview, visually nothing would change, as the beginning of the hovering UIImageView would be transparent, But then You start animate frame (origin.x) of the hovering UIImageView so that it would be moved to the left side. While this happens, bottom ImageView will be gradually hidden from one side. After animation ends, You remove/hide both UIImageViews.
Not the best solution, but - if You are stuck, and still want the effect... Atleast some option.. Good luck!

Objective C - OBShapedButton and LongpressGestureRecognizer

I have got some special buttons(implemented with the subtype OBShapedButton, the button can have an transparent image and is only clickable on the size of the image) on my view. Now I have the idea to touch on the screen and move around. Everytime when I move over one of my buttons, I want to do something. How can I do that? I tried with the LongpressGestureRecognizer, but I dont know how I can get the objects I touch during the movement of my finger.
Any ideas?
Go take a look at UIControlEventTouchDragEnter in the documentation.

animate pan gesture

i have wrote a subclass of UIView, which in drawRect: draws itself. it is actually something like day-long timeline for movie - it draws time axis with ticks and time text labels. it can be zoomed in up to seconds and zoomed out up to all 24 hours. when its zoomed in, it could be scrolled with pan gesture. so here is the question: how can i implement simple animation, when the finger is lifted, timeline continues to scroll for a while and then stops (with negative acceleration)?
two ideas comes to my mind:
implement animation by myself using another thread
make new class - a subclass of CALayer and then use CABasicAnimation. add this class to the layers of my view. but here i should totally move all my code written for view to new subclass of CALayer, what i dont want to do. would it be ok?
any other ideas?
Wouldn't it be easier to integrate the view in a UIScrollView, let that handle the scrolling and zooming and let your class just do the drawing?

object position relative to a different subview

I am thinking about creating a Game Board view with an array of subviews to form slots for tiles. I plan to have tiles that I can drop onto the board and have them snap into position. The part I am unclear about is when I drop my tile and the touchesEnded event fires, what is the best way to loop through the subviews of my Game Board to see which slot I am over so I can have the tile snap into proper position? Or is there a better way to keep track of all the "slot" positions?
I really don't want to have to hardcode every cell position and then keep track of it if the Game Board ever gets shifted in my view controller.
Check out hitTest:withEvent: and pointInside:withEvent:.
ditto imaginaryboy. you don't need to loop through anything. let UIKit do the heavy work for you. Compute the center point of the piece that was dropped on your board and the use hitTest:withEvent: on the view containing your board.

How can I render a custom view in a UIScrollView at varying zoom levels without distorting the view?

The scenario:
I have a custom view (a subclass of UIView) that draws a game board. To enable the ability to zoom into, and pan around, the board I added my view as a subview of UIScrollView. This kind of works, but the game board is being rendered incorrectly. Everything is kind of fuzzy, and nothing looks right.
The question:
How can I force my view to be redrawn correctly ay varying scales? I'm providing my view with the current scale and sending it a setNeedsDisplay message after the scroll view is done zooming in/out, but the game board is still being rendered incorrectly. My view should be redrawing the game board depending on the zoom level, but this isn't happening. Does the scroll view perform a generic transformation on subviews? Is there a way to disable this behavior?
The easiest way to do this is to render your game board at a really high resolution, then let the ScrollView handle scaling it down to your display size automatically.
Basically, set the contentSize of your ScrollView to something big (say 1024x1024), and make your game board one giant view inside it, of the same size (say 1024x1024). Then simply let the ScrollView handle all the scaling questions. You don't even need to intercept setNeedsDisplay or anything; as far as your game is concerned, it's just always rendering at the highest resolution.