프로그래밍/android2011. 7. 27. 16:25





public class Scene1 extends CCLayer
{
	ArrayList<sprite> items = new ArrayList<sprite>();
	
	public static void show()
	{
		CCScene scene = CCScene.node();
		CCLayer layer = new Scene1();
		scene.addChild(layer);
		CCDirector.sharedDirector().pushScene(scene);
	}
	
	private Scene1()
	{
		CCSprite img = CCSprite.sprite("new_normal.png");
		img.setPosition(100, 200);
		addChild(img);
		items.add(img);
		
		CCSprite img2 = CCSprite.sprite("new_press.png");
		img2.setPosition(200, 150);
		addChild(img2);
		items.add(img2);
		
		CCSprite img3 = CCSprite.sprite("about_press.png");
		img3.setPosition(150, 250);
		addChild(img3);
		items.add(img3);
	}
	
	@Override
	public boolean ccTouchesBegan(MotionEvent event)
	{
		CCIntervalAction fade1 = CCFadeIn.action(0.5f);
		CCIntervalAction fade2 = CCfade1.reverse();
		CCIntervalAction fade = CCSequence.actions(fade2, fade1);
		
		CCSprite item = getItem(event.getX(), event.getY());
		if (item != null)
			item.runAction(fade);
		
		return CCTouchDispatcher.kEventIgnored;
	}
	
	public CCSprite getItem(float x, float y)
	{
		CCSprite result = null;
		
		for (CCSprite item : items)
		{
			CGPoint point = CCDirector.sharedDirector().convertToGL(
					CGPoint.make(x, y));
			
			if (item.getBoundingBox().contains(point.x, point.y))
				result = item;
		}
		return result;
	}
}

Posted by 쎄미

댓글을 달아 주세요