images not showing visually.

Hey guys, could anyone tell me what I’m doing wrong? My games got enemies that spawn randomly through a timer however, when they spawn their images don,t show up, even though the actual spawn is onscreen with collision, its invisible. I’ve set it up so it uses storyboard. Have I set up storyboard assets incorrectly? any help would be awesome, the terminal (Mac) is showing no errors.

Here are some key parts to my setup

local physics = require “physics”
physics.start()

local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

function scene:createScene( event )
print( “Menu: createScene event”)
local screenGroup = self.view

local enemies = display.newGroup()

screenGroup:insert(enemies)

function addEnemy(e)
enemy = display.newImage(‘enemyA.png’)
enemy.y = math.floor(math.random() * (display.contentHeight))
enemy.x = (display.contentWidth)
enemy.name = ‘enemy’
physics.addBody(enemy, { isSensor = true })
enemy.bodyType = ‘static’
enemy.speed = math.random(2,100)
enemies.insert(enemies, enemy)
enemy:addEventListener(‘collision’, collisionHandler)
print(“enemy”)

end

function update(event)

if(enemies.numChildren ~= 0) then
for i = 1, enemies.numChildren do
if(enemies[i] ~= nil) then
enemies[i].x = enemies[i].x - 3

if(enemies[i].x < -200) then
enemies:remove(enemies[i])
display.remove(enemies[i])
changeHealth( 10 )
print(“UFO destroyed”)
end
end
end
end
end
end

function scene:enterScene( event )
print( “GAME: enterScene event” )

Runtime:addEventListener(‘enterFrame’, update)
Runtime:addEventListener(‘enterFrame’, spawn)
end

I haven’t used storyboards, but typically if you don’t see the enemy sprite, but the collision is working, then it is a layering problem.

A couple of things.

1.  I don’t know that you can do:   somegroup:insert(somegroup, someobject)

It needs to be either:   somegroup:insert(someobject)  or somegroup:insert(index, someobject).

  1. Do you have a background?  If so where is it being created?  Keep in mind any display object NOT in a storyboard display group/view will sit on top of all storyboard managed objects.

PS.  Use and tags (leaving out the space) so that your code is easier to read.

Thanks for the response guys.
@ Rob Miracle - I am using a back ground, and its called after the scene group is made. I have tried to insert the background using screen group:insert(background), but that didn’t work either. I have tried changing the way I insert objects, but it still didn’t work correctly. Its weird because before I put it into using storyboard it worked fine.

@Micah_neveu - I tried changing the layering of images, but it never worked. All other images are showing fine, including the player, its just the enemy images.

Corona orders the layers in the order you insert them into groups.  If you add a button, then a background, the background will be on top of the button.  There is two ways to solve this.  1.  The obvious, create the background first.  2.  Use the object:toFront() and object:toBack() API calls.  These will move something either to the top most layer or the back most layer.

I haven’t used storyboards, but typically if you don’t see the enemy sprite, but the collision is working, then it is a layering problem.

A couple of things.

1.  I don’t know that you can do:   somegroup:insert(somegroup, someobject)

It needs to be either:   somegroup:insert(someobject)  or somegroup:insert(index, someobject).

  1. Do you have a background?  If so where is it being created?  Keep in mind any display object NOT in a storyboard display group/view will sit on top of all storyboard managed objects.

PS.  Use and tags (leaving out the space) so that your code is easier to read.

Thanks for the response guys.
@ Rob Miracle - I am using a back ground, and its called after the scene group is made. I have tried to insert the background using screen group:insert(background), but that didn’t work either. I have tried changing the way I insert objects, but it still didn’t work correctly. Its weird because before I put it into using storyboard it worked fine.

@Micah_neveu - I tried changing the layering of images, but it never worked. All other images are showing fine, including the player, its just the enemy images.

Corona orders the layers in the order you insert them into groups.  If you add a button, then a background, the background will be on top of the button.  There is two ways to solve this.  1.  The obvious, create the background first.  2.  Use the object:toFront() and object:toBack() API calls.  These will move something either to the top most layer or the back most layer.