a function is even over every image.

Hello.
I have a problem. I have a function, calling randomly enemys at random position.
But, i can do what i want, if i want to put a Image over all those enemys, it does not work, the enemys are even over everything else.
How can i fix this?

Thank you :slight_smile:

Are you inserting the enemies into a display group?

Add them all into the same display group, then insert another display group afterwards which will contain anything you want to appear on top of the enemies.

Thank you 4 your fast answer.
The problem is, I have all enemy picture in enemypics als call dem with emeny (random bla bla bla)

Emepypics in a group gives me an error and enemy in the group does not work.

What’s about composer scene? Could it works with it? I didn’t try this till now.

Ore is there any other opportunity?

Can you post your code otherwise it’s difficult to help?

curse:

ill post parts of my code, with explantation, in the same order:

my soldat, i the main character:

local soldat = display.newImage("soldat.png") soldat.x = \_W/2 soldat.y = \_H/2 soldat.rotation = 0

then the soldat function, to rotate the guy - he can rotate above the aiming image, if he likes:

function touched(event) if(event.phase == "began" or event.phase == "moved") then angle = math.deg(math.atan2((event.y-soldat.y),(event.x-soldat.x))) soldat.rotation = angle +90 end end

bg:addEventListener(“touch”, touched)

followed by the enemy function:

local enemypics = {"zombiebrain.png","zombieeye.png","buggreen.png"} function spawnEnemy() local enemy = display.newImage(enemypics[math.random (#enemypics)]) enemy:addEventListener("tap", smash) if math.random(2) == 1 then enemy.x = math.random(-100, -10) -- enemy.y = math.random(10, 100) else enemy.x = math.random ( \_H + \_W ) enemy.xScale = 0 end enemy.y = math.random (\_W + \_H) enemy.trans = transition.to (enemy, {x=centerX, y=centerY, time=3000, onComplete=hitPlanet } ) speedBump = speedBump + 1 angle = math.deg(math.atan2((soldat.y-enemy.y),(soldat.x-enemy.x))) enemy.rotation = angle +90 end getTimer = timer.performWithDelay(900+Rand, spawnEnemy, numbEnemy+Rand)

 and the image, wich should be over everything else:

local soldatlicht = display.newGroup() soldatlicht:insert(lichtkranz) soldatlicht:insert(soldat) soldatlicht:insert(black) local verlauf = display.newImage("verlauf.png") verlauf.anchorX = 0.5 verlauf.anchorY = 0.5 verlauf.x = \_W/2 verlauf.y= \_H/2 soldatlicht:insert(verlauf)

the “soldat” function works correct, if i change the X and Y of his position, he is covered by the “verlauf” (- in englich: gardien)

but all enemypics and enemy´s are not.

i tried to put them into a group, but “enemy” didnt works and “enemypics” gave me an error

Are you inserting the enemies into a display group?

Add them all into the same display group, then insert another display group afterwards which will contain anything you want to appear on top of the enemies.

Thank you 4 your fast answer.
The problem is, I have all enemy picture in enemypics als call dem with emeny (random bla bla bla)

Emepypics in a group gives me an error and enemy in the group does not work.

What’s about composer scene? Could it works with it? I didn’t try this till now.

Ore is there any other opportunity?

Can you post your code otherwise it’s difficult to help?

curse:

ill post parts of my code, with explantation, in the same order:

my soldat, i the main character:

local soldat = display.newImage("soldat.png") soldat.x = \_W/2 soldat.y = \_H/2 soldat.rotation = 0

then the soldat function, to rotate the guy - he can rotate above the aiming image, if he likes:

function touched(event) if(event.phase == "began" or event.phase == "moved") then angle = math.deg(math.atan2((event.y-soldat.y),(event.x-soldat.x))) soldat.rotation = angle +90 end end

bg:addEventListener(“touch”, touched)

followed by the enemy function:

local enemypics = {"zombiebrain.png","zombieeye.png","buggreen.png"} function spawnEnemy() local enemy = display.newImage(enemypics[math.random (#enemypics)]) enemy:addEventListener("tap", smash) if math.random(2) == 1 then enemy.x = math.random(-100, -10) -- enemy.y = math.random(10, 100) else enemy.x = math.random ( \_H + \_W ) enemy.xScale = 0 end enemy.y = math.random (\_W + \_H) enemy.trans = transition.to (enemy, {x=centerX, y=centerY, time=3000, onComplete=hitPlanet } ) speedBump = speedBump + 1 angle = math.deg(math.atan2((soldat.y-enemy.y),(soldat.x-enemy.x))) enemy.rotation = angle +90 end getTimer = timer.performWithDelay(900+Rand, spawnEnemy, numbEnemy+Rand)

 and the image, wich should be over everything else:

local soldatlicht = display.newGroup() soldatlicht:insert(lichtkranz) soldatlicht:insert(soldat) soldatlicht:insert(black) local verlauf = display.newImage("verlauf.png") verlauf.anchorX = 0.5 verlauf.anchorY = 0.5 verlauf.x = \_W/2 verlauf.y= \_H/2 soldatlicht:insert(verlauf)

the “soldat” function works correct, if i change the X and Y of his position, he is covered by the “verlauf” (- in englich: gardien)

but all enemypics and enemy´s are not.

i tried to put them into a group, but “enemy” didnt works and “enemypics” gave me an error