Zooming whole scen in Flash - dictionary

I've made a interactive map in Adobe Flash Profesional CS6 and i was wondering if there is a way to zoom in and out. Yes i know convert map in to a symbol and do Mouseevent. MOUSEWHEEL etc...... But this doesnt make the whole scene zoom in. So is there any way to do that? Thank you for answering guys.
so I've tried this:
stage.addEventListener(MouseEvent.MOUSE_WHEEL, MouseZoom) function MouseZoom(e:MouseEvent):void{
if (e.delta > 0)
{
trace(e.delta);
Lake_mc.width += 20
Lake_mc.height += 20
}
if (e.delta < 0)
{
trace(e.delta);
Lake_mc.width -= 20;
Lake_mc.height -= 20;
}}

Related

Why is my JavaFX PerspectiveCamera Rotating Around a Seemingly Arbitrary Point?

I am working on a first-person game, and right now I am building a game engine using JavaFX. I am using the PerspectiveCamera as my player character. However, when I use the default rotation method in JavaFX to rotate my camera, it ends up rotating around some point, moving it far and wide. What I want is for the camera to simply rotate on the spot, and stay in place.
Here is my code:
camera.setRotationAxis(new Point3D(camera.getLayoutX() + (Toolkit.getDefaultToolkit().getScreenSize().width/2), camera.getTranslateZ(), 0));
if (event.getCode() == KeyCode.RIGHT){
camera.getTransforms().add(new Rotate(5, camera.getTranslateX(), camera.getTranslateY(), camera.getTranslateZ(), Rotate.Y_AXIS));
camrot += 5;
if (camrot > 360) {
camrot -= 360;
}
System.out.println(camrot);;
}else if (event.getCode() == KeyCode.LEFT){
camera.getTransforms().add(new Rotate(-5, camera.getTranslateX(), camera.getTranslateY(), camera.getTranslateZ(), Rotate.Y_AXIS));
camrot -= 5;
if (camrot < 0) {
camrot += 360;
}
System.out.println(camrot);
}
Does anyone know what might be wrong here? Maybe something to do with the rotation axis? Not sure, somebody else told me what to put there.

A-Frame. Zoom on wheel scroll

I've come through the official docs but wasn't able to locate information about how possibility of zooming in/out panorama images, is it supported in the A-Frame or maybe there is a workaround to read about implementing some of three.js on top of it?
This might be a cleaner way in 2018.
I limited the zoom of the Aframe camera 1-5 so it doesn't get too messy.I just tested this and its working greatly.Hope it helps others.
window.addEventListener("mousewheel", event => {
const delta = Math.sign(event.wheelDelta);
//getting the mouse wheel change (120 or -120 and normalizing it to 1 or -1)
var mycam=document.getElementById('cam').getAttribute('camera');
var finalZoom=document.getElementById('cam').getAttribute('camera').zoom+delta;
//limiting the zoom so it doesnt zoom too much in or out
if(finalZoom<1)
finalZoom=1;
if(finalZoom>5)
finalZoom=5;
mycam.zoom=finalZoom;
//setting the camera element
document.getElementById('cam').setAttribute('camera',mycam);
});
You could either:
Scale an <a-sphere> up or down when detecting the mouse wheel event
zoom in or out the camera, like documented here
This article might be helpful, as it covers using the mousewheel event on multiple browsers.
I think scaling may screw up Your setup, or be a resource waste, so I'd go with 2.
Sandy's answer helped me. I want to contribute an answer which shows the full code and enables smoother zooming (increments of 0.1):
<script>
window.addEventListener("wheel", (event) => {
// small increments for smoother zooming
const delta = event.wheelDelta / 120 / 10;
var mycam = document.getElementById("cam").getAttribute("camera");
var finalZoom =
document.getElementById("cam").getAttribute("camera").zoom + delta;
// limiting the zoom
if (finalZoom < 0.5) finalZoom = 0.5;
if (finalZoom > 2) finalZoom = 2;
mycam.zoom = finalZoom;
document.getElementById("cam").setAttribute("camera", mycam);
});
</script>
<a-scene>
<a-entity
id="cam"
camera="zoom: 1"
look-controls="reverseMouseDrag: true"
></a-entity>
<!-- my pano image stuff -->
<a-assets>
<img id="skyTexture" crossorigin="anonymous" />
</a-assets>
<a-sky src="#skyTexture"></a-sky>
</a-scene>
This is what I put together to do it. Check the initial vrZoom variable.
For me, what I struggled the most, was to understand the way you set a parameter that's inside a component. You have to call it like this: element.setAttribute('componentName', 'parameterName', 'value') and in my case cam.setAttribute('camera', 'zoom', vrZoom)
Here's my script all together. It would be possible to create a component with this, such as look-controls.
var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel";
if (document.attachEvent)
document.attachEvent("on"+mousewheelevt, function(e){scroller(e)});
else if (document.addEventListener)
document.addEventListener(mousewheelevt, function(e){scroller(e)},false);
var vrZoom = 4; // My initial zoom after animation
var cam = document.querySelector('#mainCam');
function scroller(evt)
{
//Guess the delta.
var delta = 0;
if (!evt) evt = window.event;
if (evt.wheelDelta) {
delta = evt.wheelDelta/120;
} else if (evt.detail) {
delta = -evt.detail/3;
}
if (evt.preventDefault) evt.preventDefault();
evt.returnValue = false;
//Actual Zooming.
vrZoom += delta * 0.1
vrZoom = Math.min(Math.max(vrZoom, 1), 8); // clamp between 1 and 8
cam.setAttribute('camera', 'zoom', vrZoom)
}
I struggled quite a bit with getting this to work for an embedded a-frame, especially because the scene would become skewed upon dynamically adjusting the camera's zoom setting. This is a bug with a-frame. Here are the two ways I found to reset the scene upon setting the zoom level.
AFRAME.scenes[0].resize();
Or ...
let scene = document.querySelector('a-scene');
scene.camera.aspect = scene.clientWidth / scene.clientHeight;
scene.camera.updateProjectionMatrix();

Detect which Taskbar button was clicked (identify target window)

I am trying to figure out how to detect which Taskbar button was clicked. Specifically, I want to write a script that makes it possible to maximize a window by double-clicking its Taskbar button. That requires knowing which Taskbar button was clicked, which I am having a difficult time finding any leads on.
Does anyone know how this can be accomplished?
That's a though one I have to admit. I can't offer you a best practice solution, but here is a little work around, maybe that enough for your purposes:
CoordMode, Mouse, Screen
~LButton::
If (A_TimeSincePriorHotkey<400) and (A_PriorHotkey="~LButton") {
WinGetPos, taskBarX, taskBarY, taskBarW, taskBarH, ahk_class Shell_TrayWnd
MouseGetPos, mouseX, mouseY
If (mouseX >= taskBarX && mouseY >= taskBarY && mouseX <= taskBarX+taskBarW && mouseY <= taskBarY+taskBarH)
OnDoubleClickTaskbar()
}
Return
OnDoubleClickTaskbar() {
;WinWaitNotActive, ahk_class Shell_TrayWnd
Sleep, 200
WinMaximize, A
}
Tested on Windows 8.1.

Fade In Raster with PaperJS

How to fade in / fade out a Raster (image) with PaperJS ? Currently I'm using the following clumsy function to handle 1 raster (codes are simplified):
var img = new Raster('test.jpg');
img.opacity = 0;
function onFrame() {
if(img.opacity < 1) {
img.opacity += 0.1;
}
}
Is there a faster way to do so?
The ultimate aim is to achieve:
Fade In > Hold 3 seconds > Fade Out
There's this attempt at an animation lib for Paper.js.
As a side note it would be nice if you kept it's creator updated with bugs or any recommendations in this thread

Create a chess board in Flex 4.6

I'm starting a new project in Flash Builder 4.6 and need some advices before going in one direction instead of the right one.
Basically, my application in Flash Builder is for mobile devices and tablets, so I need to know how could I create a chess board that fix exactly the width of any device. I do not know how could i do it exactly in Flex.
Could anyone give an idea or supply an example i could use?
Thanks.
Why not use a TileGroup/TileLayout with 100% height and width? You then set the rowHeight to be {this.height / ROWS} (ROWS being however many rows there are on a Chessboard) and doing the same for columnWidth. You could even use the horizontalGap and verticalGap properties to show through to a black background that could be used as separators between each box (though you would have to account for this in your rowHeight and columnWidth calculations, obviously)
I would populate the screen via AS3, as opposed to Flex. Something like this is what I have in mind.
var columnCount:int = 0;
var rowCount:int = 0;
var boxes:int = 64; //however many boxes on a chess board goes here
for ( var i:Number = 0; i < boxes; i+ ){
var rect:Rect = new Rect();
var color:SolidColor;
rect.percentHeight = 100;
rect.percentWidth = 100;
rect.name = i.toString(); //this will make it easier to keep track of which box is which later on
if ( rowCount % 2 == 1 ) {
if ( i % 2 == 1 ) color = 0x000000;
else color = 0xffffff;
}
else {
if ( i % 2 == 1 ) color = 0xffffff;
else color = 0x000000;
}
this.rect.fill = color;
this.tileGroup.addElement(rect);
if ( columnCount == 7 ) {
columnCount = 0;
rowCount++;
}
else {
columnCount++;
}
}
That is completely off the top of my head and untested, so I am sure there is an error or two, but you get the idea of how it would work.
EDIT: As an afterthought, you could probably do the colors 100% mathematically without using rowCount/columnCount vars, though it is probably much much easier to do so.

Resources