# Problemas con surface.setResizable(true) y fullscreen

**URL:** https://discourse.processing.org/t/problemas-con-surface-setresizable-true-y-fullscreen/21396
**Category:** Español
**Created:** [May 29, 2020, 9:51am UTC](https://discourse.processing.org/t/problemas-con-surface-setresizable-true-y-fullscreen/21396 "2020-05-29T09:51:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hokuto](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hokuto/32/2139_2.png) [@hokuto](https://discourse.processing.org/u/hokuto)
#### Post date: [May 29, 2020, 9:51am UTC](https://discourse.processing.org/t/problemas-con-surface-setresizable-true-y-fullscreen/21396/1 "2020-05-29T09:51:00Z")

</div>

Hola que tal.

Estoy intentando hacer un pequeño juego de naves a una resolucion de 640x480,el problema que tengo es que cuando uso la funcion surface.setResizable(true) y maximizo la ventana,la imagen del juego no se estira,si no que quedan unos bordes negros abajo y a la derecha de la imagen.

Me pasa lo mismo cuando utilizo la funcion fullscreen,alguna solucion para esto.  
Un amigo me comento que creara una superficie con createGraphics() y pintara todos los objetos en esa superficie pero tampoco me ha funcionado,ya no se que hacer mas.

 ![Captura](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/ae63832dacc0373d162a0d8d13b7f7ce4b71fd0f.png)

---

<div class="post-metadata">

### Author: ![cansik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cansik/32/8815_2.png) [@cansik](https://discourse.processing.org/u/cansik)
#### Post date: [May 29, 2020, 7:53pm UTC](https://discourse.processing.org/t/problemas-con-surface-setresizable-true-y-fullscreen/21396/2 "2020-05-29T19:53:06Z")

</div>

I guess the problem is that you are using static values in your sketch. Here is a very simple example that shows you how to create a responsive sketch. The margin between the right border and the circle is always `100`. In your game, you always have to take the current width into account and of course the screen ratio (4:3).

```auto
void setup() {
  size(500, 500);
  
  surface.setResizable(true);
}

void draw() {
  background(55);
  
  circle(width - 100, height / 2, 50);
}

```

---

<div class="post-metadata">

### Author: ![hokuto](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hokuto/32/2139_2.png) [@hokuto](https://discourse.processing.org/u/hokuto)
#### Post date: [May 31, 2020, 9:18am UTC](https://discourse.processing.org/t/problemas-con-surface-setresizable-true-y-fullscreen/21396/3 "2020-05-31T09:18:33Z")

</div>

Ya he podido solucionarlo creando una superficie con   
createGraphics() y pintando todo hay.Tengo otra duda,me gustaria que al ponerlo en pantalla completa o maximizar la ventana no se estire la imagen,en vez de eso quiero que mantenga un apecto de 4:3 con el fondo centrado y no en una esquina.

---

<div class="post-metadata">

### Author: ![cansik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cansik/32/8815_2.png) [@cansik](https://discourse.processing.org/u/cansik)
#### Post date: [June 1, 2020, 8:30am UTC](https://discourse.processing.org/t/problemas-con-surface-setresizable-true-y-fullscreen/21396/4 "2020-06-01T08:30:26Z")

</div>

Have a look at [imageMode](https://processing.org/reference/imageMode_.html):

```auto
imageMode(CENTER)
image(canvas, width / 2, height / 2);

```

To keep the ratio, you have to calculate it with simple math:

1. find ratio between canvas width & height
2. find out which length to scale (canvas width or height) by using the sketch width & height
3. scale the longer one to the sketch size and apply the same length multiplied with the ratio to the other length (for example: `canvas_height = height; canvas_width = height * ratio;`)

---

<div class="post-metadata">

### Author: ![hokuto](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hokuto/32/2139_2.png) [@hokuto](https://discourse.processing.org/u/hokuto)
#### Post date: [June 1, 2020, 9:16am UTC](https://discourse.processing.org/t/problemas-con-surface-setresizable-true-y-fullscreen/21396/5 "2020-06-01T09:16:27Z")

</div>

Gracias por la ayuda. 👍
