简体   繁体   English

Flash AS3从顶部减小载物台高度

[英]Flash AS3 Reduce stage height from top

I'm trying to reduce stage height from the top to get an item to spawn under a specific area. 我正在尝试从顶部减小舞台高度,以使某个项目在特定区域下生成。 Where the HUD is. HUD所在的位置。

I used to have my HUD on the bottom which caused no problem. 我曾经将HUD放在底部,这没有造成任何问题。 Because my function has: 因为我的功能有:

headY = Math.ceil((((stage.stageHeight - hudHeight)))/(headWidth))*Math.random())*headWidth;

This reduces stage.stageHeight with 80 so the head can spawn properly. 这样可以将stage.stageHeight降低80,因此可以正确生成头部。 However, this isn't the case when the HUD is at the top. 但是,当HUD位于顶部时,情况并非如此。 What this line currently does is that it is making the head not able to spawn under stageheight - 80 pixels instead of the top. 这行代码当前所做的是使头部无法在stageheight(80像素而不是顶部)下生成。

My question is; 我的问题是; how can I make the code reduce the stageheight from the top. 我怎样才能使代码从顶部减少stageheight。

Thanks in advance, 提前致谢,

Jordi 乔迪

Extra info about my question: All I'm trying to do actually, is 'selecting' the bottom of the stage, leaving the stage out of the picture. 有关我的问题的更多信息:我实际上想做的只是“选择”舞台的底部,而使舞台不在画面之列。 I was just using stageheight as an indicator to control the 800 pixels. 我只是使用stageheight作为控制800像素的指示器。 So when I manipulate the stageheight, I wouldn't have to change the code. 因此,当我操作stageheight时,无需更改代码。 But since this might not be possible. 但是由于这不可能。 There should be a different way. 应该有不同的方式。 I hope you understand my question now. 希望你现在理解我的问题。 If not, what I want to do is select everything from 80 pixels down and under. 如果没有,我想做的就是从80像素上下选择所有内容。 The stage's height is 800 pixels so I need to select 720 pixels. 舞台的高度为800像素,因此我需要选择720像素。 However, I can't find a way to select the bottom 720 pixels.. only the top 720 pixels. 但是,我找不到选择底部720像素的方法。仅选择顶部720像素。

Although your question is hard to understand, the answer is most likely that you cant . 尽管您的问题很难理解,但是答案很可能是您无法理解的。 The stageHeight is read-only. stageHeight是只读的。 You can set it in HTML, and even set it to a percentage. 您可以使用HTML进行设置,甚至可以将其设置为百分比。 But you can't alter it in Actionscript. 但是您不能在Actionscript中更改它。

The way your question is worded, makes it extremely hard to understand what you want. 您的问题的措辞方式使您很难理解自己想要的内容。

I am guessing that what you want is to spawn a given object and ensure that it is not spawned in the same space as your HUD. 我猜想您想要的是生成给定的对象并确保它不会与HUD出现在相同的空间中。

So if your screen is 800 x 800 , and your HUD takes up the full width of the screen and the top 80 pixels of the screen you might try this to get a valid y spawn location : 因此,如果您的屏幕为800 x 800,并且HUD占据了屏幕的整个宽度以及屏幕的前80个像素,则可以尝试这样做以获取有效的y生成位置:

var headY:Number = Math.random() * (800 - 80) + 80;

That would give you a resulting value from 80 - 800; 这将为您带来80到800之间的价值;

Given your variables I would suggest this : 给定您的变量,我建议这样做:

var headY:Number = Math.random() * (stage.stageHeight - hudHeight) + hudHeight; 

Now based on your code, it seems like you are also trying to ensure that whatever you are spawning is not partially off the top or bottom of the screen, so you need to factor in the height of the head. 现在基于您的代码,似乎您也在尝试确保生成的内容不会部分偏离屏幕的顶部或底部,因此您需要考虑头部的高度。 So consider this code : 因此,请考虑以下代码:

var headY:Number = Math.random() * ((stage.stageHeight - headHeight) - (hudHeight + headHeight)) + (hudHeight + headHeight);

Not completely sure if this is what you are looking for, but it's the best I can do based on your question and trying to suppose what it is that you want. 不能完全确定这是否是您要寻找的东西,但这是我根据您的问题并尝试假设您想要的东西时能做的最好的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM