• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Why can't I fit my AIR app to the screen of the device ??

Contributor ,
Nov 13, 2014 Nov 13, 2014

Copy link to clipboard

Copied

Hi all,

I've made some apps on device but it's the first time that I can't make the app fit the screen and I really don't understand why.

I've downloaded an exemple of the game Flappy bird and I would like to play with my device.

Can you help me make the app fit the device screen please ?

Here's my main.as

package{

  import citrus.core.starling.StarlingCitrusEngine;

    import flash.display.Stage;

  import flash.events.*;

    import flash.display.StageAlign;

   import flash.display.StageScaleMode;

  [SWF(frameRate="60")]

  public class Main extends StarlingCitrusEngine {

  public function Main() {

        stage.align = StageAlign.TOP_LEFT;

  stage.scaleMode = StageScaleMode.EXACT_FIT;

  }

  override public function initialize():void {

  setUpStarling();

  }

  //starling is ready, we can load assets

  override public function handleStarlingReady():void

  {

  state = new FlappyBirdGameState();

  }

  }

}

Here's my FlappyBirdGameState.as :

public function FlappyBirdGameState()

  {

  super();

  }

  override public function initialize():void

  {

  super.initialize();

  ce = CitrusEngine.getInstance();

  // load assets, then draw screen

  loadAssets();

  // fly with the spacebar, alternatively

  kb = ce.input.keyboard;

  kb.addKeyAction("fly", Keyboard.SPACE);

  }

  private function loadAssets():void {

  assets = new AssetManager();

  assets.verbose = true;

  assets.enqueue(Assets);

  assets.loadQueue(function(ratio:Number):void

  {

  trace("Loading assets, progress:", ratio);

  if (ratio == 1.0)

  // add game elements

  drawScreen();

  });

  }

  private function drawScreen():void

  {

  var bg:CitrusSprite = new CitrusSprite("bg", {x: 0, y: 0, width: 320, height: 480});

  bg.view = new Image(assets.getTexture("bg.png"));

  add(bg);

  box = new CitrusSprite("box", {x: 40, y: -200, width: 240, height: 200});

  box.view = new Image(assets.getTexture("box.png"));

  add(box);

  textField = new TextField(200, 200, "CLICK TO FLY", "Flappy", 20, Color.NAVY);

  textField.x = 60;

  textField.y = -200;

  addChild(textField);

  // box and textField have synced tweens

  eaze(box).to(0.4, { y: 150 } );

  eaze(textField).to(0.4, { y: 150 } );

  ce.stage.addEventListener(MouseEvent.MOUSE_DOWN, start);

  function start(e:MouseEvent):void

  {

  eaze(box).to(0.2, { y: -200 } );

  eaze(textField).to(0.2, { y: -200 } );

  newGame();

  ce.stage.removeEventListener(MouseEvent.MOUSE_DOWN, start);

  }

  }

  public function newGame():void

  {

  // get a random Y position for first pipe

  randomizePipeY();

  pipe1 = new CitrusSprite("pipe", {x: 380, y: pipeY, width: 60, height: 160});

  pipe1.view = new Image(assets.getTexture("pipe.png"));

  add(pipe1);

  pipeBoundsTop1 = new Rectangle(0, 0, 50, 355);

  pipeBoundsBottom1 = new Rectangle(0, 0, 50, 364);

  // get a random Y position for second pipe

  randomizePipeY();

  pipe2 = new CitrusSprite("pipe2", {x: 620, y: pipeY, width: 60, height: 860});

  pipe2.view = new Image(assets.getTexture("pipe.png"));

  add(pipe2);

  pipeBoundsTop2 = new Rectangle(0, 0, 50, 355);

  pipeBoundsBottom2 = new Rectangle(0, 0, 50, 364);

  // the character

  thing = new CitrusSprite("thing", {x: 100, y: 200, width: 40, height: 50});

  thingImage = new Image(assets.getTexture("thing.png"));

  thing.view = thingImage;

  add(thing);

  thingBounds = new Rectangle(0, 0, 35, 45);

  ce.stage.addEventListener(MouseEvent.MOUSE_DOWN, fly);

  // move box to top

  var container:Sprite = view.getArt(box).parent;

  container.swapChildren(view.getArt(box) as DisplayObject, view.getArt(pipe1) as DisplayObject);

  container.swapChildren(view.getArt(box) as DisplayObject, view.getArt(pipe2) as DisplayObject);

  container.swapChildren(view.getArt(box) as DisplayObject, view.getArt(thing) as DisplayObject);

  // score text field

  scoreText = new TextField(300, 50, "", "Flappy", 20, Color.NAVY);

  scoreText.hAlign = "right";

  scoreText.x = -10;

  scoreText.y = 0;

  addChild(scoreText);

  // a few more things

  clicked = true;

  score = 0;

  velocity = -7;

  }

  // click to fly

  public function fly(e:MouseEvent):void

  {

  velocity = -7;

  assets.playSound("whoosh");

  }

  // get a new Y position for a pipe

  private function randomizePipeY():void

  {

  pipeY = new Number(Math.floor(Math.random() * -330) + -40);

  }

  override public function update(timeDelta:Number):void

  {

  super.update(timeDelta);

  if (clicked)

  {

  if (!gameOver)

  {

  // move pipes

  pipe1.x -= 2;

  pipe2.x -= 2;

  }

  // after pipes go off screen, move them

  if (pipe1.x <= -60)

  {

  //randomize pipe Y

  randomizePipeY();

  pipe1.x = 380;

  pipe1.y = pipeY;

  }

  if (pipe2.x <= -60)

  {

  // randomize pipe Y

  randomizePipeY();

  pipe2.x = 380;

  pipe2.y = pipeY;

  }

  // fly through a pipe, gain a point

  if (pipe1.x == thing.x || pipe2.x == thing.x)

  {

  score++;

  scoreText.text = String(score);

  assets.playSound("ding");

  }

  // spacebar to fly

  if (ce.input.justDid("fly"))

  {

  if (!gameOver)

  {

  velocity = -7;

  assets.playSound("whoosh");

  }

  }

  // character falls with gravity

  velocity += gravity;

  thing.y += velocity;

  // prevent flying through the top and bottom of screen

  if (thing.y <= 0)

  {

  thing.y = 0;

  }

  if (thing.y >= 430)

  {

  thing.y = 430;

  }

  // collision

  thingBounds.y = thing.y + 2.5;

  thingBounds.x = thing.x + 2.5;

  pipeBoundsTop1.x = pipe1.x + 5;

  pipeBoundsTop1.y = pipe1.y;

  pipeBoundsBottom1.x = pipe1.x + 5;

  pipeBoundsBottom1.y = pipe1.y + 495;

  pipeBoundsTop2.x = pipe2.x + 5;

  pipeBoundsTop2.y = pipe2.y;

  pipeBoundsBottom2.x = pipe2.x + 5;

  pipeBoundsBottom2.y = pipe2.y + 495;

  // lose the game

  if (thingBounds.intersects(pipeBoundsTop1) || thingBounds.intersects(pipeBoundsBottom1)

  || thingBounds.intersects(pipeBoundsTop2) || thingBounds.intersects(pipeBoundsBottom2))

  {

  die();

  }

  }

  }

  // death, show score and click to play again

  private function die():void

  {

  if (!gameOver)

  {

  gameOver = true;

  assets.playSound("smack");

  ce.stage.removeEventListener(MouseEvent.MOUSE_DOWN, fly);

  // prevent clicking briefly to let the player see their score

  var t:Timer = new Timer(500, 1);

  t.addEventListener(TimerEvent.TIMER_COMPLETE, cont);

  t.start();

  function cont(e:TimerEvent):void

  {

  textField.text = "Score: " + score;

  scoreText.text = "";

  eaze(box).to(0.4, { y: 150 } );

  eaze(textField).to(0.4, { y: 150 } );

  ce.stage.addEventListener(MouseEvent.MOUSE_DOWN, startOver);

  }

  }

  }

  // reset everything, start the game again

  private function startOver(e:MouseEvent):void

  {

  eaze(box).to(0.2, { y: -200 } );

  eaze(textField).to(0.2, { y: -200 } );

  score = 0;

  pipe1.x = 380;

  pipe2.x = 620;

  thing.x = 100;

  thing.y = 200;

  velocity = 0;

  gravity = 0.4;

  gameOver = false;

  randomizePipeY();

  ce.stage.removeEventListener(MouseEvent.MOUSE_DOWN, startOver);

  ce.stage.addEventListener(MouseEvent.MOUSE_DOWN, fly);

  }

  }

Thanks,

TOPICS
ActionScript

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2014 Nov 15, 2014

Copy link to clipboard

Copied

use,

stage.displayStage='fullScreen'; 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 15, 2014 Nov 15, 2014

Copy link to clipboard

Copied

Weirdly it is not working....

I've tried to put it in the main function... It doesn't work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 16, 2014 Nov 16, 2014

Copy link to clipboard

Copied

This works fine on Android for me...

stage.displayState = StageDisplayState.FULL_SCREEN;

stage.scaleMode = StageScaleMode.EXACT_FIT;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 16, 2014 Nov 16, 2014

Copy link to clipboard

Copied

Yeah, it should. But, weirdly, it's not...

Here's what I see on the device emulator with Adobe Flash Pro :

print.png

And here's what I see when I install the apk on my Android device :

print2.jpg

Can't understand why it's happening.

The game was in an example package of the citrus engine : https://drive.google.com/file/d/0B5-MjJcEPm3lMU5jSzB0dDBualk/view?usp=sharing

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2014 Nov 16, 2014

Copy link to clipboard

Copied

you have objects offstage.

use:

stage.stageWidth=Capabilities.screenResolutionX;

stage.stageHeight=Capabilities.screenResolutionY;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 16, 2014 Nov 16, 2014

Copy link to clipboard

Copied

Hmm. I've tried :

public function Main() {

stage.stageWidth=Capabilities.screenResolutionX;

stage.stageHeight=Capabilities.screenResolutionY;

stage.displayState = StageDisplayState.FULL_SCREEN;

stage.scaleMode = StageScaleMode.EXACT_FIT;

  trace("fullscreen");

  }

But it still not on fullscreen mode on my Android device...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2014 Nov 16, 2014

Copy link to clipboard

Copied

assuming Main is your document class, try:

public function Main() {

stage.stageWidth=Capabilities.screenResolutionX;

stage.stageHeight=Capabilities.screenResolutionY;

  trace("fullscreen");

  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2015 Dec 18, 2015

Copy link to clipboard

Copied

LATEST

Hii kglad.com,

I am really beginner in this field.And i learn lots of about app development with the help of internet.So you understand what is my actual position in ode development.So please help me.

Here is the same problem regarding fit to screen my app.My app is completely ready to upload on different store.But i am also facing this problem "Doesn't fit on different resolution".

App development software is flash cs6. Can you please brief me easily how i resolve this problem.

My email id is 99264mony@gmail.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines