Hi!
Okey, so I have managed to make three sprite sheets which I am very happy about (everything is new to me, so every success is a big success for me).
The sprites are enemies that will spawn outside the right side of the screen and transition and disappear on the left. My code works, but I don’t know if it’s the right thing to do regarding performance etc.
if event.time - timeLastPlane \>= math.random(4000, 5000) then
-- Randomly position it on the top of the screen
stringHeight = math.random(20, 190)
require "sprite"
--Random nr
local r = math.random(1, 3);
local sheet
if r == 1 then
sheet = sprite.newSpriteSheet( "plane1.png", 226, 116 )
planexscale = 0.5
planeyscale = 0.5
thetime = 5000
elseif r == 2 then
sheet = sprite.newSpriteSheet( "plane2.png", 201, 95 )
planexscale = 0.5
planeyscale = 0.5
thetime = 5000
elseif r == 3 then
sheet = sprite.newSpriteSheet( "plane3.png", 225, 125 )
planexscale = 0.3
planeyscale = 0.3
thetime = 4000
end
local spriteSet = sprite.newSpriteSet(sheet, 1, 4)
sprite.add( spriteSet, "plane", 1, 4, 200, 0 )
local instance = sprite.newSprite( spriteSet )
instance.x = 520
instance.y = stringHeight
instance.xScale = planexscale
instance.yScale = planeyscale
instance:prepare("plane")
instance:play()
instance.name = "plane"
physics.addBody(instance, "kinematic")
transition.to( instance, { time=thetime, alpha=1, x=-420, y=stringHeight, onComplete = function(self) self.parent:remove(self); self = nil; end } )
enemiesLayer:insert(instance)
timeLastPlane = event.time-1500
end
Any feedback would be appreciated!
Best regards,
joelwe [import]uid: 54640 topic_id: 9813 reply_id: 309813[/import]