void BubbleEmitter::SetBackground( Image bgImage, const Vector3& hsvDelta ) { mBackgroundImage = bgImage; mHSVDelta = hsvDelta; ImageActor sourceActor = ImageActor::New( bgImage ); sourceActor.SetSize( mMovementArea ); sourceActor.SetParentOrigin(ParentOrigin::CENTER); Stage::GetCurrent().Add( sourceActor ); ShaderEffect colorAdjuster = CreateColorAdjuster( hsvDelta, true /*ignore alpha to make bubble color always*/ ); sourceActor.SetShaderEffect( colorAdjuster ); RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList(); RenderTask task = taskList.CreateTask(); task.SetRefreshRate( RenderTask::REFRESH_ONCE ); task.SetSourceActor( sourceActor ); task.SetExclusive(true); task.SetCameraActor(mCameraActor); task.GetCameraActor().SetInvertYAxis(true); task.SetTargetFrameBuffer( mEffectImage ); task.FinishedSignal().Connect(this, &BubbleEmitter::OnRenderFinished); mRenderTaskRunning = true; }
// The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { //std::cout << "HelloWorldController::Create" << std::endl; // Get a handle to the stage Stage stage = Stage::GetCurrent(); //ImageActor bgActor = ImageActor::New(CreateBitmapImage(480, 800)); Control bgActor = Control::New(); bgActor.SetSize(64 * STAGE_COL, 64 * STAGE_ROW); //bgActor.SetBackgroundColor(Vector4(.125f, .125f, .125f, 1.f)); bgActor.SetBackgroundColor(Vector4(1.f, 1.f, 1.f, 1.f)); bgActor.SetParentOrigin(ParentOrigin::CENTER); bgActor.SetAnchorPoint(AnchorPoint::CENTER); bgActor.SetZ(0.1f); //stage.Add(bgActor); ResourceImage spriteImage = ResourceImage::New(PUYO_IMAGE); // background { ResourceImage image = ResourceImage::New(BACKGROUND_IMAGE); ImageActor actor = ImageActor::New(image); actor.SetParentOrigin(ParentOrigin::BOTTOM_LEFT); actor.SetAnchorPoint(AnchorPoint::BOTTOM_LEFT); stage.Add(actor); } // sprites { ImageActor actor[STAGE_COL * STAGE_ROW]; for (int i = 0; i < STAGE_ROW; i++) { for (int j = 0; j < STAGE_COL; j++) { actor[i * STAGE_COL + j] = ImageActor::New(spriteImage, PUYO_OFFSET[int(Random::Range(0.f, NUM_PUYO))]); actor[i * STAGE_COL + j].SetParentOrigin(ParentOrigin::BOTTOM_LEFT); actor[i * STAGE_COL + j].SetAnchorPoint(AnchorPoint::BOTTOM_LEFT); actor[i * STAGE_COL + j].SetX(i * 60.f); actor[i * STAGE_COL + j].SetY(j * -1.f * 60.f); actor[i * STAGE_COL + j].SetZ(0.1f); stage.Add(actor[i * STAGE_COL + j]); } } #if 0 Animation anim = Animation::New(1.f); for (int i = 0; i < STAGE_ROW; i++) { for (int j = 0; j < STAGE_COL; j++) { anim.MoveBy(actor[i * STAGE_COL + j], Vector3(0.f, j * _(7), 0.1f), AlphaFunctions::Bounce); anim.Resize(actor[i * STAGE_COL + j], _(32), _(25), AlphaFunctions::Bounce); anim.SetLooping(true); } } anim.Play(); #endif } { ImageActor actor = ImageActor::New(spriteImage, ImageActor::PixelArea(0, 224, 64, 64)); actor.SetParentOrigin(ParentOrigin::CENTER); actor.SetAnchorPoint(AnchorPoint::CENTER); actor.SetSize(_(32), _(32)); actor.SetZ(0.1f); //stage.Add(actor); } // Respond to a click anywhere on the stage stage.GetRootLayer().TouchedSignal().Connect( this, &HelloWorldController::OnTouch ); }
ImageActor CreateSolidColorActor( const Vector4& color, bool border, const Vector4& borderColor, const unsigned int borderSize ) { ImageActor image; if( borderSize > MAX_BORDER_SIZE ) { return image; } const unsigned int bitmapWidth = borderSize * 2 + 2; bool needAlphaChannel = (color.a < 1.0f) || ( border && borderColor.a < 1.0f ); BufferImage imageData; if( needAlphaChannel ) { imageData = BufferImage::New( bitmapWidth, bitmapWidth, Pixel::RGBA8888 ); } else { imageData = BufferImage::New( bitmapWidth, bitmapWidth, Pixel::RGB888 ); } // Create the image PixelBuffer* pixbuf = imageData.GetBuffer(); if( !pixbuf ) { return image; } Vector4 outerColor = color; if ( border ) { outerColor = borderColor; } // Using a (2 + border) x (2 + border) image gives a better blend with the GL implementation // than a (1 + border) x (1 + border) image const unsigned int bitmapSize = bitmapWidth * bitmapWidth; const unsigned int topLeft = bitmapWidth * borderSize + borderSize; const unsigned int topRight = topLeft + 1; const unsigned int bottomLeft = bitmapWidth * (borderSize + 1) + borderSize; const unsigned int bottomRight = bottomLeft + 1; if( needAlphaChannel ) { for( size_t i = 0; i < bitmapSize; ++i ) { if( i == topLeft || i == topRight || i == bottomLeft || i == bottomRight ) { pixbuf[i*4+0] = 0xFF * color.r; pixbuf[i*4+1] = 0xFF * color.g; pixbuf[i*4+2] = 0xFF * color.b; pixbuf[i*4+3] = 0xFF * color.a; } else { pixbuf[i*4+0] = 0xFF * outerColor.r; pixbuf[i*4+1] = 0xFF * outerColor.g; pixbuf[i*4+2] = 0xFF * outerColor.b; pixbuf[i*4+3] = 0xFF * outerColor.a; } } } else { for( size_t i = 0; i < bitmapSize; ++i ) { if( i == topLeft || i == topRight || i == bottomLeft || i == bottomRight ) { pixbuf[i*3+0] = 0xFF * color.r; pixbuf[i*3+1] = 0xFF * color.g; pixbuf[i*3+2] = 0xFF * color.b; } else { pixbuf[i*3+0] = 0xFF * outerColor.r; pixbuf[i*3+1] = 0xFF * outerColor.g; pixbuf[i*3+2] = 0xFF * outerColor.b; } } } imageData.Update(); image = ImageActor::New( imageData ); image.SetParentOrigin( ParentOrigin::CENTER ); if( border ) { image.SetStyle( ImageActor::STYLE_NINE_PATCH ); image.SetNinePatchBorder( Vector4::ONE * (float)borderSize * 2.0f ); } return image; }