I'm using Corona SDK in my Lua code I'm trying to transition from one screen to the next and show objects that are hidden, alpha = 0, by simply adjusting their alpha to equal 1. When I ran my code its only working properly for the very last element in the array, but nothing is happening to the rest. My code is below.
Main:
--------------------------------------
local function test2ScreenTransition()
--Gets the files level1 & Menu for use
require "Menu"
require "level1"
--Creates a menu screen, First Screen seen
local menu = Menu:new();
--Creates level 1 screen, Creates Enemies hidden at this point
local lvl1 = level1;
lvl1.new();
--Event when the user pushes the Play button on the menu, Transitions to level 1
local onPlayButTouched = function(e)
--Hides Menu Screen
menu:hide();
--HERE IS THE ISSUE FUNCTION, Suppose to call this function and change alphas of the objects
--to 1
lvl1.show();
end
local onMenuHidded = function(e)
lvl1.isVisible = true;
end
Runtime:addEventListener ( "playButTouched", onPlayButTouched )
Runtime:addEventListener ( "menuHidden", onMenuHidded )
end
.
level1
------------------------------------------
--New Level 1 table
level1 = {};
--Array Holding Objects Needings Alpha changed
local array = {};
function level1.new()
end
--Filling Array with Objects
function level1.addEnemies()
local Enemy = require "Enemy"
local StartX = 50;
local StartY = 20;
local counter = 0;
for i=0, 17 do
array[i] = Enemy;
array[i].new({x=StartX,y=StartY});
--print(i);
if counter > 4 then
StartX = 50;
StartY = StartY+35;
counter=0;
else
StartX =StartX+35;
counter = counter+1;
end
end
end
--FUNCTION HAVING ISSUES WITH
function level1.show()
for i = 0, 17 do
array[i].show();
end
end
level1.addEnemies();
return level1;
.
Enemy
---------------------------------
enemy = {};
--Table that holds properties of Object
local Obj = {};
function enemy.new(args)
Obj.x = args.x;
Obj.y = args.y;
Obj.spriteTexFile= "MYIMG.png";
Obj.sprite = display.newImage( Obj.spriteTexFile);
Obj.sprite:setReferencePoint ( display.TopLeftReferencePoint );
Obj.sprite.x = Obj.x;
Obj.sprite.y = Obj.y;
Obj.sprite.alpha = 0;
end
--FUNCTION HAVING ISSUES WITH
function enemy.show()
Obj.sprite.alpha = 1;
end
return enemy;
I noticed that its processing the same address every time in the table. I printed out the table numbers and am noticing the addresses are the same, hence why is only one object is changing. Yet I still don't why this is happening.