table transition group

 hi everybody,

i want to move my player and his head :slight_smile: this snippet works but i would like to move him in a single command.

is it possible to make a group of the player[1] ?

local player={} for i=1,5 do player[i]=display.newCircle(100,100,10) player[i].head=display.newCircle(100,80,5) end     transition.to(player[1],{time=700,x=400,y=300}) transition.to(player[1].head,{time=700,x=400,y=300})

Thanks

local player= display.newGroup() player.body = display.newCircle(player,0,0,10) player.head=display.newCircle(player,0,-20,5) player.x = 100 player.y = 100 transition.to(player,{time=700,x=400,y=300})

I didn’t understand why you had a loop, but lay all the players on top of each other, so I just guessed what you were doing with this change to my above code:

local player = {} for i = 1, 5 do local player= display.newGroup() player.body = display.newCircle(player,0,0,10) player.head=display.newCircle(player,0,-20,5) player.x = 100 + (i-1) \* 15 player.y = 100 players[i] = player end transition.to(players[1],{time=700,x=400,y=300}) transition.to(players[2],{time=700,x=500,y=300}) transition.to(players[3],{time=700,x=400,y=500})

hi Roaminggamer,

i would have a tank of player with multi-element.

In fact, i would have a player with physics and with a text above his head and the text follow the player.

With you code i have an error probably the “s” of player and the transition don’t work.

I have wrote an runtime to have the text that follow the player but it’s not fully good in term of performance. a group with table would be better…

local player = {} for i = 1, 5 do local player= display.newGroup() player.body = display.newCircle(player,0,0,10) player.head=display.newCircle(player,0,-20,5) player.x = 100 + (i-1) \* 15 player.y = 100 players[i] = player --player with S ? end transition.to(players[1],{time=700,x=400,y=300})--bug don't work transition.to(players[2],{time=700,x=500,y=300})--bug don't work transition.to(players[3],{time=700,x=400,y=500})--bug don't work

hi,

Finally, i have uhnderstood what you try to do and this snippet works.

Thanks for  your advice

local physics = require("physics") physics.start() for i = 1, 5 do     local players=display.newGroup()     player.body = display.newCircle(players,0,0,10)     player.head=display.newCircle(players,0,-20,5)     players.x = 100 + (i-1) \* 15        players.y = 200     player[i] = players end physics.addBody( player[2], { density=.5, friction=1, bounce=0.7,shape=pentagonShape } ) player[2]:applyForce( 80, 150, objectB.x, objectB.y )

 

You have an error in this code, assigning the body and head to player rather than players. Also remember to put ‘local player = {}’ at the top of your lua file, otherwise the player table will become global.

it’s noted, thanks.

local physics = require("physics") physics.start() local player={} for i = 1, 5 do     local players=display.newGroup()     players.body = display.newCircle(players,0,0,10)     players.head=display.newCircle(players,0,-20,5)     players.x = 100 + (i-1) \* 15        players.y = 200     player[i] = players end physics.addBody( player[2], { density=.5, friction=1, bounce=0.7,shape=pentagonShape } ) player[2]:applyForce( 80, 150, player[2].x, player[2].y ) player[2].isFixedRotation=true

hi, to come back with this, is it possible to delimit my contour’s player for the physics to only the body ? the head is with the body during the physics but the contour of interaction is only the body.

if i have one player that is above the player[2], those feet is on the body, the head don’t interact with this first player. hope it’s clear…

No, not the way you’re doing it.  I never add physics bodies to groups, only to tradition display objects.  So, I don’t know what to tell you about that technique.

However, there is a better way to achieve what you’re doing if the body will NOT rotate:

local physics = require("physics") physics.start() local players = {} for i = 1, 5 do local player = display.newCircle(100 + (i-1) \* 15,200,10) players[i] = player physics.addBody( player, { density=.5, friction=1, bounce=0.7,shape=pentagonShape } ) player.isFixedRotation = true player.head = display.newCircle(0,0,5) player.enterFrame = function( self ) if( self.removeSelf == nil or self.head.removeSelf == nil) Runtime:removeEventListener("enterFrame", self ) return end self.head.x = self.x self.head.y = self.y - 20 end Runtime:addEventListener("enterFrame", player ) end

Hi, i would know how to access a specific player with this code because

player[2]:setFillColor(1,0,0) doesn't work...

local physics = require("physics") physics.start() local player={} for i = 1, 5 do local players=display.newGroup() players.body = display.newCircle(players,0,0,10) players.head=display.newCircle(players,0,-20,5) players.x = 100 + (i-1) \* 15 players.y = 200 player[i] = players end physics.addBody( player[2], { density=.5, friction=1, bounce=0.7,shape=pentagonShape } ) player[2]:applyForce( 80, 150, player[2].x, player[2].y ) player[2].isFixedRotation=true

thanks if you could help me

Nobody for my previous question ?

hi espace3d,

i can’t help you…maybe start a new post ?

@espace3d,

Please do not hijack someone’s thread.  Start your own.  If you have a question that contributes to an ongoing discussion as posed by the original person that is fine.  If you’re looking for help for your own issue, that is not fine.

Adding your own new question because you think it is somehow related is (very) bad forums etiquette.

You shouldn’t get an answer as that only encourages this behavior.  Imagine a forum where everyone posted their questions into random threads… chaos.   :o

Please re-post your question as a new and detailed forums post with an appropriate tittle…

PS - If you think a discussion is partially relevant to your question, link to it in your new post and say “I think this discussion might be related, but I’m still confused/stuck”, just don’t hijack.

local player= display.newGroup() player.body = display.newCircle(player,0,0,10) player.head=display.newCircle(player,0,-20,5) player.x = 100 player.y = 100 transition.to(player,{time=700,x=400,y=300})

I didn’t understand why you had a loop, but lay all the players on top of each other, so I just guessed what you were doing with this change to my above code:

local player = {} for i = 1, 5 do local player= display.newGroup() player.body = display.newCircle(player,0,0,10) player.head=display.newCircle(player,0,-20,5) player.x = 100 + (i-1) \* 15 player.y = 100 players[i] = player end transition.to(players[1],{time=700,x=400,y=300}) transition.to(players[2],{time=700,x=500,y=300}) transition.to(players[3],{time=700,x=400,y=500})

hi Roaminggamer,

i would have a tank of player with multi-element.

In fact, i would have a player with physics and with a text above his head and the text follow the player.

With you code i have an error probably the “s” of player and the transition don’t work.

I have wrote an runtime to have the text that follow the player but it’s not fully good in term of performance. a group with table would be better…

local player = {} for i = 1, 5 do local player= display.newGroup() player.body = display.newCircle(player,0,0,10) player.head=display.newCircle(player,0,-20,5) player.x = 100 + (i-1) \* 15 player.y = 100 players[i] = player --player with S ? end transition.to(players[1],{time=700,x=400,y=300})--bug don't work transition.to(players[2],{time=700,x=500,y=300})--bug don't work transition.to(players[3],{time=700,x=400,y=500})--bug don't work

hi,

Finally, i have uhnderstood what you try to do and this snippet works.

Thanks for  your advice

local physics = require("physics") physics.start() for i = 1, 5 do     local players=display.newGroup()     player.body = display.newCircle(players,0,0,10)     player.head=display.newCircle(players,0,-20,5)     players.x = 100 + (i-1) \* 15        players.y = 200     player[i] = players end physics.addBody( player[2], { density=.5, friction=1, bounce=0.7,shape=pentagonShape } ) player[2]:applyForce( 80, 150, objectB.x, objectB.y )

 

You have an error in this code, assigning the body and head to player rather than players. Also remember to put ‘local player = {}’ at the top of your lua file, otherwise the player table will become global.

it’s noted, thanks.

local physics = require("physics") physics.start() local player={} for i = 1, 5 do     local players=display.newGroup()     players.body = display.newCircle(players,0,0,10)     players.head=display.newCircle(players,0,-20,5)     players.x = 100 + (i-1) \* 15        players.y = 200     player[i] = players end physics.addBody( player[2], { density=.5, friction=1, bounce=0.7,shape=pentagonShape } ) player[2]:applyForce( 80, 150, player[2].x, player[2].y ) player[2].isFixedRotation=true

hi, to come back with this, is it possible to delimit my contour’s player for the physics to only the body ? the head is with the body during the physics but the contour of interaction is only the body.

if i have one player that is above the player[2], those feet is on the body, the head don’t interact with this first player. hope it’s clear…