Comments (8)
Hi!
This works a little different than how it does in Flash -- that needs clarification, I have to add more documentation on that one. However, here's a sample.
I've added a resize event listener just as you, but it outputs some more values.
private function onResize(event:ResizeEvent):void
{
trace("--- onResize() ---");
trace("event.width: " + event.width);
trace("stage.width: " + stage.width);
trace("stage.stageWidth: " + stage.stageWidth);
trace("starling.viewPort.width: " + Starling.current.viewPort.width);
}
Now, when I resize the Flash Player, I get output like this:
--- onResize() ---
event.width: 447
stage.width: 336
stage.stageWidth: 320
starling.viewPort.width: 320
--- onResize() ---
event.width: 444
stage.width: 336
stage.stageWidth: 320
starling.viewPort.width: 320
--- onResize() ---
event.width: 442
stage.width: 336
stage.stageWidth: 320
starling.viewPort.width: 320
As you can see, only the "event.width" changes. Here's what the different properties mean in Starling:
event.width: the new width of the Flash Player
stage.width: the width of the content on the stage
stage.stageWidth: the width of the coordinate system of the stage.
starling.viewPort.width: the width of the actually rendered pixels
So, when you catch a ResizeEvent, you get the new size of the player. Now you can choose what happens by modifying the viewPort size or the stage size (all those properties are writeable in Starling).
E.g.:
// viewport gets bigger, stage scales with it -- no matter how ugly
// it looks! ;-)
private function onResize(event:ResizeEvent):void
{
Starling.current.viewPort = new Rectangle(0, 0,
event.width, event.height);
}
// viewport gets bigger, stage stays as it is. User could move
// elements around to make up for bigger screen size.
private function onResize(event:ResizeEvent):void
{
Starling.current.viewPort = new Rectangle(0, 0,
event.width, event.height);
stage.stageWidth = event.width;
stage.stageHeight = event.height;
}
I hope that makes sense!
from starling-framework.
Ok, I understand how it works. All those values are very useful but a bit unintuitive. I think more documentation is a great idea. Thanks for your help on this, so far I think the package is awesome.
from starling-framework.
Thanks for the compliments!
Yeah, you're right: it's not obvious how this works, I'll definitely have to document this better!
The reasoning behind it: you can develop a game for several resolutions without having to deal with different coordinate systems. E.g. when you develop for the iPhone, you need to support 480x320 and 960x640 (non-retina and retina display). With the setup above, you can set the viewport to one of those resolutions -- depending on where your app is running -- but use a stage size of 480x320 for both of them.
from starling-framework.
Oh sure, I get why it's useful. It's just that I've been making apps with liquid displays for years and it took me several hours to figure out, even with the user guide from Thibault. Of course maybe I'm just a little slow sometimes. I think that how similar you've made Starling to the regular Flash display framework is a double edged sword. It's great to carry over concepts that we all understand but when there's a variation it's a lot more confusing than it would've been otherwise. That's ok though, after working through a project or two it'll just be second nature and I'm sure we'll all wish the Flash framework worked the way Starling does. Again, I'm loving working with it. Thanks a lot for your effort on it.
--- On Sun, 11/20/11, Daniel Sperl [email protected] wrote:
From: Daniel Sperl [email protected]
Subject: Re: [Starling-Framework] Resize event width and height don't match stage.stageWidth and stage.height (#51)
To: "mrpenguin" [email protected]
Date: Sunday, November 20, 2011, 4:37 AM
Thanks for the compliments!
Yeah, you're right: it's not obvious how this works, I'll definitely have to document this better!
The reasoning behind it: you can develop a game for several resolutions without having to deal with different coordinate systems. E.g. when you develop for the iPhone, you need to support 480x320 and 960x640 (non-retina and retina display). With the setup above, you can set the viewport to one of those resolutions -- depending on where your app is running -- but use a stage size of 480x320 for both of them.
Reply to this email directly or view it on GitHub:
#51 (comment)
from starling-framework.
Mhm, I totally agree about the double edged sword ...! In those cases where Starling does differ, almost everyone will be a little puzzled at first.
Thanks for the nice words, that means a lot to me! :-)
from starling-framework.
@PrimaryFeather I love you man. You saved my life :D Very nice tutorial (Y)
from starling-framework.
Haha, thanks for the compliments! I'm glad to hear it helped you, as well! 😄
from starling-framework.
Yes because it's different from native Flash api. But now I understand after your tutorial :) thanks
from starling-framework.
Related Issues (20)
- TextFormat leading doesn't affect last line's height HOT 5
- TextField AutoScale clips text if multiline and > 100% display scale HOT 2
- Glow Filter: Color issue HOT 7
- native overlay now block touch and mouse input HOT 1
- How do I use it correctly “drawToBitmapData” HOT 6
- AssetManager strange behavior
- AssetManager problem HOT 9
- Reverse delay for Tween HOT 2
- Stats showing actually rendered frames HOT 8
- ArgumentError in createVertexBuffer HOT 14
- DisplayObject dispose() method doesn't automatically remove the object from its parent HOT 3
- Render Texture: "Error #3605: Sampler 0 binds an invalid texture" when not cleared or drawn before actual Image rendering HOT 3
- Render Texture: draw method doesn't render display object with filter if parent is shifted HOT 8
- Texture: Setting vertex UV coordinates doesn't take into account the potential frame of SubTextures HOT 5
- How do we use Asset Manger with Google Play's Install Time Asset Packs? HOT 4
- Starling Texture.fromCamera() flickering and a part of the picture is missing on Windows HOT 4
- Object not removed from Stage on Android - Starling maybe? HOT 5
- Starling update from 2.5 to 2.7 doesn't catch tap around the left/bottom side HOT 2
- Juggler: String allocation when using IAnimatable as a Dictionary key HOT 4
- OpenGL error at macOS 12.2.1 (M1) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from starling-framework.