Not a problem just a sprite question

Discussion in 'Questions (Windows Mobile)' started by enonod, Jun 26, 2009.

  1. enonod

    enonod Well-Known Member Licensed User

    I am studying the Sprite sample, and would like to know if I am interpreting correctly.

    1. I notice that the 'added' sprites all have the same name 'Sprite', (an unfortunate choice?) and that they are not directly referred to again but have been preset.

    2. Also two empty sprites are used to take on the attributes of any two sprites that have collided and created an event.

    What I don't quite follow is, why...
    when a Sprite object is installed into the program from Add Object, why is this done for each required sprite?
    I would have expected to add Sprite once as an object and then instantiated each new sprite required, in my code i.e....
    add a sprite called 'Master' then
    Master.New1("mySpriteA")
    Master.New1("mySpriteB")
    mySpriteA.velocity=10
    mySpriteB.velocity=20
    It seems that I must add every instantiation from the Add Object menu or have I got it wrong?

    [Edit] In the instance of all these anonymous sprites that have been added above, if one DID want to suddenly refer to it, it would not seem possible because it doesn't have a name and there, as stated, doesn't seem to be a way to give it one (after the event?) [bad choice event] (after its creation.
     
    Last edited: Jun 26, 2009
  2. agraham

    agraham Expert Licensed User

    The added Sprites, spr1, spr2 and sprite are three different objects each of type Sprite. A Component is a library (dll) that you add to a project. It contains the descriptions of Classes (types) of objects, in this case Sprite amongst others. Each individual Object refers to a separate instance of a Class type, the actual instance being created by New. Objects can be created in the Designer or added at runtime by AddObject.

    It is confusing that a Sprite object in the demo is actually called "Sprite" which is also the name of the Class it belongs to. Unfortunately the Sprite library Sprite class behaviour is not quite the same as a "normal" library object because it is a wrapper of an existing game engine. For example Sprite.New2 actually creates a new instance of a Sprite object which is unusual for a library object and once that new Sprite is added to the game you can't identify it until it collides with something. So this is not a good example to start learn about libraries and objects in Basic4ppc.

    In this demo Sprite is used to create new Sprites to add to the game window and sppr1 and spr2 are used to access the colliding Sprite(s).

    That's the only way to access the properties of those Sprites. You can't get at them any other way.

    An object is an instance, not a class and you can't make multiple copies of it.
    Yes, or by AddObject at runtime.
     
  3. enonod

    enonod Well-Known Member Licensed User

    Thank you agraham that has clarified and crystallised matters.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice