void Platform::initPlatform(int width, float angle, CCPoint position) { //Define shape b2PolygonShape box; box.SetAsBox(width * 0.5f /PTM_RATIO, PLATFORM_HEIGHT * 0.5f / PTM_RATIO); //Define fixture b2FixtureDef fixtureDef; fixtureDef.shape = &box; fixtureDef.density = 1; fixtureDef.restitution = 0; //reutilize body from the pool: so destroy any existent fixture if (_body->GetFixtureList()) { _body->DestroyFixture(_body->GetFixtureList()); } _body->CreateFixture(&fixtureDef); _body->SetTransform(b2Vec2(position.x / PTM_RATIO, position.y / PTM_RATIO), CC_DEGREES_TO_RADIANS(-angle)); _body->SetActive(true); CCSprite * block; float startX = -width * 0.5f + TILE * 0.5f; //set unused tiles in the platform invisible for (int i = 0; i < TILES_PER_PLATFORM; i++) { block = (CCSprite *) _tiles->objectAtIndex(i); if (i >= width/TILE) { block->setVisible(false); } else { block->setVisible(true); block->setPosition(ccp(startX + i * TILE, 0)); block->setFlipY(false); block->setFlipX(false); if (angle == 0.0) { if (position.y >= TILE * 13) block->setFlipY(true); } if (angle == 90.0) { if (position.x > TILE * 5) block->setFlipY(true); } } } switchTexture(); this->setRotation(angle); this->setPosition(position); setVisible(true); }
void Platform::onGravityChanged(CCObject * note) { if (this->isVisible()) { switchTexture(); } }
void ImageViewer::setpixmap(const renderBuffer* pixmap) { rbuf = pixmap; switchTexture(); }