Hi,
I am going to be quite precise in what I have been battling for what seems like eons.
I have a set of 5 sprites.
They are put into a loop which is passed to another loop which creates a grid of enemies (think space invaders).
When enemies are shot the score is increased.
Fine no problems.
My problem is that the enemies when shot need to each display a different score.
So
row 1 should display 100pts
row 2 should display 100pts
row 3 should display 200pts
row 4 should display 200pts
row 5 should display 300pts
The issue is I created the sprites in a loop, I tried to assign values and pass as an argument to the create function but no good. I am afraid I just dont get it.
Please look at the code to understand the problem as it should become clear, so any solutions would be awesome please.
The code below is what I started with when I have just a single score.
Here is the modified version I had a crack at: http://pastebin.com/2NXevHz5
The modified versio is nearly working but as you can see when the loop is ran it will always report a score of 500 for ALL enemies.
[lua]
SPRITE SHEET + FUNCTION
local public = {}
local sheets = {}
local sequences = {}
public.sheets = sheets
public.sequences = sequences
sheets.invaders = {}
public.createSpriteStuff = function()
local sheetData = {
width = 53,
height = 38,
numFrames = 2,
}
local i
for i=1,5 do
sheets.invaders[i] = graphics.newImageSheet(“images/sprite”…i…".png", sheetData )
end
sequences.normRun =
{
name = “normalRun”,
start = 1,
count = 2,
time = 1710,
loopCount = 0,
loopDirection = “forward”
}
end
return public
MAIN.LUA
function createInvader(xloc, yloc, row)
scene = display.newGroup()
if levelDrop > 350 then
levelDrop = 350
end
for j = 1, 5 do
for i = 1, 11 do
allEnemys[#allEnemys + 1] = enemys:new()
allEnemys[#allEnemys]:init(i * 60, j * 70 + levelDrop, j) spacing
allEnemys[#allEnemys]:start()
end
end
end
ENEMY.LUA
function enemys:new()
local group = {}
return setmetatable( group, enemys_mt )
end
function enemys:init(xloc, yloc, row )
self.image = display.newSprite(budSprites.sheets.invaders[row], budSprites.sequences.normRun)
self.image:setReferencePoint( CenterReferencePoint )
self.image.x = xloc
self.image.y = yloc
self.image.name = “enemy”
self.image:play()
end
–SCORE IN ENEMY.LUA–
local currentScore = getScores( )
currentScore = currentScore --JUST ADD THE VALUE HERE.e.g.+ myValue
setScores( currentScore )
end
[lua]
Also if anybody has worked out how to wrap code in nice tags do let me know, it dosnt work for me no more.