Hi all,
I’m making a game where I have enemies spawn and rotate around a point in the centre of the screen. In order to do this I set the x and y of the sprite to the middle of the screen, then change the yReference to offset to the desired distance. I then have a function that rotates them. I change the offset so I can have layers of these rotating enemies. In the middle is the player, who must hit the rotating enemies.
The problem I have is that the sprite does not detect hits. I narrowed it down to being a problem with the yReference changing. I did a small test where the yReference is at the default 0 (so no offset). All works fine. As soon as I change it, to say a yReference of 50, the collision doesn’t align with the sprite. The collision is still at 0.
I’ve posted some code to help clarify things
[code]local imgTable = {
[1] = 220,
[2] = 290,
[3] = 360,
[4] = 430
}
function createInvader(num)
invaderGroup = display.newGroup()
local invaderSheet = sprite.newSpriteSheet(“Assets/Gfx/invaders.png”, 64, 64)
local invaderSpriteSet = sprite.newSpriteSet(invaderSheet, 1, 4)
local invader = sprite.newSprite(invaderSpriteSet)
invader.name = “invader”
invader:scale(0.8, 0.8)
invader.currentFrame = num
invader.yReference = imgTable[num]
invader.rotation = mRand(360)
invader.x = _W*0.5 invader.y = _H*0.5
physics.addBody(invader, “kinematic”, {radius=24})
local function rotate(event)
if num == 1 then
invader.rotation = invader.rotation+1
elseif num == 2 then
invader.rotation = invader.rotation-1.25
elseif num == 3 then
invader.rotation = invader.rotation+1.5
elseif num == 4 then
invader.rotation = invader.rotation-1.75
end
end
Runtime:addEventListener(“enterFrame”, rotate)
return invader
end
[/code]
Does anybody have any suggestions on how to fix this, either a different way to do this, or just something I’m forgetting to do?
Hope somebody can help. [import]uid: 88980 topic_id: 27783 reply_id: 327783[/import]