static int tolua_SneakyJoystickSkinnedBase_SneakyJoystickSkinnedBase_getThumbSprite00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isusertype(tolua_S,1,"SneakyJoystickSkinnedBase",0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  SneakyJoystickSkinnedBase* self = (SneakyJoystickSkinnedBase*)  tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
  if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getThumbSprite'", NULL);
#endif
  {
   CCSprite* tolua_ret = (CCSprite*)  self->getThumbSprite();
    tolua_pushusertype(tolua_S,(void*)tolua_ret,"CCSprite");
  }
 }
 return 1;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'getThumbSprite'.",&tolua_err);
 return 0;
#endif
}
Beispiel #2
0
void InputLayer::addJoyStick() {
	float stickRadius = 50;

	joystick = new SneakyJoystick();
	joystick->initWithRect(CCRectMake(0, 0, 100.0f, 100.0f));
	joystick->setAutoCenter(true);
	joystick->setHasDeadzone(true);
	joystick->setDeadRadius(10);

	SneakyJoystickSkinnedBase *skinjoystick = SneakyJoystickSkinnedBase::create();
	skinjoystick->setPosition(stickRadius * 1.5f, stickRadius * 1.5f);
	skinjoystick->setBackgroundSprite(Sprite::create("button-disabled.png"));
	skinjoystick->getBackgroundSprite()->setColor(ccMAGENTA);
	skinjoystick->setThumbSprite(Sprite::create("button-disabled.png"));
	skinjoystick->getThumbSprite()->setScale(0.5f);
	skinjoystick->setJoystick(joystick);

	this->addChild(skinjoystick);
}
// on "init" you need to initialize your instance
bool CCGVirtualJoystick::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Layer::init())
	{
		return false;
	}

	// set joystick params.
	float defaultThumbRadius = 64;
	float defaultBackgroundRadius = 100;
	float defaultDeathRadius = 10;
	Vec2  defaultJoystickPosition = Vec2(200, 200);

	_leftJoystick = static_cast<CCGJoystick*>(new SneakyJoystick());
	_leftJoystick->initWithRect(Rect::ZERO);
	_leftJoystick->setAutoCenter(true);  
	_leftJoystick->setHasDeadzone(true);
	_leftJoystick->setDeadRadius(defaultDeathRadius);

	SneakyJoystickSkinnedBase *leftJoystickSkin = new SneakyJoystickSkinnedBase();
	leftJoystickSkin->autorelease();
	leftJoystickSkin->init();

	// set background sprite
	leftJoystickSkin->setBackgroundSprite(CCSprite::create("joystick/RadialJoy_Area.png"));
	auto backgroundSpriteSize = leftJoystickSkin->getBackgroundSprite()->getContentSize();
	leftJoystickSkin->getBackgroundSprite()->setScaleX(2* defaultBackgroundRadius / backgroundSpriteSize.width);
	leftJoystickSkin->getBackgroundSprite()->setScaleY(2* defaultBackgroundRadius / backgroundSpriteSize.height);

	// set thumb sprite
	leftJoystickSkin->setThumbSprite(CCSprite::create("joystick/Button_normal.png"));
	auto thumbSpriteSize = leftJoystickSkin->getThumbSprite()->getContentSize();
	leftJoystickSkin->getThumbSprite()->setScaleX(2 * defaultThumbRadius / thumbSpriteSize.width);
	leftJoystickSkin->getThumbSprite()->setScaleY(2 * defaultThumbRadius / thumbSpriteSize.height);

	leftJoystickSkin->setPosition(defaultJoystickPosition);
	leftJoystickSkin->setJoystick(_leftJoystick.get());
	this->addChild(leftJoystickSkin);

	// create attack button
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2  defaultAttackButtonPosition = Vec2(visibleSize.width - 200, 200);

	_attackButton = static_cast<CCGButton*>(new SneakyButton());
	_attackButton->initWithRect(Rect::ZERO);
	_attackButton->setIsToggleable(false);
	_attackButton->setIsHoldable(false);

	SneakyButtonSkinnedBase *attackButtonSkin = new SneakyButtonSkinnedBase();
	attackButtonSkin->autorelease();
	attackButtonSkin->init();

	attackButtonSkin->setDefaultSprite(CCSprite::create("joystick/attackButton_normal.png"));
	attackButtonSkin->setPressSprite(CCSprite::create("joystick/attackButton_pressed.png"));
	attackButtonSkin->setActivatedSprite(CCSprite::create("joystick/attackButton_pressed.png"));

	attackButtonSkin->setPosition(defaultAttackButtonPosition);
	attackButtonSkin->setButton(_attackButton.get());
	this->addChild(attackButtonSkin);

	return true;
}
Beispiel #4
0
HelloWorld::HelloWorld()
{
    hello = this;
    // Define the gravity vector.
    b2Vec2 gravity;
    gravity.Set(0.0f, 0.0f);
    // Do we want to let bodies sleep?
    bool doSleep = true;
    
    // Construct a world object, which will hold and simulate the rigid bodies.
    world = new b2World(gravity);
    world->SetAllowSleeping(doSleep);
    world->SetContinuousPhysics(true);
    
    joyStick = new SneakyJoystick();
    joyStick->autorelease();
    joyStick->initWithRect(CCRectZero);
    joyStick->setAutoCenter(true);
    joyStick->setHasDeadzone(true);
    joyStick->setDeadRadius(10);
    
    SneakyJoystickSkinnedBase *joystickSkin = new SneakyJoystickSkinnedBase();
    joystickSkin->autorelease();
    joystickSkin->init();
    joystickSkin->setBackgroundSprite(CCSprite::create("button-default.png"));
    joystickSkin->setThumbSprite(CCSprite::create("button-disabled.png"));
    joystickSkin->getThumbSprite()->setScale(0.5f);
    joystickSkin->setPosition(ccp(50, 50));
    joystickSkin->setJoystick(joyStick);
    


    // load shapes
    GB2ShapeCache::sharedGB2ShapeCache()->addShapesWithFile("physicalTest.plist");
    
    setTouchEnabled(true);
    setAccelerometerEnabled( true );
    
    CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
    

    
//    m_debugDraw = new GLESDebugDraw( PTM_RATIO );
//    world->SetDebugDraw(m_debugDraw);
//    
//    uint32 flags = 0;
//    flags += b2Draw::e_shapeBit;
//    flags += b2Draw::e_jointBit;
//    //        flags += b2Draw::e_aabbBit;
//    //        flags += b2Draw::e_pairBit;
//    //        flags += b2Draw::e_centerOfMassBit;
//    m_debugDraw->SetFlags(flags);
//    
    b2BodyDef groundBodyDef;
    groundBodyDef.position.Set(screenSize.width/2/PTM_RATIO, screenSize.height/2/PTM_RATIO);
    
    // Call the body factory which allocates memory for the ground body
	// from a pool and creates the ground box shape (also from a pool).
	// The body is also added to the world.
    b2Body *groundBody = world->CreateBody(&groundBodyDef);
    
    // Define the ground box shape.
    b2PolygonShape groundBox;
    
    /*
    // bottom
    groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, -screenSize.height/2/PTM_RATIO), 0);
 	groundBody->CreateFixture(&groundBox, 0);
	
    // top
    groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, screenSize.height/2/PTM_RATIO), 0);
    groundBody->CreateFixture(&groundBox, 0);
    
    // left
    groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(-screenSize.width/2/PTM_RATIO, 0), 0);
    groundBody->CreateFixture(&groundBox, 0);
    
    // right
    groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(screenSize.width/2/PTM_RATIO, 0), 0);
    groundBody->CreateFixture(&groundBox, 0);
    
*/
    //initBG
    initBG();
    
    PhysicsSprite *sprite = PhysicsSprite::create("missile", CCPointMake(screenSize.width/2/32, screenSize.height/2/32), world);
    sprite->setCollisionGroup(-10);
    
    sprite->setTag(1);
    playerBody = sprite->getBody();
    bgLayer->addChild(sprite);
    
    Weapon *gun = Weapon::create("SlienceBullet.png");
    sprite->addChild(gun);
    

    
    
    
    PhysicsSprite *sprite_2 = PhysicsSprite::create("missile", CCPointMake(screenSize.width/2/32, screenSize.height/2/32), world);
    sprite_2->setTag(2);
    bgLayer->addChild(sprite_2);
    

    //addNewSpriteWithCoords( CCPointMake(screenSize.width/2, screenSize.height/2) );
	//playerBody = addNewSpriteWithCoords( CCPointMake(screenSize.width/2, screenSize.height/2),"missile" ,1);
    //addNewSpriteWithCoords( CCPointMake(screenSize.width/2 + 100, screenSize.height/2),"missile",2 );

    CCFollow *follow = new CCFollow();
    follow->initWithTarget((CCSprite*)playerBody->GetUserData(),CCRectMake(0, 0, screenSize.width * 2, screenSize.height * 2));
    bgLayer->runAction(follow);
    bgLayer->setTag(100);
    follow->release();
   

    schedule(schedule_selector(HelloWorld::tick));
    scheduleUpdate();
    
    CCLayer *UI = CCLayer::create();
    this->addChild(UI);
    
    UI->addChild(joystickSkin);
    joystickSkin->setPosition(ccp(100, 100));
    
    speed = 0;
    
    
    // MyContactListener *_contactListener;
    _contactListener = new MyContactListener();
    world->SetContactListener(_contactListener);
}