XNA -- Setting Position for an Array of Sprites per Index -


i'm having problem setting position , subsequently drawing individual elements within array of sprites. have no issue standalone sprites, i'm getting tripped on array.

simple example illustrate problem, real code proper, same concept --

myvar[0]=myimg; myvar[0].position.x=300; myvar[0].position.y=300; myvar[1]=myimg; myvar[1].position.x=400; myvar[1].position.y=400; 

if go draw these, myvar[1] @ 400 painted because myvar[0] has taken same position. problem when same image used in multiple elements. drawing 20x20 grid array using 5 different tile images, naturally there re-used.

is sprite array capable of having per index position...? can around in way?

i able sidestep earlier on looping through , setting position subsequently drawing per index, need take calculations in function based on position, , position same elements

cheers & help! :)

the problem here referencing 1 object multiple times.

myvar[0] , myvar[1] pointing same memory location. want create new sprite every entry.

for (int = 0; < myvar.length; i++) {   myvar[i] = new sprite(<your img>);//this ensure have different                                      //memory location each sprite object                                      //but keep same image. } 

then can modify positions accordingly.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -