local function spawnEnemy() enemies[#enemies + 1] = display.newImage("images/enemy1.png") enemy = enemies[#enemies]; enemy:setReferencePoint(display.CenterReferencePoint); enemy.x, enemy.y = random(\_W + 200, \_W\*2), ground.y - ground.height\*0.5; enemy.hPoints = 5; --health points enemy.scorePoints = 100; enemy.name = "enemy"; physics.addBody(enemy); enemy:setSequence("walking"); enemy:play(); localGroup:insert(enemy); function spawnAttack() attackTable[#attackTable + 1] = display.newImage("images/attack.png"); attack = attackTable[#attackTable]; attack:setReferencePoint(display.CenterReferencePoint); attack.x, attack.y = player.x + 100, enemy.y; physics.addBody(attack); attack.name = "attack"; localGroup:insert(attack); local playerXDist = player.x - attack.x; attack:setLinearVelocity(-playerXDist/2, 0); end enemy.trans = transition.to(enemy, {time = 5000, x = player.x + 100, onComplete = spawnAttack}) end
Then, after creating the spawnEnemy function, I set up a timer like this:
timer.performWithDelay(3000, spawnEnemy, 2);
Results: the first enemy comes to the position player.x + 100, and stops, but DO NOT toss an “attack” object as it’s supposed to do; the second enemy comes to the position, and DO toss an “attack” object.
So… what’s wrong with my code, folks?
Thank you.
Thank you, dude.