It looks like you're new here. If you want to get involved, click one of these buttons!
Player = Core.class(Sprite) function Player:init(x, y) self.sprite = Bitmap.new(atlas:getTextureRegion("player.png")) self.sprite:setAnchorPoint(0.5, 0.5) self.sprite:setPosition(x, y) self:addChild(self.sprite) stage:addChild(self) end |
Scene1:Player = Core.class(Sprite) |
Comments
Likes: Ninjadoodle
Does this mean that I can create ...
Scene1.Player=Core.class(Sprite)
Scene2.Player=Core.class(Sprite)
without conflicting?
Thanks again!
Likes: Ninjadoodle, antix
Likes: pie, Ninjadoodle
Thank you for the tip Is there any benefit / performance increase by doing this - or any disadvantage in using sprites for single bitmaps?
Likes: Ninjadoodle
In your example one could still say Scene1.player = Core.class(Bitmap)
That doesn't mean player is a child of Scene1.
You would still have to call Scene1:addChild(Scene1.player) in order for the Bitmap/Sprite/whatever to show up.
Storing the player-object in the Scene vs. in global scope is purely a matter of how you want to call it and if you want to have one player for each scene, and possibly multiple scenes/players active at the same time.
@Ninjadoodle could you supply some more information on what you're trying to do? Because your request may or may not make sense. Usually you would only create one player object and add it to different scenes once they show up.
1. Create a Sprite, then attach a Bitmap to that Sprite, and finally add the Sprite to your scene.
2. Create a Bitmap and add that to your scene.
So my whole point was that just creating a Bitmap is more efficient than first creating a Sprite and then a Bitmap to represent a game entity. I hope that's clearer
Thank for the reply
What you described is exactly what I was looking at doing. Many scenes (mini games) which might all have a Player object.
I was wondering what the best practice is.
I could simply do ...
PlayerScene1 = Core.class(Sprite)
PlayerScene2 = Core.class(Sprite)
and so on ...
I however wasn't sure if there is another way that's commonly used to deal with this case.
Thanks again
PLAYER = Player.new()
Then in your scene you can cache the player and then add it to the scene
Thank you for the tip! I will just go with the global setup it seems like its the simplest, and to be honest I think I'm overcomplicating things
Likes: antix, Ninjadoodle, Apollo14
Likes: Ninjadoodle
Likes: totebo