background preloader

Interacting

Facebook Twitter

How To Drag and Drop Sprites with Cocos2D. This post is also available in: Chinese (Simplified), Japanese Drag and drop these cute pets with Cocos2D! I’ve received several requests to write a Cocos2D tutorial on how to drag and drop sprites in Cocos2D by touch gestures. You asked for it, you got it! In this Cocos2D tutorial, you’re going to learn: The basics of dragging and dropping sprites with touchesHow to scroll the view itself via touchesHow to keep coordinates straight in your headHow to use gesture recognizers with Cocos2D for even more cool effects! To make things fun, you’ll be moving some cute animals around the scene drawn by my lovely wife, on a background made by gwebstock.

This Cocos2D tutorial assumes you have at least basic knowledge of Cocos2D and have the Cocos2D templates already installed. So without further ado, drag your fingers over to the keyboard and let’s get started! Getting Started Before you implement the touch handling, first you’ll create a basic Cocos2D scene displaying the sprites and artwork. Pinch zoom pan scale AGAIN. Tips:touchdelegates – cocos2d for iPhone. Touch Detection in Cocos2d iPhone @ Irrational Exuberance. Ivan Moen left a comment asking for an explanation about detecting which sprites have been touched in Cocos2d for the iPhone, and it was something I was intended to write about (eventually), so it seemed like a ripe time to address it.

Before we start, I'd like to mention that Luke Hatcher created much of the code that these snippets are inspired by. Broadly, there are three different approaches to adding touch detection to pixels in Cocos2d iPhone. Which one you should choose depends on the needs of your application. While considering this topic, it's important to keep in mind that you're not just detecting touches, you're integrating a user interface management system to your application. The three approaches are: Well, there you have it, three approaches to handling touch detection for Cocos2d iPhone, presented in a confusing and at most halfway organized article. Let me know if you have any questions, but I hope this is enough to get you moving in the right direction. How do you do your scroling? move the content or the camera?