Bitmap cache as image source - easeljs

is it possible to create bitmap cache of shape and use it for beginBitmapFill?
now i have code:
var shape = new createjs.Shape();
shape.graphics.beginStroke('red').moveTo(0, 0).lineTo(150, 0).lineTo(150, 150).lineTo(0, 150).lineTo(0, 0).moveTo(0, 50).lineTo(150, 50).moveTo(0, 100).lineTo(150, 100).moveTo(50, 0).lineTo(50, 150).moveTo(100, 0).lineTo(100, 150);
shape.cache(0, 0, 150, 150);
//shape.graphics.clear();
//shape.graphics.beginBitmapFill(img); //, "repeat", matrix)
shape.graphics.beginBitmapFill(shape.cacheCanvas);
stage.addChild(shape);

i found solution:
var shape = new createjs.Shape();
shape.graphics.beginStroke('red').moveTo(0, 0).lineTo(150, 0).lineTo(150, 150).lineTo(0, 150).lineTo(0, 0).moveTo(0, 50).lineTo(150, 50).moveTo(0, 100).lineTo(150, 100).moveTo(50, 0).lineTo(50, 150).moveTo(100, 0).lineTo(100, 150);
shape.cache(0, 0, 150, 150);
shape.graphics.clear().beginBitmapFill(shape.cacheCanvas).drawRect(0, 0, 300, 300);
shape.cache(0, 0, 300, 300);
stage.addChild(shape);

Related

How to draw label bigger size?

I am working with Unity and I try to output some info, in order to do this I draw label
void OnGUI()
{
GUI.Label(new Rect(10, 10, 300, 100), FpsDecoded.ToString("D3")+" FPS Decoded" + (buffereing?" Bufferring...":""));
}.
As a result I see label with output info, but problem is that size of this label very small...
and whatever I do, nothing work. I tried to apply different Rect sizes , but text size doesn't changes
What am I doing wrong?
Eventually I solved it this way
private GUIStyle guiStyle = new GUIStyle(); //create a new variable
void OnGUI()
{
guiStyle.fontSize = 20;
string text = FpsDecoded.ToString("D3") + " FPS Decoded" + (buffereing ? " Bufferring..." : "");
GUI.Label(new Rect(10, 10, 300, 100), text, guiStyle);
}

invert image black to white in flutter

I have a bitmap image with black and white color I just need to invert the image and display how can I convert and display image. I have inverted bitmap image in java using this code can anyone suggest me how to do this in a flutter.
private Bitmap createInvertedBitmap(Bitmap src) {
ColorMatrix colorMatrix_Inverted =
new ColorMatrix(new float[] {
-1, 0, 0, 0, 255,
0, -1, 0, 0, 255,
0, 0, -1, 0, 255,
0, 0, 0, 1, 0});
ColorFilter ColorFilter_Sepia = new ColorMatrixColorFilter(
colorMatrix_Inverted);
Bitmap bitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColorFilter(ColorFilter_Sepia);
canvas.drawBitmap(src, 0, 0, paint);
return bitmap;
}
Now it is possible to change/invert the color via ColorFiltered class
You can refer to this blog for more details: https://www.burkharts.net/apps/blog/over-the-rainbow-colour-filters/
Another solution
You can try using ShaderMask class, and try passing it to the corresponding Shader, such as InvertColorShader. Currently, no shader can do this as of now.
Also check out BlendMode class to achieve your desired result.

How to use DrawNode with RenderTexture cocos2d-x

I cannot draw a simple line or a dot with DrawNode and RenderTexture.
This is how to I implemented:
AppDelegate.cpp
auto scene = Scene::create();
auto layer = BackgroundLayer::create();
scene->addChild(layer);
// run
director->runWithScene(scene);
BackgroundLayer.cpp
bool BackgroundLayer::init()
{
if ( !LayerColor::initWithColor(Color4B::WHITE) )
{
return false;
}
auto renderTexture = RenderTexture::create(300, 200);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(250, 250), 20, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(this->getContentSize()/2);
this->addChild(renderTexture, 10000);
}
I tried with some complex shape with DrawNode, but the result is just a black rectangle stayed in the center of the screen.
I compile with cocos2d-x v3.6 & VS2013.
auto renderTexture = RenderTexture::create(50, 50);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(10, 10), 2, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(SCREENSIZE.width/2,SCREENSIZE.height/2);
this->addChild(renderTexture, 10000);
Try this it will create red dot on the texture

Tween transition in Kinetic js

I've been using the old 'transitionTo()' in my program but since Kineticjs is using Tween, i am a bit lost.
I've tried a simple shape transition using Tween and i've got some issues:
If you drag the shape to another point before doing anything, then click on the button for the transition, the shape comes back to the original hard coded coordinates and then does the transition.
I want the shape to start the transition where it has been dropped.
2.The 1st time it will do the transition, but afterwards it won't take the whole duration. It will just shift to the end point of the transition, like mentioned here.
Some codes:
var rect = new Kinetic.Rect({
x: 100,
y: 100,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 2,
draggable: true
});
layer.add(rect);
stage.add(layer);
var tween = new Kinetic.Tween({
node: rect,
x: 200,
y: 200,
rotation: 0,
duration:5
});
jsFiddle provided above.
Any help will be appreciated; thanx :)
This is what I would propose to solve your problems :
var stage = new Kinetic.Stage({
container: 'container',
width: 700,
height: 300
});
var layer = new Kinetic.Layer();
var rect = new Kinetic.Rect({
x: 100,
y: 100,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 2,
draggable: true
});
layer.add(rect);
stage.add(layer);
document.getElementById('run').addEventListener('click', function() {
var tween = new Kinetic.Tween({
node: rect,
x: 200,
y: 200,
rotation: 0,
duration:5
});
tween.play();
}, false);
Just instantiate the Tween transition at the moment, you want to use it. Otherwise, the transition will start with the position at the moment you instantiated it.
Here is the fork of your fiddle with my proposal : http://jsfiddle.net/kMvzy/

gamequery collision detection doesnt react

i created 2 sprite objects and want to check if they collide, but it doesnt seem to work.
My code:
creation of the sprites:**
.addGroup("flying", {width: 366, height: 254})
.addSprite("flyinganimation",{animation: flight,
posx: 0, posy: 0, width: 366, height: 254})
.addGroup("obstacles", {width: 169, height: 67})
.addSprite("obstaclenames", {animation: obstacleimage,
width: 169,height: 67,
posx: 300,
posy: 400})
looped code in the callback function:**
var collision = $("#flying,.group").collision("#obstacles,.group");
if (collision > 0)
{
document.write ("collision");
}
I see two potential problems here:
1) collision() returns a jQuery object so you will need to do a .size() in order to retrieve the number of collisions
2) you should apply collision() to only one object.
To sum up your first line should look like this:
var collision = $("#flying").collision("#obstacles,.group").size();