Detect pixels in an object that are off-screen in Flash - actionscript-3

Is there a way (using Starling, Stage3d, or any other Flash framework) to determine if certain pixels are actually being rendered (vs. off screen due to browser scrolling or covered by another window)?
I know there are events to let an app know if the entire player has been throttled due to it getting moved off screen, but if even one pixel in the app is visible the entire player is un-throttled.
Is there any property or performance metric that can tell my app it's ok to stop wasting cycles on an object that isn't being drawn to the screen when another part of the stage is?
(Sorry this is so vague.)

Related

FlashDevelop debugger window showing incorrect resolution

I have an AIR Projector game that's set to 640x640 resolution in the Project -> Properties -> Dimensions field. But for some reason when I debug the game the window sizes itself to 800x800.
Here's the properties window.
And here's what happens when I launch the game.
You can see the image is 800x800. It should be 640x640, I don't know why it's being scaled up by 25%. This stretches the image and makes the quality worse.
I already found a hack-y solution but I was hoping there was a more elegant reason or solution as to why this is happening.
I have to go into the AIR Application Properties and set the Initial Window Size field to 526x549, as shown here.
When I set those fields to those values (keeping in mind the Project Properties Dimensions field is still set to 640x640), the game then launches in the correct dimension with perfect image quality.
I found this other user having the exact same problem. Their solution was to scale the main Sprite to fit the stage dimensions, but I'm trying to avoid scaling to preserve the image quality.
I'm coming back to this because the realization just hit me while going through my computer settings. The reason the game was being rendered 25% larger is because my 1440p monitor is set to 125% scale in my Windows 10 display settings.

'Runner' Game, loop sliding background, remove children when outside

I've just started using actionscript 3 and I am currently trying to make a scrolling runner game in Flash CS5, similar to the Flood Runner games from Tremor games. The difference is, however, that my game is not an endless runner game and the character has a destination that she must reach before time runs out. Alot of the tutorials I've read on the subject use the player character's x and y positions to scroll, but in my game the background scrolls independent of the character. The tutorials I've read about this do not address my problems specifically.
TL;DR: I do not want to loop my background but have a series of multiple background images.
I am trying to figure out the best way to patch together multiple background images seamlessly. Currently, I have one background movie clip object at the maximum pixel width. The background object scrolls to the left independently of the position of the player character, who can only jump.
What I am thinking about doing is this:
Every time a point at the far right edge of one background image reaches the far right stage boundary, I have my actionscript call an addChild command for the next background object and instantiate it at the far right stage boundary. It will scroll at the same speed as the preceding background object.
I also need to figure out how to remove the background objects once they have completely exited the stage for memory purposes.
So, what would be the best way to tackle this?
Your basic concept will work, and to remove you just need to evaluate when the background image is off the screen :
if (backgroundImage.x < -backgroundImage.width)
{
// image is no longer on the screen.
removeChild(backgroundImage);
}

Way to detect if WebGL viewport is on screen?

Is there any way to be able to query the GPU to tell me if my viewport in my webpage is currently on screen or not? For example, if I had a 3d scene rendering in a canvas in an iframe, is there a way to query the hardware (within my iframe and only the pixels or verts in the viewport) to say if I am on screen or scrolled off screen?
I'm curious as to whether this is something I can do at the vertex shader level. Does WebGL even perform the shader program on a viewport that is offscreen? Lets say if it is scrolled below the canvas, or the viewport is obstructed by another webpage browser window? Is there a way to query the compositing portion of webgl to see if it is even in view or Iterate through the "RenderObject" Tree to test if it is even onscreen and then return this value? I am trying to get much more performance out of a project I am working on and I am trying to only render what is visible on screen.
Any possible ideas? Is this even possible? Thanks!
RequestAnimationFrame is only reasonable way to handle unnecessary performance loss even semantically because window.requestAnimationFrame tells the browser that you wish to perform an animation... So browser will figure out how it should handle your wish in optimal way taking into account current page state.
But since iframes communicate using local storage you can push to them your base page state so each of them will decide should it RequestAnimationFrame or not. But im not shure that it is a good thing to have multiply render contexts on your page, they all eat resources and can't share them (data that stored in GPU is sandboxed) so eventually they will start to push each other from GPU memory and cause lags + GPU pipeline might be not so happy with all those tiny standalone entities. Fragmentation is main GPU performance enemy.
You don't ask this question at the canvas/WebGL level, because it might, for example, be scrolled back on screen before you draw another frame, and browsers don't want to not have content to show, so there's no provision to not draw.
I believe you will have to consult the DOM geometry properties (e.g. .scrollLeft) of your scrollable areas to determine whether the canvas is visible. There is enough information in said properties that you can do this generically without hardcoding knowledge of your page structure.
Also, make sure you are exclusively using requestAnimationFrame for your drawing/simulation scheduling; it will pause animations if the page is hidden/minimized/in another tab/otherwise explicitly invisible.

How to handle HTML5 Canvas consuming pinch-to-zoom on tablet?

I have been doing a fair bit of research and reading into the following scenario:
Scenario:
User touches the screen in such a way as to pinch-to-zoom in on the canvas element.
Canvas element now takes up 100% of the width and height of the viewport after zooming.
User is now unable to unzoom or remove themselves from this state without hitting the back button. Pinch-to-zoom is consumed by the canvas.
The design specifications for our web application necessitate the ability to pinch-to-zoom on the page housing the canvas. As such, the suggested best practice of disabling user-scalability on the tablet is not applicable to my scenario.
Is it conceptually possible to bubble the multi-touch "pinch-to-zoom" event up from the canvas element to the browser/tablet?
Are there other, less-obvious solutions I should consider other than:
Invisible div overlay on the canvas. Disable all user-interactivity, but support pinch-to-zoom.
Somehow provide a way of unzooming that doesn't involve a gesture so that the user can escape from the scenario outlined above.

How do video games get on my screen?

When i play a video game (any old game like a racing game or pack man or whatever) how does everything get displayed on the screen in terms of what is going on in the program? is there some big RenderEverything method that is executed once a frame? this strikes me as a bit of a slow way to go about such a thing though.
EDIT: as a follow up question:
How does the computer doing the rendering define the frame both for rendering graphis and for doing in game activites like having a character walk across a room slowly. Like is there some clock t that keeps increasing and every render and every movment hapens as a function of t? If so how is t defined relative to the system that it runs on?
I intend this question to be somewhat synonomous to: When my cursor in the screen right now blinks twice every second how does it know what a second is? Also in java how would i make a program that displays a line of text then waits a second and desplays another line? (perahps this is getting too spacific)
They have a loop. Inside this loop it's called a method for rendering graphics and another for processing logic (and getting input). So this method will calculate everything based on the input and the graphics method print on screen based on the data already computed -- like what should be printed and its position.
Is that what you asked?
Questions about game development should be made here: https://gamedev.stackexchange.com/ :)
When i play a video game (any old game like a racing game or pack man or whatever) how does everything get displayed on the screen in terms of what is going on in the program? is there some big RenderEverything method that is executed once a frame?
Depends on the game. 2D games may be able to keep part of scenes rendered in previous frames, especially old games without scrolling screens. 3D game most likely redraws entire screen. Also good game never renders everything - only visible objects. Because rendering everything is slow, while rendering only visible objects is significantly faster.
this strikes me as a bit of a slow way to go about such a thing though.
You are free to try to find different way. Normal game repaints every visible object. Non-hardware-accelerated game may track unmodified screen regions, and repaint only objects that changed, moved, etc. Hardware accelerated game doesn't have to do that - it can redraw everything on screen every frame. As game/frame/scene complexity increases, it is much easier to simply repaint every visible object during every frame instead of tracking things that changed from previous frame.
That's basically it. The 'video game' is effectively a big state machine where all state is updated according to a frame rate. User input combined with game rules and enemy AI affect the state of the game. Once every frame the players view of the game, not the complete view of the game, is rendered.
Download the quake source, it makes for some interesting reading in the comments and also gives excellent insight as to how a game is constructed.