Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - qwerty

Pages: [1]
1
DotNet / Re: detect if mouse is at colored area of a sprite
« on: December 12, 2022, 04:22:38 pm »
Are you just showing what you've achieved or do you have a question and forgot to actually ask it? :D

the last part of my topic is the problem itself.

2
DotNet / detect if mouse is at colored area of a sprite
« on: December 11, 2022, 07:33:52 am »
for example, I have this sprite:

https://imgur.com/UOl0DVN

I need this for drag the sprite only from that area, but I'll take care of that.

This is my code:

Quote
piece.cs
using System;
using System.Collections.Generic;
using SFML.Graphics;

namespace puzzlegame
{
        public class piece:Sprite
        {
                Texture txtr;
                public bool is_mOver,is_mReleased;
                public List<string> lst_pos = new List<string>();
               
                public piece()
                {
                }
               
                public void setTexture(int num){
                        string path="";
                       
                        if(num==1)
                                path=@"E:\puzzle_game\shape1.png";
                        if(num==2)
                                path=@"E:\puzzle_game\shape2.png";
                        if(num==3)
                                path=@"E:\puzzle_game\shape3.png";
                        if(num==4)
                                path=@"E:\puzzle_game\shape4.png";
                        if(num==5)
                                path=@"E:\puzzle_game\shape5.png";
                       
                        txtr = new Texture(path);
                        this.Texture = txtr;
                }
               
                public void checkColoredArea(int mx,int my){
                        int px,py;
                        int charPos,sz;
                        for(int i=0;i<lst_pos.Count;i++){                      
                                charPos=lst_pos[i].IndexOf(":");
                                sz=lst_pos[i].Length;
                                px=int.Parse(lst_pos[i].Substring(0,sz-(sz-charPos)));
                                py=int.Parse(lst_pos[i].Substring(charPos+1,sz-(charPos+1)));
                               
                                if(mx==px && my==py){
                                        is_mOver=true;
                                        Console.WriteLine("it's over shape");
                                }
                                else{
                                        is_mOver=false;
                                }
                        }
                }
               
                public void fillPosxy(){
                        Color colortmp;
                        Image img = this.txtr.CopyToImage();
                        for(int i=0;i<txtr.Size.X;i++){
                                for(int j=0;j<txtr.Size.Y;j++){
                                        colortmp=img.GetPixel((uint)j,(uint)i);
                                        string pos = (j+this.Position.X)+":"+(i+this.Position.Y);
                                       
                                        if(colortmp.A!=0){
                                                //Console.WriteLine(pos);
                                                lst_pos.Add(pos);
                                        }
                                }
                        }
                        Console.WriteLine("lst_pos: "+lst_pos.Count);
                }
        }
}

Quote
Program.cs
using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;
using System.Collections.Generic;
using SFML.System;

namespace puzzlegame
{
        class Program
        {
                public static bool is_r,is_l,is_u,is_d,is_e,is_i;
                public static RenderWindow rw;
                public static float velx,vely;
                public static Vector2i mouse;
                public static bool idle_der=true,idle_izq;
                public static bool isReleased;
                public static List<piece> lst_piece1 = new List<piece>(5);
               
                public static void Main(string[] args)
                {
                        rw = new RenderWindow(new VideoMode(850,650),"puzzle");
                        rw.SetActive(true);
                        rw.SetVerticalSyncEnabled(true);
                        rw.SetFramerateLimit(60);
                       
                        rw.KeyPressed += OnKeyPressed;
                        rw.KeyReleased += OnKeyReleased;
                        rw.MouseMoved += OnMouseMoved;
                        rw.MouseButtonPressed += OnMouseButtonPressed;
                        rw.MouseButtonReleased += OnMouseButtonReleased;
                       
                        Clock clck = new Clock();
                        Time timeSinceLastUpdate=Time.Zero;
                        Time timePerFrame=Time.FromSeconds(1.0f/60.0f);
                        loadPiece();
                        lst_piece1[0].fillPosxy();
                       
                        while(rw.IsOpen==true){
                                Time elapsedTime = clck.Restart();
                                timeSinceLastUpdate+=elapsedTime;
                                while(timeSinceLastUpdate>timePerFrame)
                                {
                                        timeSinceLastUpdate-=timePerFrame;
                                        rw.DispatchEvents();
                                        update(timePerFrame);
                                }
                                draw();
                        }
                }
               
                static void update(Time deltatime){
                        if(is_r){
                                velx = 1f;
                        }
                        if(is_l){
                                velx = -1f;
                        }
                        if(is_u){
                                vely = -1f;
                        }
                        if(is_d){
                                vely = 1f;
                        }
                       
                        lst_piece1[0].checkColoredArea(mouse.X,mouse.Y);
                        rw.SetTitle("is_mOver: "+lst_piece1[0].is_mOver+" | mx: "+mouse.X+", my: "+mouse.Y+" | colored pixels: "+lst_piece1[0].lst_pos.Count);
                }
               
                static void draw(){
                        rw.Clear(Color.Cyan);
                        for(int i=0;i</*lst_piece1.Count*/1;i++)
                                rw.Draw(lst_piece1[i]);
                        rw.Display();
                }
               
                static void OnMouseMoved(object sender, MouseMoveEventArgs e){
                        mouse = Mouse.GetPosition(rw);                 
                }
               
                static void OnMouseButtonPressed(object sender, MouseButtonEventArgs e){
                        if(e.Button == Mouse.Button.Left){
                                isReleased = false;
                        }
                }
               
                static void OnMouseButtonReleased(object sender, MouseButtonEventArgs e){
                        if(e.Button == Mouse.Button.Left){
                                isReleased = true;
                        }
                }
               
                static void OnKeyReleased(object sender, KeyEventArgs e){
                        if(e.Code == Keyboard.Key.Right){
                                is_r=false;
                               
                                velx=0f;
                               
                                idle_der=true;
                                idle_izq=false;
                        }
                        if(e.Code == Keyboard.Key.Left){
                                is_l=false;
                               
                                velx=0f;
                               
                                idle_izq=true;
                                idle_der=false;
                        }
                        if(e.Code == Keyboard.Key.Up){
                                is_u=false;
                               
                                vely=0f;
                        }
                        if(e.Code == Keyboard.Key.Down){
                                is_d=false;
                               
                                vely=0f;
                        }
                        if(e.Code == Keyboard.Key.Space)
                                is_e=false;
                        if(e.Code == Keyboard.Key.I){
                                is_i=false;
                        }
                }
                static void OnKeyPressed(object sender, KeyEventArgs e){
                        if(e.Code == Keyboard.Key.Right){
                                is_r=true;
                               
                                is_l=false;
                                idle_der=false;
                                idle_izq=false;
                        }
                        if(e.Code == Keyboard.Key.Left){
                                is_l=true;
                               
                                is_r=false;
                                idle_der=false;
                                idle_izq=false;
                        }
                        if(e.Code == Keyboard.Key.Up)
                                is_u=true;
                        if(e.Code == Keyboard.Key.Down)
                                is_d=true;
                        if(e.Code == Keyboard.Key.Escape)
                                Environment.Exit(0);
                        if(e.Code == Keyboard.Key.Space)
                                is_e=true;
                        if(e.Code == Keyboard.Key.I){
                                is_i=true;
                        }
                }
               
                static void loadPiece(){
                        for(int i=0;i<5;i++){
                                piece pz = new piece();
                                pz.Position = new Vector2f(550,90);
                                pz.setTexture(i+1);
                                lst_piece1.Add(pz);
                        }
                }
        }
}
 

when the cursor enters the colored area prints a message to console, but "is_mOver" variable of sprite always figure as false at window title. here's a video for better explanation:
https://imgur.com/a/bx8jv8l

3
this is my code:

using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.System;
using SFML.Window;
using System.Collections.Generic;

namespace salto_grnd_pltfrm
{
        class Program
        {
                public static RenderWindow rw;
                public static Texture txtr_bgrnd;
                public static Texture txtr_grnd;
                public static Texture txtr_wall;
                public static Texture txtr_plyr;
                public static Texture txtr_coin;
                public static Texture txtr_fire;
                public static Texture txtr_robot;
                public static Sprite sprt_bgrnd;
                public static Sprite sprt_grnd;
                public static Sprite sprt_wall;
                public static Sprite sprt_plyr;
                public static Sprite sprt_coin;
                public static Sprite sprt_robot;
                public static Platform[] arr_pltfrm = new Platform[3];
                public static bool is_r=false,is_l=false,is_u,is_d,is_spc,is_grnd,is_pltfrm,is_jump;
                public static float velx=0.0f,vely=0.0f;
                public static float jumpheight = -300.0f, gravity=-400.0f;
                public static float piy,piy2;
                public static float piy_d;
                public static bool canJump;
                public static int acum=0;
                public static Clock tmpcl;
                public static float vida=0.0f;
                public static bool isVida=false;
                public static bool isUpdate=true;
                public static bool mouseOverBtn=false, isClick=false, isReleased=false;
                public static Clock cl,clck_shoot;
                public static Time elapsedTime2;
                public static bool idle_der=true,idle_izq=false,is_ctrl;
                public static bool tmp_area=false,isBack=false;
                public static Texture t1,t2,t3,t4,t5,t6;
                public static string r1=@"E:\sprites\player_idle_r.png";
                public static string r2=@"E:\sprites\player_anim_r.png";
                public static string r3=@"E:\sprites\player_idle_l.png";
                public static string r4=@"E:\sprites\player_anim_l.png";
                public static string r5=@"E:\sprites\enemy_anim_r.png";
                public static string r6=@"E:\sprites\enemy_anim_l.png";
                public static string r7="";
                public static string r8="";
                public static Player player;
                public static List<EnemySpawn> arr_misil = new List<EnemySpawn>(10);
               
                public static void Main(string[] args)
                {
                        rw = new RenderWindow(new VideoMode(700,500),"tipos de salto...");
                        rw.SetActive(true);
                        bool estado=rw.IsOpen();
                        rw.SetKeyRepeatEnabled(false);
                        rw.SetFramerateLimit(60);
                       
                        txtr_bgrnd = new Texture(@"C:\sprites\bckgrnd.jpg");
                        sprt_bgrnd = new Sprite(txtr_bgrnd);
                        sprt_bgrnd.Position = new SFML.Window.Vector2f(0.0f,0.0f);
                        txtr_grnd = new Texture(@"C:\sprites\ground.jpg");
                        sprt_grnd = new Sprite(txtr_grnd);
                        sprt_grnd.Position = new SFML.Window.Vector2f(200.0f,400.0f);
                        txtr_wall = new Texture(@"C:\sprites\pltfrm_0_rect_slm.png");
                        sprt_wall = new Sprite(txtr_wall);
                        sprt_wall.Position = new SFML.Window.Vector2f(300.0f,300.0f);
                        txtr_plyr = new Texture(@"C:\sprites\Sprite-0002.png");
                        sprt_plyr = new Sprite(txtr_plyr);
                        sprt_plyr.Position = new SFML.Window.Vector2f(190,400-sprt_plyr.TextureRect.Height);
                        txtr_coin = new Texture(@"C:\sprites\coin_3030.png");
                        sprt_coin = new Sprite(txtr_coin);
                        sprt_coin.Position = new SFML.Window.Vector2f(sprt_wall.Position.X+(sprt_wall.TextureRect.Width/2),sprt_wall.Position.Y-sprt_coin.TextureRect.Height);
                        txtr_fire = new Texture(@"C:\sprites\fire_enemy.png");
                        txtr_robot = new Texture(@"C:\sprites\monster.png");
                        sprt_robot = new Sprite(txtr_robot);
                        sprt_robot.Position = new SFML.Window.Vector2f(530.0f,sprt_grnd.Position.Y-sprt_robot.TextureRect.Height);
                       
                        piy_d=300-sprt_plyr.TextureRect.Height;        
               
                        Clock clck = new Clock();
                        Time timeSinceLastUpdate = Time.Zero;
                        Time timePerFrame = Time.FromSeconds(1.0f/60.0f);
                       
                        tmpcl = new Clock();
                        clck_shoot = new Clock();
                        elapsedTime2=new Time();
                        cl=new Clock();
                       
                        rw.KeyPressed+= OnKeyPressed;
                        rw.KeyReleased+= OnKeyReleased;
                       
                        t1 = new Texture(r1);
                        t2 = new Texture(r2);
                        t3 = new Texture(r3);
                        t4 = new Texture(r4);
                       
                        t5 = new Texture(r5);
                        t6 = new Texture(r6);
                        player = new Player();
                        player.setTexture2(t1);
                        piy=400-player.TextureRect.Height;
                        piy2=sprt_grnd.TextureRect.Height+player.TextureRect.Height;
                        player.setPosition(300f,sprt_grnd.Position.Y-player.TextureRect.Height);
                       
                        createPlatform();
                       
                        while(estado==true)
                        {
                                Time elapsedTime = clck.Restart();
                        timeSinceLastUpdate += elapsedTime;
                                while(timeSinceLastUpdate>timePerFrame)
                                {
                                        timeSinceLastUpdate-=timePerFrame;
                                        rw.DispatchEvents();
                                        if(isUpdate==true || isReleased==true)
                                                update3(timePerFrame);
                                }
                                render();
                               
                        rw.SetTitle(" plyrY: "+player.Position.Y+" pPosy: "+player.posy+" pltfrmd "+is_pltfrm+" canjump "+canJump+" grndY "+sprt_grnd.Position.Y);
                        }
                }
               
                public static void update3(Time deltaTime)
                {
                        if(is_r)
                        {
                                player.moveR(deltaTime,1f);
                                idle_der=false;
                                idle_izq=false;
                        }
                        if(is_l)
                        {
                                player.moveL(deltaTime,1f);
                                idle_der=false;
                                idle_izq=false;
                        }
                       
                        player.setPosition(player.Position.X+player.posx,player.Position.Y+player.posy);
                        ManageJump(deltaTime);
                }
               
                public static void render()
                {      
                        rw.Clear(Color.White);
                        rw.Draw(sprt_bgrnd);
                        rw.Draw(sprt_grnd);
                        rw.Draw(sprt_wall);
                        if(sprt_coin!=null)
                                rw.Draw(sprt_coin);
                       
                        if(is_r==true && is_l==false){
                                player.Texture = t2;
                        }
                        if(is_l==true && is_r==false){
                                player.Texture = t4;
                        }
                       
                        if(idle_der==true){
                                player.Texture = t1;
                        }
                        if(idle_izq==true){
                                player.Texture = t3;
                        }
                       
                        rw.Draw(player);
                        loadPlatform();
                        rw.Display();
                }
               
                static void createPlatform(){
                        Random r = new Random();
                        Platform p = new Platform();
                       
                        for(int i=0;i<arr_pltfrm.Length;i++){
                        arr_pltfrm[i] = new Platform();
                                arr_pltfrm[i].setTexture(txtr_wall);
                        }
                       
                        arr_pltfrm[0].Position = new SFML.Window.Vector2f(470f,280f);
                        arr_pltfrm[1].Position = new SFML.Window.Vector2f(400f,175f);
                        arr_pltfrm[2].Position = new SFML.Window.Vector2f(500f,75f);
                }
               
                static void loadPlatform(){
                        for(int i=0;i<arr_pltfrm.Length;i++)
                        {
                                rw.Draw(arr_pltfrm[i]);
                        }
                }
               
                static void OnKeyPressed(object sender, KeyEventArgs e)
                {
                        if(e.Code == Keyboard.Key.Right)
                        {
                                is_r=true;
                                is_l=false;
                                idle_der=false;
                                idle_izq=false;
                        }
                        if(e.Code == Keyboard.Key.Left)
                        {
                                is_l=true;                     
                                is_r=false;
                                idle_izq=false;
                                idle_der=false;
                        }
                        if(e.Code == Keyboard.Key.Up)
                        {
                                is_u=true;
                        }
                        if(e.Code == Keyboard.Key.Space)
                        {
                                is_spc=true;
                        }
                        if(e.Code == Keyboard.Key.Escape)
                        {
                                Environment.Exit(0);
                        }
                        if(e.Code == Keyboard.Key.LControl){
                                is_ctrl=true;
                        }
                }
               
                static void OnKeyReleased(object sender, KeyEventArgs e)
                {
                        if(e.Code == Keyboard.Key.Right)
                        {
                                is_r=false;
                                player.posx=0.0f;
                                idle_der=true;
                                idle_izq=false;
                        }
                        if(e.Code == Keyboard.Key.Left)
                        {
                                is_l=false;
                                player.posx=0.0f;
                                idle_izq=true;
                                idle_der=false;
                        }
                        if(e.Code == Keyboard.Key.Up)
                        {
                                is_u=false;
                        }
                        if(e.Code == Keyboard.Key.Space)
                        {
                                is_spc=false;
                        }
                        if(e.Code == Keyboard.Key.LControl){
                                is_ctrl=false;
                        }
                }
               
                public static bool grounded()
                {
                        if(player.Position.Y+player.TextureRect.Height>=sprt_grnd.Position.Y && player.Position.X+player.TextureRect.Width>=sprt_grnd.Position.X)
                        {
                                player.Position=new SFML.Window.Vector2f(player.Position.X,piy);
                                player.posy=0.0f;
                                is_grnd=true;
                                is_pltfrm=false;
                        }
                        else
                        {
                                is_grnd=false;
                        }
                        return is_grnd;
                }
               
                public static bool pltfrmd()
                {
                        for(int i=0;i<arr_pltfrm.Length;i++){
                                if((player.Position.Y+player.TextureRect.Height>arr_pltfrm[i].Position.Y && player.Position.Y+player.TextureRect.Height<arr_pltfrm[i].Position.Y+arr_pltfrm[i].TextureRect.Height ) && (player.Position.X+player.TextureRect.Width>arr_pltfrm[i].Position.X && player.Position.X<arr_pltfrm[i].Position.X+arr_pltfrm[i].TextureRect.Width))
                                {
                                        player.Position = new SFML.Window.Vector2f(player.Position.X,arr_pltfrm[i].Position.Y-player.TextureRect.Height);
                                        player.posy=0.0f;
                                        is_pltfrm=true;
                                        is_grnd=false;
                                }
                        }
                        return is_pltfrm;
                }
               
                static void ManageJump(Time deltaTime){
                        if(grounded()==true || pltfrmd()==true){
                canJump=true;
                }
                       
                for(int i=0;i<arr_pltfrm.Length;i++){
                        if((is_u==true && canJump && player.Position.Y > sprt_grnd.Position.Y-150f) || (is_u==true && canJump && player.Position.Y > arr_pltfrm[i].Position.Y-150f)){
                        player.posy-=30.0f*deltaTime.AsSeconds();
                        is_pltfrm=false;
                        }
                        else{
                        canJump=false;
                        if((player.Position.Y <= sprt_grnd.Position.Y-150f) || (player.Position.Y <= arr_pltfrm[i].Position.Y-150f)){
                            player.posy++;
                        }
                        player.posy++;
                        }
                }
        }
        }
}
 

When the character jumps from ground it does higher than if jumps from platform. My approach is a constant jump height, but I'm stuck :/

EDIT: I change this:
player.Position.Y > arr_pltfrm.Position.Y-150f
to this:
player.Position.Y > arr_pltfrm.Position.Y-210f

This should work and the player when jumps while i'ts on platform should jump higher than if it's on ground, but the result is the same.

for(int i=0;i<arr_pltfrm.Length;i++){
                        if((is_u==true && canJump && player.Position.Y > sprt_grnd.Position.Y-150f) || (is_u==true && canJump && player.Position.Y > arr_pltfrm[i].Position.Y-210f)){
                        player.posy-=30.0f*deltaTime.AsSeconds();
                        is_pltfrm=false;
                        }
                        else{
                        canJump=false;
                        if((player.Position.Y <= sprt_grnd.Position.Y-150f) || (player.Position.Y <= arr_pltfrm[i].Position.Y-210f)){
                            player.posy++;
                        }
                        player.posy++;
                        }
                }
        }
 

Here's a video that can provide more info:
https://vimeo.com/630581663

*Finally I solved that adding a global variable and set different values in grounded() and pltfrmd() methods:
public static float jumpheight;

public static bool grounded()
                {
                        if(player.Position.Y+player.TextureRect.Height>=sprt_grnd.Position.Y && player.Position.X+player.TextureRect.Width>=sprt_grnd.Position.X)
                        {
                                player.Position=new SFML.Window.Vector2f(player.Position.X,piy);
                                player.posy=0.0f;
                                is_grnd=true;
                                is_pltfrm=false;
                                jumpheight=-17f;
                        }
                        else
                        {
                                is_grnd=false;
                        }
                        return is_grnd;
                }

public static bool pltfrmd()
                {
                        for(int i=0;i<arr_pltfrm.Length;i++){
                                if((player.Position.Y+player.TextureRect.Height>arr_pltfrm[i].Position.Y && player.Position.Y+player.TextureRect.Height<arr_pltfrm[i].Position.Y+arr_pltfrm[i].TextureRect.Height ) && (player.Position.X+player.TextureRect.Width>arr_pltfrm[i].Position.X && player.Position.X<arr_pltfrm[i].Position.X+arr_pltfrm[i].TextureRect.Width))
                                {
                                        player.Position = new SFML.Window.Vector2f(player.Position.X,arr_pltfrm[i].Position.Y-player.TextureRect.Height);
                                        player.posy=0.0f;
                                        is_pltfrm=true;
                                        is_grnd=false;
                                        jumpheight=-20f;
                                }
                        }
                        return is_pltfrm;
                }

static void ManageJump(Time deltaTime){
                        if(grounded()==true || pltfrmd()==true){
                canJump=true;
                }
                       
                for(int i=0;i<arr_pltfrm.Length;i++){
                        if((is_u==true && canJump && player.posy > jumpheight)){
                        player.posy-=30.0f*deltaTime.AsSeconds();
                        is_pltfrm=false;
                        }
                        else{
                        canJump=false;
                        if((player.posy <= jumpheight)){
                            player.posy++;
                        }
                        player.posy++;
                        }
                }
        }
 

Please, mark this question as solved :)

4
Hi all, for example each 5 seconds, a enemy will spawn at random position, after another 5 seconds a new enemy will spawn at random position, but without the previous one change their position, and so on.

This is my code:
using System;
using System.Collections.Generic;
using SFML.Graphics;
using SFML.System;
using SFML.Window;

namespace sfml_array_sprites
{
        class Program
        {
                public static RenderWindow rw;
                public static Clock tmpcl;
                public static List<Sprite> lst_sprt;
                public static Texture txtr;
                public static Random rndm;
                public static int l_size=0;
                public static List<float> lst_posx;
                public static List<float> lst_posy;
               
                public static void Main(string[] args)
                {
                        rndm = new Random();
                        rw = new RenderWindow(new VideoMode(700,500),"...");
                        rw.SetActive(true);
                        bool state=rw.IsOpen();
                        txtr = new Texture(@"c:\assets\player.png");
                       
                        Clock clck = new Clock();
                        Time timeSinceLastUpdate=Time.Zero;
                        Time timePerFrame=Time.FromSeconds(1.0f/60.0f);
                        tmpcl = new Clock();
                       
                        lst_sprt=new List<Sprite>();
                        lst_posx = new List<float>();
                        lst_posy = new List<float>();
                                               
                        while(state==true)
                        {
                                timeSinceLastUpdate+=clck.Restart();
                               
                                while(timeSinceLastUpdate>timePerFrame)
                                {
                                        timeSinceLastUpdate-=timePerFrame;
                                        update(timePerFrame);
                                }
                                render();
                        }
                }
                public static void update(Time deltaTime)
                {
                        if(tmpcl.ElapsedTime.AsSeconds()>4.0f)
                        {
                                spawnEnemy();
                                l_size+=1;
                                tmpcl.Restart();
                        }
                }
               
                public static void render()
                {
                        rw.Clear(Color.White);
                        rw.DispatchEvents();
                        for(int p=0;p<lst_sprt.Count;p++)
                        {
                                rw.Draw(lst_sprt[p]);
                        }
                        rw.Display();
                }
               
                public static void spawnEnemy()
                {
                        Sprite obj;
                        lst_sprt = new List<Sprite>(l_size);
                        lst_posx = new List<float>(l_size);
                        lst_posy = new List<float>(l_size);
                       
                        for(int dd=0;dd<lst_posx.Capacity;dd++)
                        {
                                lst_posx.Add((float)Rndm_pX());
                                lst_posy.Add((float)Rndm_pY());
                        }
                                               
                        for(int u=0;u<lst_sprt.Capacity;u++)
                        {
                                obj = new Sprite(txtr);
                                lst_sprt.Add(obj);
                                lst_sprt[u].Scale = new SFML.Window.Vector2f(0.5f,0.5f);
                                lst_sprt[u].Position=new SFML.Window.Vector2f(lst_posx[u],lst_posy[u]);
                        }
                }
               
                public static int Rndm_pX()
                {
                        return rndm.Next(0,625);
                }
                public static int Rndm_pY()
                {
                        return rndm.Next(0,404);
                }
        }
}
 

If I comment these lines I get an NullReferenceException:
lst_sprt=new List<Sprite>();
lst_posx = new List<float>();
lst_posy = new List<float>();
 

I am aware that after resetting the clock a new position will be generated for each sprite. I do not know how to prevent that from happening, neither do I know where in the code that method should be implemented. That's why I need your help.
P.S. I do not know if it is allowed to upload videos from a specific platform, but here is the video:
https://vimeo.com/259498754

Thanks, problem solved ^^
The new spawnEnemy code:

Sprite obj=new Sprite(txtr);
rndm=new Random();
obj.Position=new SFML.Window.Vector2f((float)rndm.Next(0,500),(float)rndm.Next(0,700));
lst_sprt.Add(obj);

https://vimeo.com/260712715

Pages: [1]