When there is a touch in a CGRect, do something (Cocos2d Question)? - iphone

I am new to Cocos2d and I am making a game with a SneakyJoystick and a SneakyButton. The SneakyJoystick works fine, it moves the sprite character around the screen. But the SneakyButton is a problem. How do I implement shooting another sprite from the characters position when the SneakyButton is pressed? Do I modify the SneakyButton.h and SneakyButton.m? Or do I recreate the code in the HelloWorldLayer.h and HelloWorldLayer.m? This is extremely confusing and please remember that I am using a SneakyButton, not a button that I programmed myself. Thanks!!!

No, you don't have to modify the code. You just include the SneakyInput code in your project. Then import the SneakyButton headers in your class. Create the instance of SneakyButton and add it to your layer. Then you can just query the state of button if it is pressed or not.
Its very simple, just follow this tutorial from link below,
http://www.qcmat.com/sneakyinput-joystick-dpad-and-buttons-for-cocos2d/

Related

How do I implement a raycast / laserpointer to Oculus controller?

I want to implement a graphic raycaster/ laserpointer to the left Oculus controller, so I can interact with UI buttons in Unity.
I have seen a lot of tutorials etc. but nothing has helped.
I want a laserbeam or laserpointer/graphic raycast to shoot out from Oculus controller when a button os pressed on the controller. I need the laserbeam to interact with UI buttons in Unity.
You can use a normal raycast
I recomend you make this:
Create a script on your hand,and add a component called line renderer
In the script attach the lineRenderer component
make a simple raycast hit
get the position of the hit object
set the first position of the actual hand and the second to the hit object like this:
lineRenderer.SetPosition(0,transform.position);
lineRenderer.SetPosition(1,hitObject.transform.position);
And it draw a line from your hand to the hit object, remember to change the lineRender parameter to make a beautiful line
hope it helps
I created a project that uses unity's event system. It is a laser pointer which you can interact with unity's UI and 3d objects in the scene. If you want to check it out here's the link: https://github.com/balataca/oculus-laser-pointer

Scrolling Scene Background - Unity

My title might have actually been a bit misworded, as to be honest I'm not sure how to word it, but basically I'm making a game on Unity and I have my main scene and I am making a main menu however what I want to do is have a, I guess, camera slowly panning around the main scene as the background of the main menu. Not sure if I worded that right or what wording to actually type into Google to research it so I'm hoping you guys might be able to point me in the right direction.
Cheers guys,
Jason
As stromdotcom mentioned you can attach a script to the camera.
It's hard to tell what you're trying to do but if you want to circle the camera around a point...
Try making an empty game object in the middle of your scene and point the camera at it.
Make the object the parent of the camera (using the object and cameras transform properties).
From here you should be able to set the game object to rotate using a script, which should make the camera spin as it is a child of the object.
I have not tried this in Unity but I have used this technique in other programs so I'm assuming it will work. Sorry if it doesn't.
If your scene is already set up then you can attach a script to your camera which simply modifies the camera's transform to move it around the room. You can move and rotate the camera just like any other transform in your scene.
Im pretty sure what you are looking for is "Animation view". Unity has a tutorial on it: https://unity3d.com/learn/tutorials/topics/animation/animation-view?playlist=17099

understand more about andengine

guys i am new to andengine so i am sorry if what i am asking is straight forward.
so my question is i want to make a chicken lay a egg when i press a button.
an egg sprite should fall out of my main character when i press a button.
it would be really help full if you guys give the idea how do it it or show me thank you.
i tried making button with a sprite and connecting it to the hud so it works fine but i dont know how to impliment its fucntion to when ever i press it a sprite should fall from my character help.
First take a look at this: AndEngine Tutorials
Be sure you have the latest AndEngine, I'll advise you to use AnchorCenter branch, where by default all your sprites will have thier anchor center in the middle of "their body". After that just create 2 sprites, the Chicken (C) and the Egg (E) both with the same position but with different zIndex where the C will have a higher one, so that the E will be behind hidden. Then override the C sprite onClick method (the C could be a ButtonSprite instead of a simple Sprite). To move the E you could use an EntityYModifier with the desired offset.
This is the main idea ;)

How to recognize when an object is touched in Cocos2d?

I am making a game in Cocos2d. It has a 'shoot' button. How can I make it so that it:
1. Recognizes that the button sprite was touched
2. Perform a method that will actually load the bullet graphic onto the layer and
3. Have it moved at a steady pace across the screen (like a real bullet)
Any help is appreciated. Thanks!
Great questions, all three, and all are covered in the various Cocos2d getting started books (Yes, books!) and guides! To answer your questions specifically would require that you answer a number of questions about how you've set up Cocos2d in the first place; what kind of map you are using, whether and which physics engine, etc....
If you haven't answered those questions yet, best to start by researching Cocos2d.
Start here.
I haven't read the book(s) available, but Ray Wenderlich's Cocos2d tutorials were incredible helpful and demonstrative.
If you're subclassing CCLayer, set the isTouchEnabled property to YES. You then receive callbacks like -ccTouchesBegan:withEvent:, -ccTouchesMoved:withEvent:, etc. Your button handling code would go in those methods. See the documentation on CCLayer and related classes for more information.
Set the isTouchesEnabled to TRUE in init. And just get rectangular co-ordinates around your button sprite and then in touchesBegan just check whether the touched location is inside the rectangular button area, if it is inside it just call your respective function.

XCode: Capturing swipe gesture and creating a moving object

Newbie in XCode & IPhone development.
I'm trying to create a game, where throwing an object (using a swipe gesture) will move the object to the direction requested and will continue with momentum until the border of the view.
Anyone has some code snippets (or links) I can look into for examples?
Thanks.
Take a look at cocos2D-iphone for animation and physics.