# Which is best way of creating group of enemy? tiles way or the programmatic way?

Attention Topic was automatically imported from the old Question2Answer platform.

I have created simple 2D Arcade game for mobile device. Where as player can move left and right to avoid obstacles that is coming from top to bottom. My obstacles are sticking around the left and right edges of the mobile screen. This is a simple prototype, also It is working file.

Here is the Image File

The problem with this approach is all obstacles are added at run time with some logic. Also I have to perform some calculation on obstacles to fit on different screen size of mobile screen. The runtime math calculation on obstacles goes really big.

To avoid this I planned to go for the second solution But don’t know how to achieve this in godot engine.

Here is my second solution
Instead of creating Obstacles at runtime and attaching it to the edges of the screen, I want to create a new scene that includes all the Obstacles placed inside of it as ready made one. In need I can attach this obstacles scene as a child of the main scene so that player can play around. But HERE COMES THE PROBLEM.

How can I create obstacles scene separately that can fit for different screen size?
Note [ Portrait is the only mode for mobile device]

You actually have not described what problem you are facing in the second solution. No mindreaders around today

Reloecc | 2020-09-15 07:04

I am new to Godot and GdScript. Creating things dynamically itself is difficult for me but somehow I can manage creating things with editor. I am looking for runtime solution with easiest way.

anbarasu chinna | 2020-09-15 12:48

If so, maybe you just may change a stretch mode of your whole application in [ Godot > Project > Project settings > Display > Window > Stretch > Mode | Aspect | Stretch ]

Reloecc | 2020-09-15 13:04

I would…

A) create a scene for an Obstacle with a script with a `func setHole(left :int, width :int, angle :float)`

B) prepare few obstacles during first game loading (based on your sketch, you’ll need ~8 of them?).

C) recycle obstacles going out of screen, set new hole via `setHole`, place them above the top of the game scene and make them move to bot again

If your obstacles are going to be made out of textures (fancy animations, pixel perfect graphics or so) you may create multiple types of obstacle scene and recycle few types.

If your holes are not going to be quads only, you also may want to prepare some types with different `func setHole` eg. `setHoles(holes :Array)` for multiple holes and so on.

I do not believe (based on your sketch) there are some heavy calculations needed for obstacle placing during runtime. May you elaborate on this point? What calculations are you perfrorming currently in solution 1?

In case you are going to have so many different types of obstacles (with saws, lasers, goos, spikes, two holes etc.) you may prepare that many obstacle scenes, precache (save to array) them per type and duplicate them via `.duplicate()` during loading. This way you’ll go your heavy calculations once per obstacle only (I suppose that calculations are needed only for left and right sides of obstacles).

From my point of view positioning, scaling, distancing parameters are seems complex. I will try to create simple obstacle as a scene with script attached init and add it to the scene at runtime as you said and will recycle it for complex levels.

anbarasu chinna | 2020-09-15 08:29

What is .dublicate() function you explained above. Is that same as scene.instance() can you explain it?

anbarasu chinna | 2020-09-15 08:30

You can duplicate nodes with Node — Godot Engine (stable) documentation in English

`.instance()` is not an approach I recommend because I adviced you to prepare your obstacles (set them correct widths) prior the game runnin and duplicate them on runtime. This way you do not need to calculate widths (what you believe is cpu heavy). If you’d `.instance()` new scenes for every obstacle, you’d have to calculate widths for them every time they are about to appear.

Reloecc | 2020-09-15 10:14

Feel free to share a full code if you need futher help, it’s going to be easier to help you.

Reloecc | 2020-09-15 10:15

As you suggest I recycle my obstacles to have predefined with and height. So it will not calculated at runtime. Along with your approach duplicating node can save lots of cpu usage. Definitely I will use this approach. Good one

anbarasu chinna | 2020-09-15 12:55