How to create a group

Personal, I have a project in which I need to continually move two objects (the enemies in the case) on the screen. Perempts that I have to make a group to move them but do not know how to do. Can someone help me?

I knew this group would help at the time of the collision, when I want to eliminate only one enemy.

The problem is because currently I have 5 functions to move a single enemy, one to eliminate it from the screen and position it in another corner of the screen. Fisting all the enemies I have 20 functions only for the movement of the enemies and I know that this is not the correct way to do

If you are using Physics for collision detection, you cannot put objects in a group and move that group, then hope for the objects to collide with objects in other groups.  Box2D as utilized by Corona can’t handle this.

Can I suggest you zip up your project and share it with on on drop box?  Someone may then be able to give you some suggestions.

What do you mean position it in another corner of the screen? Please post code for us to work with, or zip it up and share it on DropBox.

Friend, I’ll put the github link ok?

Answering your question, I want that when the shot hits an enemy, it removes the shot and removes or repositions the enemy in position y = 0

For you to understand better, I’m doing a River-Raid style game.

The game starts at the start.lua that goes to the game.lua that calls the enemy in the enemy.lua that when and onimigo to collect with the ship must go to the gameover.lua and the cycle continues from the game.lua.

The link is this:

Https://github.com/andersonf007/River-Raid.git

If you want to talk about whatsapp +55 (81) 9.9679-8640

I also realized that I can not use the group for this situation, but I do not know how to do so after the shot collides with the enemy, repositioning the enemy in position y = 0

Game looks cool! I did immediately get an error when I hit an enemy: 

ERROR: Runtime error enemy.lua:120: attempt to compare nil with number

Looks like there’s a lot of debugging to do. I will help.  :wink:

Yes, this always appears

I do not know what to do anymore, lol

thank you

I was thinking of changing it that way.

Function creatingEnemy (x, y, name)

Enemy = display.newRect (0, 0, 20, 20) - first enemy

Enemy: setFillColor (1, 0.5, 0.5, 1)

Enemy x = x

Enemy and

Enemy.speed = 1

Enemyname = name

Enemy.validation = true

Physics.setGravity (0,0)

Physics.addBody (enemy, {friction = 1, bounce = 0})

Return enemy

End

Function enemy: createEnemy () - create enemy

Enemy1 = creatingEnemy (70,20, “enemy”)

Enemy2 = creatingEnemy (70,250, “enemy2”)

Enemy3 = creatingEnemy (240,130, “enemy3”)

Enemy4 = creatingEnemy (240,220, “enemy4”)

End

Because I have 20 functions to move the 4 enemies, now imagine that it was 10 enemies? It seems that this way can help me to reduce the numbers of functions

Or instead you could have the enemyCreate function and add each enemy into a table, then you could just do:

for i = 1, #enemyTable do enemyTable[i]:removeSelf() --or you could add physics, movement, etc. end

In fact, here is a sample of something I worked on to get you started, I will add the file below.

The error on line 120 in enemy.lua appears to be this problem: for some reason inimigo is nil. This could be because you have them in a function, but you never called the function. Try adding local inimigo1, 2, 3, 4, etc. at the top of your enemy.lua file, and see if it works.

Here is the sample: (hope it helps)

Oh, to use the sample, in the text field type a number that is less than 1000, than a crate will fall with a number on it.

Oh wait that’s the wrong one, this is the right one:

Ok, I’ll take a look and analyze to see what I can do

Thanks for the help.

You are welcome.

Hey friend, I was able to remove an enemy (trying the enemy on the left side, which is closer to the ship) but after it collides and it goes to the position it should when the shot hits it appears that message

what you mean?

ERROR: C: \ Users \ ander \ Documents \ IFPE 2017.1 \ game development \ corona \ Riverraid \ enemy.lua: 21: physics.addBody () can not be called when the world is locked and in the middle of number crunching, such As during a collision event

This error means you cannot add or remove physics bodies while a collision event is still happening. The normal solution to this is to do your actions to add or remove your object in a short timer, something like:

timer.performWithDelay(10, function() display.remove(myObject); end) -- or code to add a new enemy

Rob

ok,thx

If you are using Physics for collision detection, you cannot put objects in a group and move that group, then hope for the objects to collide with objects in other groups.  Box2D as utilized by Corona can’t handle this.

Can I suggest you zip up your project and share it with on on drop box?  Someone may then be able to give you some suggestions.

What do you mean position it in another corner of the screen? Please post code for us to work with, or zip it up and share it on DropBox.

Friend, I’ll put the github link ok?

Answering your question, I want that when the shot hits an enemy, it removes the shot and removes or repositions the enemy in position y = 0

For you to understand better, I’m doing a River-Raid style game.

The game starts at the start.lua that goes to the game.lua that calls the enemy in the enemy.lua that when and onimigo to collect with the ship must go to the gameover.lua and the cycle continues from the game.lua.

The link is this:

Https://github.com/andersonf007/River-Raid.git

If you want to talk about whatsapp +55 (81) 9.9679-8640

I also realized that I can not use the group for this situation, but I do not know how to do so after the shot collides with the enemy, repositioning the enemy in position y = 0

Game looks cool! I did immediately get an error when I hit an enemy: 

ERROR: Runtime error enemy.lua:120: attempt to compare nil with number

Looks like there’s a lot of debugging to do. I will help.  :wink:

Yes, this always appears

I do not know what to do anymore, lol

thank you

I was thinking of changing it that way.

Function creatingEnemy (x, y, name)

Enemy = display.newRect (0, 0, 20, 20) - first enemy

Enemy: setFillColor (1, 0.5, 0.5, 1)

Enemy x = x

Enemy and

Enemy.speed = 1

Enemyname = name

Enemy.validation = true

Physics.setGravity (0,0)

Physics.addBody (enemy, {friction = 1, bounce = 0})

Return enemy

End

Function enemy: createEnemy () - create enemy

Enemy1 = creatingEnemy (70,20, “enemy”)

Enemy2 = creatingEnemy (70,250, “enemy2”)

Enemy3 = creatingEnemy (240,130, “enemy3”)

Enemy4 = creatingEnemy (240,220, “enemy4”)

End

Because I have 20 functions to move the 4 enemies, now imagine that it was 10 enemies? It seems that this way can help me to reduce the numbers of functions