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.
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.
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
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.
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
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.
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.
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
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