# How to create random 2D maps?

**URL:** <https://forum.defold.com/t/how-to-create-random-2d-maps/68511>\
**Category:** Questions\
**Created:** [May 24, 2021, 11:40am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511 "2021-05-24T11:40:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rhuan\_silva](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rhuan_silva/32/25035_2.png) [@Rhuan\_silva](https://forum.defold.com/u/Rhuan_silva)\
**Post date:** [May 24, 2021, 11:40am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/1 "2021-05-24T11:40:53Z")

</div>

Good morning, I’m developing a ‘hell bullet’ style game. But I’m having trouble creating the rooms, so that the generation of each one is random and the enemies only identify the player after entering the room

 ![Cenario](https://forum-defold-uploads.b-cdn.net/original/3X/7/0/70230737fa0d1b75b24d48a432d068e15d1e9461.png)  
 ![Script](https://forum-defold-uploads.b-cdn.net/original/3X/2/4/249c2400db729953f4406de26b04de071dca56f4.png)

I am now starting to move on defold and game creation, I apologize for the lack of programming knowledge

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 24, 2021, 2:03pm UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/2 "2021-05-24T14:03:28Z")

</div>

> [@Rhuan\_silva](#):
>
> I’m having trouble creating the rooms, so that the generation of each one is random

You need to look into procedural content creation. There are a lot of good articles on this. I’d google something like “roguelike random dungeon algorithm”.

@WhiteBoxDev has a series of video tutorials on procedural content generation. Here’s one of them: [YouTube](https://www.youtube.com/embed/slTEz6555Ts)

You can probably find some inspiration from my old Ludum Dare entry:

HTML5: [Overrun Room 0.1](https://britzl.github.io/OverrunRoom/)  
Source: [GitHub - britzl/oneroom: Ludum Dare #37 · GitHub](https://github.com/britzl/oneroom)  
Using Conway’s game of life algorithm: [oneroom/utils/conway.lua at master · britzl/oneroom · GitHub](https://github.com/britzl/oneroom/blob/master/utils/conway.lua)  
Applied to tilemap: [oneroom/oneroom/level.lua at master · britzl/oneroom · GitHub](https://github.com/britzl/oneroom/blob/master/oneroom/level.lua#L101-L117)

---

<div class="post-metadata">

**Author:** ![Rhuan\_silva](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rhuan_silva/32/25035_2.png) [@Rhuan\_silva](https://forum.defold.com/u/Rhuan_silva)\
**Post date:** [May 26, 2021, 10:42am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/3 "2021-05-26T10:42:21Z")

</div>

Thanks for the help, I had a better idea of ​​what the map would look like for my project and decided to create a continuous map instead of upgradable instances. I still have some doubts, so see you soon (^. ^ ')

---

<div class="post-metadata">

**Author:** ![Rhuan\_silva](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rhuan_silva/32/25035_2.png) [@Rhuan\_silva](https://forum.defold.com/u/Rhuan_silva)\
**Post date:** [May 27, 2021, 10:12am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/4 "2021-05-27T10:12:02Z")

</div>

Good morning, I’m having trouble updating the face of my sprites that are in a collection.

 ![codeSprite](https://forum-defold-uploads.b-cdn.net/original/3X/6/a/6ac80b8a71a8b8730a03a632cd5234ba9570016a.png)  
 ![erroSprite](https://forum-defold-uploads.b-cdn.net/original/3X/7/a/7ae55d1685b620d8f90f282d40f8d073740f9f2f.png)

And another question about how to create a shooting factory for my enemies within a collection. Thank you very much

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 27, 2021, 11:21am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/5 "2021-05-27T11:21:35Z")

</div>

> [@Rhuan\_silva](#):
>
> I’m having trouble updating the face of my sprites that are in a collection

`sprite.set_hflip()` is the correct function to use when you want to flip a sprite. Do you see any errors in the console? Is “#slime” the correct id of the sprite component? What if you print() something in both the if and the else? Is the conditional check evaluated properly?

> [@Rhuan\_silva](#):
>
> how to create a shooting factory for my enemies within a collection

Here’s a project with a player that can move and shoot:

> **[publicexamples/examples/rotate\_and\_move at master · britzl/publicexamples](https://github.com/britzl/publicexamples/tree/master/examples/rotate_and_move)**
>
> Examples for the Defold engine. Contribute to britzl/publicexamples development by creating an account on GitHub.

The basic idea is that you use a factory component to spawn bullets. The bullets are moved using go.animate() and removed when a collision is detected.

---

<div class="post-metadata">

**Author:** ![Rhuan\_silva](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rhuan_silva/32/25035_2.png) [@Rhuan\_silva](https://forum.defold.com/u/Rhuan_silva)\
**Post date:** [May 28, 2021, 5:12am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/6 "2021-05-28T05:12:53Z")

</div>

Good night, I want to thank you because the mistake of the sprites was that the GO id was different from the collection.

Already to create the factory of shots I am realizing that the error is due to the number of created instances of the object.

 ![erroProjetilSlime](https://forum-defold-uploads.b-cdn.net/original/3X/7/d/7d1b69b457533594b0994450f76375db042b226c.png)

This is my script for the slime projectile

 ![scriptProjetilSlime](https://forum-defold-uploads.b-cdn.net/original/3X/6/f/6fa1f136a6163ebee1eec9caeaef8e9e177d4bcc.png)

And here I create his factory in the slime script

 ![scriptSlime](https://forum-defold-uploads.b-cdn.net/original/3X/7/6/761f8edd777dbc3102113657dd7df077ab8a28c3.png)

note: I increased the speed and also tried to destroy the objects before they accumulated, but I didn’t understand what was wrong. If you have any suggestions I am grateful

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 28, 2021, 6:49am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/7 "2021-05-28T06:49:05Z")

</div>

> [@Rhuan\_silva](#):
>
> If you have any suggestions I am grateful

Please share code in text mode instead of screenshots!

I noticed that the console says the sprite buffer is full. You can increase the buffer size in the Sprite section of game.project. Set it to a value that matches some kind of theoretical maximum number of bullets you want in your game.

---

<div class="post-metadata">

**Author:** ![Rhuan\_silva](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rhuan_silva/32/25035_2.png) [@Rhuan\_silva](https://forum.defold.com/u/Rhuan_silva)\
**Post date:** [May 28, 2021, 9:37am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/8 "2021-05-28T09:37:49Z")

</div>

I’m sorry, I’m still learning to work with the defold tool and the forum.

I managed to fix the code where I created several instances of the object, it looks like this

```lua
function update(self, dt)
	local pos = go.get_position() -- Cria a variavel 'pos' e atribui a posição atual do objeto projetil
    pos = pos + self.dir * self.speed * dt -- A variável 'pos' recebe a soma dos eixos (x, y, z) vezes a velocidade vezes o deltaT('deltaT ajusta o fps do aparelho mobile para melhor eficiência')
    go.set_position(pos)

	self.life = self.life - dt

	if not self.collided then -- Se objeto projetil não colidir execute o código
		local new_position = pos + self.dir * self.speed * dt
		go.set_position(new_position) -- Atualiza posição do objeto projetil gerado

		if self.life < 0 then -- Se o tempo do projetil for menor que 0, inicia a contagem ate tempo de vida do objeto após disparo
			self.speed = 0
			go.delete()
		end
	else
		sprite.play_flipbook('#projetil_slime_enemy', hash('atirar'), go.delete())	-- Se colidir, delete o objeto projetil
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash('contact_point_response') then -- Se local de contato de 2 objetos
		self.collided = true -- Colisão verdadeira
		self.target = message.other_id -- Armazena id do objeto alvo
		self.message_collision = true
	end
end

```

But the projectile is still standing on top of the slime, I’m having trouble understanding the factory.create () documentation

```lua
	local direction = 0
	if distance_to_player >= self.min_follow_distance and distance_to_player <= self.max_follow_distance then
		direction = 1
	elseif distance_to_player >= self.min_retreat_distance and distance_to_player <= self.max_retreat_distance then
		direction = -1
	end

	direction = 1

	local angle = -math.atan2(playerPos.x - enemyPos.x, playerPos.y - enemyPos.y) -- Calcula a direção angulo do jogador em relação ao inimigo
	local rot = vmath.quat_rotation_z(angle) -- Marca como alvo a posição calculada
	go.set_position(enemyPos + self.correction + vmath.rotate(rot, NORTH) * self.speed * dt * direction)	-- Calcula a posição do slime atraves do alvo marcado e velocidade do slime

	local props = self.correction + vmath.rotate(rot, NORTH) * self.speed * dt * direction
	print('rot ------- ',rot)
	print('props --------- ',props)

	self.correction = vmath.vector3()

	if self.rate_of_fire > 0 then
		if distance_to_player >= self.min_fire_distance and distance_to_player <= self.max_fire_distance then
			self.time_until_next_bullet = self.time_until_next_bullet - dt
			if self.time_until_next_bullet <= 0 then
				self.time_until_next_bullet = 1 / self.rate_of_fire
				factory.create( '#slime_projetil', nil, rot)
				msg.post(".", "slime_projetil")
			end
		end
	end

```

I apologize, I am still a novice and I am very grateful for all the help

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 28, 2021, 9:40am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/9 "2021-05-28T09:40:42Z")

</div>

> [@Rhuan\_silva](#):
>
> But the projectile is still standing on top of the slime, I’m having trouble understanding the factory.create () documentation

> [@Rhuan\_silva](#):
>
> `factory.create( '#slime_projetil', nil, rot)`

This will create the projectile but you have no code that moves it. If you look at the example I shared you notice that I use go.animate() to move the bullet after it is created:

> <https://github.com/britzl/publicexamples/blob/master/examples/rotate_and_move/rotate_and_move/rotate_and_move.script#L69-L73>

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [May 28, 2021, 9:43am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/10 "2021-05-28T09:43:51Z")

</div>

I interpreted it as the first script:

```lua
function update(self, dt)
	local pos = go.get_position() -- Cria a variavel 'pos' e atribui a posição atual do objeto projetil
    pos = pos + self.dir * self.speed * dt -- A variável 'pos' recebe a soma dos eixos (x, y, z) vezes a velocidade vezes o deltaT('deltaT ajusta o fps do aparelho mobile para melhor eficiência')
    go.set_position(pos)

```

However, some things to check. Is the script attached to the gameobject?  
What are the `self.dir` and `self.speed`? If any of those are 0 then it wont move.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 28, 2021, 9:46am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/11 "2021-05-28T09:46:44Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> I interpreted it as the first script

Ah, you are right! Sorry!

> [@Mathias\_Westerdahl](#):
>
> What are the `self.dir` and `self.speed`? If any of those are 0 then it wont move

Yes, check those! Also check that the collision object on the bullet isn’t dynamic. If it is dynamic it will not move unless Allow Dynamic Transforms is checked in game.project.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [May 28, 2021, 9:49am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/12 "2021-05-28T09:49:02Z")

</div>

> [@britzl](#):
>
> Yes, check those! Also check that the collision object on the bullet isn’t dynamic. If it is dynamic it will not move unless Allow Dynamic Transforms is checked in game.project.

Dynamic objects will move if there is gravity? I guess you mean “kinematic”?  
And, the “allow dynamic transforms” allows for the collision objects to be scaled with the game object (and also moving dynamic objects).

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 28, 2021, 9:51am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/13 "2021-05-28T09:51:44Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> Dynamic objects will move if there is gravity

True, but if he set gravity to 0 for some reason then it would just stay in place… but more likely is that self.dir or self.speed is 0

---

<div class="post-metadata">

**Author:** ![Rhuan\_silva](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rhuan_silva/32/25035_2.png) [@Rhuan\_silva](https://forum.defold.com/u/Rhuan_silva)\
**Post date:** [May 28, 2021, 10:34am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/14 "2021-05-28T10:34:27Z")

</div>

self.dir is really 0, because if I put some value. example (0, 1, 0) shots are fixed on the y axis  
This is the projectile\_slime.script

```lua
go.property("dir", vmath.vector3(0, 0, 0))

function init(self)

	self.speed = 200 -- Velocidade do projetil
	self.life = 1 -- Tempo de vida do objeto projetil em segundos
end

function update(self, dt)
	local pos = go.get_position() -- Cria a variavel 'pos' e atribui a posição atual do objeto projetil
    pos = pos + self.dir * self.speed * dt -- A variável 'pos' recebe a soma dos eixos (x, y, z) vezes a velocidade vezes o deltaT('deltaT ajusta o fps do aparelho mobile para melhor eficiência')
	print('dir --- ',self.dir)
	go.set_position(pos)

	self.life = self.life - dt

	if not self.collided then -- Se objeto projetil não colidir execute o código
		local new_position = pos + self.dir * self.speed * dt
		go.set_position(new_position) -- Atualiza posição do objeto projetil gerado

		if self.life < 0 then -- Se o tempo do projetil for menor que 0, inicia a contagem ate tempo de vida do objeto após disparo
			self.speed = 0
			go.delete()
		end
	else
		sprite.play_flipbook('#projetil_slime_enemy', hash('atirar'), go.delete())	-- Se colidir, delete o objeto projetil
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash('contact_point_response') then -- Se local de contato de 2 objetos
		self.collided = true -- Colisão verdadeira
		self.target = message.other_id -- Armazena id do objeto alvo
		self.message_collision = true
	end
end

```

This is the slime.script

```lua
go.property("health", 3)
go.property("speed", 50)
go.property("rate_of_fire", 10)
go.property("min_fire_distance", 0)
go.property("max_fire_distance", 1000)
go.property("min_follow_distance", 0)
go.property("max_follow_distance", 100)
go.property("min_retreat_distance", 0)
go.property("max_retreat_distance", 0)

local NORTH = vmath.vector3(0, 1, 0)

function init(self)
	msg.post('.', 'acquire_input_focus')
	self.correction = vmath.vector3()
	self.time_until_next_bullet = 0
end

function update(self, dt)
	local playerPos = go.get_position('/heroi')
	local enemyPos = go.get_position()
	local distance_to_player = vmath.length(playerPos - enemyPos)

	if playerPos.x > enemyPos.x then
		sprite.set_hflip("#slime_enemy", true)
	else
		sprite.set_hflip("#slime_enemy", false)
	end

	local direction = 0
	if distance_to_player >= self.min_follow_distance and distance_to_player <= self.max_follow_distance then
		direction = 1
	elseif distance_to_player >= self.min_retreat_distance and distance_to_player <= self.max_retreat_distance then
		direction = -1
	end

	direction = 1

	local angle = -math.atan2(playerPos.x - enemyPos.x, playerPos.y - enemyPos.y) -- Calcula a direção angulo do jogador em relação ao inimigo
	local rot = vmath.quat_rotation_z(angle) -- Marca como alvo a posição calculada
	go.set_position(enemyPos + self.correction + vmath.rotate(rot, NORTH) * self.speed * dt * direction)	-- Calcula a posição do slime atraves do alvo marcado e velocidade do slime

	local props = self.correction + vmath.rotate(rot, NORTH) * self.speed * dt * direction
	print('rot ------- ',rot)
	print('props --------- ',props)

	self.correction = vmath.vector3()

	if self.rate_of_fire > 0 then
		if distance_to_player >= self.min_fire_distance and distance_to_player <= self.max_fire_distance then
			self.time_until_next_bullet = self.time_until_next_bullet - dt
			if self.time_until_next_bullet <= 0 then
				self.time_until_next_bullet = 1 / self.rate_of_fire
				factory.create( '#slime_projetil', props, rot)
				msg.post(".", "slime_projetil")
			end
		end
	end
end

```

The problem is that when I pass the player’s position (x, y), factory.create () is not updating according to the player’s position and does not shoot

 ![erroProps](https://forum-defold-uploads.b-cdn.net/original/3X/9/1/914856474c0c69185827c74f52bf51a0093ff1b1.png)

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 28, 2021, 10:50am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/15 "2021-05-28T10:50:29Z")

</div>

> [@Rhuan\_silva](#):
>
> when I pass the player’s position (x, y)

Where do you do this? And are you sure it is the correct value?

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [May 28, 2021, 10:53am UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/16 "2021-05-28T10:53:59Z")

</div>

> [@Rhuan\_silva](#):
>
> self.dir is really 0

If the direction is 0, then it just won’t go anywhere.

You should pass properties to the factory when creating the bullet.  
The factory will pass it on to the gameobject.

---

<div class="post-metadata">

**Author:** ![Rhuan\_silva](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rhuan_silva/32/25035_2.png) [@Rhuan\_silva](https://forum.defold.com/u/Rhuan_silva)\
**Post date:** [May 28, 2021, 3:44pm UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/17 "2021-05-28T15:44:29Z")

</div>

I apologize for the delay, I spent hours trying to resolve it and luckily it worked. Thank you very much @Mathias_Westerdahl and @britzl

This is the projectile\_slime.script

```lua
go.property("health", 3)
go.property("rate_of_fire", 1)
go.property("min_follow_distance", 0)
go.property("max_follow_distance", 1000)
go.property("min_retreat_distance", 0)
go.property("max_retreat_distance", 0)

local NORTH = vmath.vector3(0, 1, 0)

function init(self)
	self.speed = 200 -- Velocidade do projetil
	self.life = 1 -- Tempo de vida do objeto projetil em segundos
end

function update(self, dt)
	self.life = self.life - dt

	if not self.collided then -- Se objeto projetil não colidir execute o código
		local playerPos = go.get_position('/heroi')
		local projetilPos = go.get_position()
		local distance_to_player = vmath.length(playerPos - projetilPos)

		local direction = 0
		if distance_to_player >= self.min_follow_distance and distance_to_player <= self.max_follow_distance then
			direction = 1
		elseif distance_to_player >= self.min_retreat_distance and distance_to_player <= self.max_retreat_distance then
			direction = -1
		end

		local angle = -math.atan2(playerPos.x - projetilPos.x, playerPos.y - projetilPos.y) -- Calcula a direção angulo do jogador em relação ao inimigo
		local rot = vmath.quat_rotation_z(angle) -- Marca como alvo a posição calculada
		go.set_position(projetilPos + vmath.rotate(rot, NORTH) * self.speed * dt * direction)	-- Calcula a posição do slime atraves do alvo marcado e velocidade do slime

		if self.life < 0 then -- Se o tempo do projetil for menor que 0, inicia a contagem ate tempo de vida do objeto após disparo
			go.delete()
		end
	else
		sprite.play_flipbook('#projetil_slime_enemy', hash('atirar'), go.delete())	-- Se colidir, delete o objeto projetil
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash('contact_point_response') then -- Se local de contato de 2 objetos
		self.collided = true -- Colisão verdadeira
		self.target = message.other_id -- Armazena id do objeto alvo
		self.message_collision = true
	end
end

```

this is the slime.script

```lua
go.property("health", 3)
go.property("speed", 50)
go.property("min_fire_distance", 0)
go.property("max_fire_distance", 200)

local NORTH = vmath.vector3(0, 1, 0)

function init(self)
	msg.post('.', 'acquire_input_focus')
	self.correction = vmath.vector3()
	self.time_until_next_bullet = 0
end

function update(self, dt)
	local playerPos = go.get_position('/heroi')
	local enemyPos = go.get_position()
	local distance_to_player = vmath.length(playerPos - enemyPos)

	if playerPos.x > enemyPos.x then
		sprite.set_hflip("#slime_enemy", true)
	else
		sprite.set_hflip("#slime_enemy", false)
	end

	local angle = -math.atan2(playerPos.x - enemyPos.x, playerPos.y - enemyPos.y) -- Calcula a direção angulo do jogador em relação ao inimigo
	local rot = vmath.quat_rotation_z(angle) -- Marca como alvo a posição calculada
	go.set_position(enemyPos + self.correction + vmath.rotate(rot, NORTH) * self.speed * dt) -- Calcula a posição do slime atraves do alvo marcado e velocidade do slime

	if distance_to_player >= self.min_fire_distance and distance_to_player <= self.max_fire_distance then
		self.time_until_next_bullet = self.time_until_next_bullet - dt
		if self.time_until_next_bullet <= 0 then
			factory.create( '#slime_projetil')
		end
	end
end

```

---

<div class="post-metadata">

**Author:** ![Rhuan\_silva](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rhuan_silva/32/25035_2.png) [@Rhuan\_silva](https://forum.defold.com/u/Rhuan_silva)\
**Post date:** [May 28, 2021, 3:51pm UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/18 "2021-05-28T15:51:08Z")

</div>

I have a question, what is the difference in creating several go.property and creating self.x in the init function?

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [May 28, 2021, 4:05pm UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/19 "2021-05-28T16:05:02Z")

</div>

You can see the `go.property()`in the editor, in the properties pane, when clicking on the script component. It makes it easier for a game designer to change the initial values of a game object.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [May 28, 2021, 4:06pm UTC](https://forum.defold.com/t/how-to-create-random-2d-maps/68511/20 "2021-05-28T16:06:46Z")

</div>

> [@Rhuan\_silva](#):
>
> `sprite.play_flipbook(...`

Note that you are starting the animation each time in the update loop.  
Not only is it redundant, but if you wish to have animations with more than one frame, you will only ever see the first frame.

[Next page](https://forum.defold.com/t/how-to-create-random-2d-maps/68511.md?page=2)
