How can I rezise an image in Haxeflixel? - haxe

I'm trying to set up a background in my game, and I want it to support multiple resolutions. I've tried using the scale trigger, but I'm pretty sure it multiplies the dimensions by the value. I need to resize the background by the resolution, so that won't work. Here's my code right now:
bgImage = new FlxSprite();
bgImage.loadGraphic(AssetPaths.SP_LevelBG__png, false, FlxG.width, FlxG.height);
bgImage.width = FlxG.width;
bgImage.height = FlxG.height;
add(bgImage);
Thanks in advance.

Use scale: https://snippets.haxeflixel.com/sprites/scale/
bgImage.scale.x = 10;
bgImage.scale.y = 10;

Related

How to display an image saved as "/storage/emulated/0/Download/IMG_1582623402006.jpg" in emulator

I capture a image by camera in emulator and it was saved as:
"/storage/emulated/0/Download/IMG_1582623402006.jpg"
I am trying to display this image in < ImageView > as the following:
Bitmap finalBitmap = BitmapFactory.decodeFile("/storage/emulated/0/Download/IMG_1582623402006.jpg");
holder.image.setImageBitmap(scaledBitmap);
but it shows that "finalBitmap" is empty. What have I missed?
Thanks in advance!
You posted this over a year ago, so it may be too old at this point.
It appears that you are using two variables for your bitmaps: finalBitmap and scaledBitmap and not referencing the proper one in the setImageBitmap command.
Instead, have you tried this?
holder.image.setImageBitmap(finalBitmap);
Not totally sure, but adding some attributes in "options" seems make it work in emulator:
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = true;
options.inSampleSize = 5;
Bitmap scaledBitmap = BitmapFactory.decodeFile(/storage/emulated/0/Download/IMG_1582623402006.jpg, options);
holder.image.setImageBitmap(scaledBitmap);

EaselJS StageGL: text not working (but does using Stage canvas)

I re-programmed a HTML5 game (using createJS) to match StageGL, but it turned out all text fields disappear. Switching back to Stage solved this specific problem (see code example below).
Does anyone know a workaround to this?
Example code:
canvas.width = stageWidth;
canvas.height = stageHeight;
stage = new createjs.StageGL(canvas); // <= text does not work with GL???
stage = new createjs.Stage(canvas); // <= text works fine
var textTest = new createjs.Text("Hello World");
textTest.x = 10;
textTest.y = 20;
stage.addChild(textTest);
Thanks in advance for your comments!
Text will not work without being cached, as the Text/Vector canvas APIs are not supported by StageGL.
Caching is pretty easy:
var bounds = text.getBounds();
text.cache(bounds.x, bounds.y, bounds.width, bounds.height);
When the text changes, you will need to recache the text.
Cheers,

Chrome capture visible tab gives messy result

I have a Chrome extension, where I'm using the captureVisibleTab method of the chrome.tabs API to capture screenshots. I have tested the extension on 3 devices (Chromebooks) and I'm getting mixed results. Two of them work perfectly, but one always returns a completely malformed screenshot.
My code:
chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){
chrome.tabs.get(tabId, function (_tab) {
if (_tab.status == "complete" && _tab.active ) {
chrome.tabs.captureVisibleTab( function(dataUrl){
});
}
});
});
Any ideas what could be the issue on that one device?
EDIT
Example of a bad screenshot:
I suspect that the device pixel ratio is higher on your 3rd device. This was an issue I was having with Retina displays when building a screenshot app. Basically, certain high-resolution displays have a higher ratio pixels per square inch. You're going to want to find window.devicePixelRatio and divide the context scale by that amount.
Assuming that you are using Canvas to draw the screenshot and capture it into an image, this little snippet should help show what you're going to want to do:
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext("2d");
if(window.devicePixelRatio > 1){
context.scale(1/window.devicePixelRatio, 1/window.devicePixelRatio);
}
context.drawImage(image, 0, 0);
Let me know if that works for you.

Fade between colors with THREE.js

I have a simple cube in THREE.js:
var cubeMaterial = new THREE.MeshLambertMaterial({color: 0xCC0000});
var cube = new THREE.Mesh(
new THREE.CubeGeometry(100, 100, 100),
cubeMaterial);
cube.position.set(0.7,1.95,-0.1);
cube.scale.x = cube.scale.y = cube.scale.z = 0.002;
scene.add(cube);
Any suggestions on how I can change the color of the material on the fly? What I want to achieve is a smooth fade (for instance from red to green) and be able to fade the color dynamically. So my guess is that it needs to be continuously re-rendered in the render-loop, and then somehow the color should be changed so it will gradually be faded to the target color. But I'm not really sure how to do that in code..
Thanks in advance!
Anders
You can use TWEEN.js: https://github.com/sole/tween.js/
There is a good solution to your question in this Stackoverflow question: How to tween between two colours using three.js?

o3d textures and transparency

I'm working at galery on o3d(plagin version) and I need make photos transparent. Photos are on hud. Here is some code:
g_canvasInfoPict = o3djs.canvas.create(g_pack, g_hudRoot, g_hudViewInfo);
alphaParam = g_canvasInfoPict.transparentState_.getStateParam("o3d.AlphaReference");
alphaParam.value = 0.5;
alphaParam = g_canvasInfoPict.transparentState_.getStateParam("o3d.BlendAlphaEquation");
alphaParam.value = g_o3d.State.BLEND_SUBTRACT;
alphaParam = g_canvasInfoPict.transparentState_.getStateParam("o3d.SourceBlendFunction");
alphaParam.value = g_o3d.State.BLENDFUNC_ONE;
paramOne = g_canvasInfoPict.transparentState_.getStateParam("o3d.DestinationBlendFunction");
paramOne.value = g_o3d.State.BLENDFUNC_DESTINATION_ALPHA;//or BLENDFUNC_SOURCE_ALPHA or BLENDFUNC_SOURCE_ALPHA_SATUTRATE or BLENDFUNC_ONE or BLENDFUNC_ZERO
g_fullPictCanvas = g_canvasInfoPict.createXYQuad(paddingX, paddingY, -14, g_fullPictTexture.width, g_fullPictTexture.height, true);
g_fullPictCanvas.canvas.drawBitmap(g_fullPictTexture, 0, g_fullPictTexture.height);
g_fullPictCanvas.updateTexture();
But it doesn't work. When setting paramOne.value = BLENDFUNC_ZERO photo displays (non-transparent)
paramOne.value = BLENDFUNC_ONE photo isn't displayed (full transparent)
So how to achive intermediate result?
Given that the O3D plug-in is deprecated in favor of the WebGL-based O3D, is it an option for you to migrate to the latter?
If so, you can inquire in the discussion group about the transparency issue (if it still exists under O3D-WebGL). The developers are very responsive.

Resources