General Question about game layers and display groups

Hi,

I load a sprite (dudeRiding) and insert it to one of my layers called topLayer:

local topLayer = display.newGroup()  
gameLayer:insert(topLayer)  
local preload = require("preload")  
local ridingSprites = preload.createRidingSprites()  
local dudeRiding  
  
local function ride(mySprite)  
 dudeRiding = mySprite;  
  
 if (dudeRiding)   
 dudeRiding.isVisible= true;  
 end  
  
 if topLayer.dudeRiding then  
 dudeRiding.parent:insert( dudeRiding )  
 else  
 topLayer:insert(dudeRiding)  
 end  
end  
  
local function main()  
...  
 ride(ridingSprites.kurtCamel)  
 ....  
 ride(ridingSprites.kurt)  
end  

for the first time when I call ride() it works fine but when I call the same function again and assign a new sprite to dudeRiding it dose not show dudeRiding on screen.

I tried to remove dudeRiding using removeself() and insert it to topLayer again but it gave me an error: bad argument #-2 to insert (proxy expected got nil). Please note dudeRiding is a global variable.

Any comment/solution would be appreciated.

Many thanks,
Arash

[import]uid: 80320 topic_id: 35295 reply_id: 335295[/import]

You can’t really change a display objects graphic after it’s created unfortunately.

The best way to do it is use sprite sheets, then when you want to use another graphic you just move to the next frame in the sprite sheet.

So your Kurt graphic and your Kurt Camel graphic would be 2 different images saved as 1 file, you load that as a sprite sheet and then you can flick between the 2 images using setSequence.

Dave [import]uid: 117617 topic_id: 35295 reply_id: 140311[/import]

You might take a look at http://developer.coronalabs.com/reference/index/movieclipnewanim

Cheers, [import]uid: 202223 topic_id: 35295 reply_id: 140366[/import]

I use to use Movie clip until I realised it doesn’t support graphic scaling.

It is easier to use that sprite sheets though.

Dave [import]uid: 117617 topic_id: 35295 reply_id: 140443[/import]

Thanks dave, used the sprite that fixed my problem. [import]uid: 80320 topic_id: 35295 reply_id: 140483[/import]

You can’t really change a display objects graphic after it’s created unfortunately.

The best way to do it is use sprite sheets, then when you want to use another graphic you just move to the next frame in the sprite sheet.

So your Kurt graphic and your Kurt Camel graphic would be 2 different images saved as 1 file, you load that as a sprite sheet and then you can flick between the 2 images using setSequence.

Dave [import]uid: 117617 topic_id: 35295 reply_id: 140311[/import]

You might take a look at http://developer.coronalabs.com/reference/index/movieclipnewanim

Cheers, [import]uid: 202223 topic_id: 35295 reply_id: 140366[/import]

I use to use Movie clip until I realised it doesn’t support graphic scaling.

It is easier to use that sprite sheets though.

Dave [import]uid: 117617 topic_id: 35295 reply_id: 140443[/import]

Thanks dave, used the sprite that fixed my problem. [import]uid: 80320 topic_id: 35295 reply_id: 140483[/import]