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

Author Topic: Rectangle collision problem  (Read 19717 times)

0 Members and 1 Guest are viewing this topic.

cx3

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Rectangle collision problem
« on: March 16, 2015, 08:59:54 pm »
Hello :) I`ve been coding for about 20 hours ( xD ) and my brain does not work. I tried various combinations in detecting collisions... and none works. Below all code:

/**
 * @(#)GameFromScratch.java
 *
 * GameFromScratch application
 *
 * @author #cx3#
 * @version 1.00 2015/3/7
 */

 
import org.jsfml.graphics.RenderWindow;
import org.jsfml.graphics.Text;
import org.jsfml.graphics.*;
import org.jsfml.system.Clock;
import org.jsfml.system.Time;
import org.jsfml.window.VideoMode;
import org.jsfml.window.WindowStyle;
import org.jsfml.window.event.Event;
import org.jsfml.graphics.Color;
 
import org.jsfml.graphics.Font;
import org.jsfml.graphics.Texture;
import org.jsfml.graphics.Sprite;
import org.jsfml.system.*;

import org.jsfml.system.Time;
import org.jsfml.system.Vector2f;
import org.jsfml.window.Keyboard;
import org.jsfml.window.event.Event;

import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;

import java.io.*;
import java.io.FileInputStream;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import java.nio.file.Paths;
import java.nio.file.*;

import java.lang.Number;
import java.lang.Math;

import java.io.FileNotFoundException;
import java.util.Scanner;

import java.util.Arrays;

import java.lang.System;

/*
 * @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 */


enum KeybAction { left,right,up,down,none,esc };

enum SpriteType { PLAYER, ENEMY, FRUIT, BRICK, BACK };


class INFO
{
        public static String            MEDIA_DIR;
        public static Bricks            BRICKS;
        public static RenderWindow  GAMEWINDOW;
}


//################################################
//################################################


interface IGetSprites{  public Sprite[] getSprites();  }

interface IDrawRenderWindow{  public void draw(RenderWindow rw);  }

//################################################

 
class ImageLoader
{
        Texture texture = new Texture();
        Sprite  sprite  = new Sprite();
        Image   image   = new Image();
       
        SpriteType      spriteType;
       
        int x,y;
       
       
public
        ImageLoader(String spritePath, SpriteType  spriteType)
        {
                x=0; y=0;
               
                this.spriteType = spriteType;
               
                try
                {
                        texture.loadFromFile(Paths.get(spritePath));   
                        texture.setRepeated(true);
                       
                        sprite = new Sprite(texture);          
                        image  = texture.copyToImage();
                }
                catch  (Exception e)
                {
                        e.printStackTrace();
                }
        }
       
public
        ImageLoader(String spritePath, SpriteType  spriteType, int x, int y)
        {
                this(spritePath, spriteType);
               
                this.spriteType = spriteType;
                this.x = x;
                this.y = y;    
        }
       
       
        public Sprite  copySprite()
        {
                Texture tx = new Texture(texture);
                tx.setRepeated(true);
                return new Sprite(sprite.getTexture());
        }
       
       
        public Sprite  copySprite(int x, int y)
        {
                Sprite s = copySprite();
                s.setPosition(x,y);
                return s;
        }
       

        public void setX(int x){ this.x = x; }
        public void setY(int y){ this.y = y; }
       
        public void setXY(int x, int y){ setX(x); setY(y); }
       

        public Sprite  getSprite()
        {
                sprite.setPosition(x,y);
                return sprite;
        }
       
       
        public Sprite  getSprite(int x, int y)
        {
                sprite.setPosition(x,y);
                return sprite;
        }
       
               
        public Image       getImage(){   return image;   }
               
        public Texture     getTexture(){ return texture; }
       
        public SpriteType  getSpriteType(){ return spriteType; }
}


//################################################
//################################################


class SafeZone
{
        private static
                boolean isColliding //arglist
                (
                        Vector2f Ax1y1,
                        Vector2f Ax2y2,
                        Vector2f Bx1y1,
                        Vector2f Bx2y2
                )
                {//method`s body start:
                        float
                                widthA  = Math.abs(Ax1y1.x - Ax2y2.x),
                                widthB  = Math.abs(Bx1y1.x - Bx2y2.x),
                               
                                heightA = Math.abs(Ax1y1.y - Ax2y2.y),
                                heightB = Math.abs(Bx1y1.y - Bx2y2.y);
                               
                        if (
                                 (Math.abs(Ax1y1.x - Bx2y2.x) <= widthA + widthB)
                                                                        &&
                                  Math.abs(Ax1y1.y - Bx2y2.y) <= heightA + heightB
                                )      
                                return true;
                               
                        return false;
                }


public static
        boolean isColliding(Sprite A, Sprite B)
        {
                Vector2f
                        vA1 = A.getPosition(), vA2 = A.getOrigin(),
                        vB1 = B.getPosition(), vB2 = B.getOrigin();
                       
                float
                        vAdtx = vA2.x - vA1.x,
                    vAdty = vA2.y - vA1.y,
                   
                    vBdtx = vB2.x - vB1.x,
                    vBdty = vB2.y - vB1.y;
                   
               
                        vA2 = new Vector2f(vA1.x, vA1.x + 2*vAdtx);
                        vB2 = new Vector2f(vB1.x, vB1.x + 2*vBdtx);
               
                return isColliding(vA1, vA2, vB1, vB2);
        }
       
       
public static
        boolean isColliding(Sprite A, Sprite[] sprites)
        {
                for (Sprite sprite : sprites)
                        if (isColliding( sprite, A) == true ) return true;
                return false;
        }
}


//################################################
//################################################
 
class Bricks  implements  IGetSprites, IDrawRenderWindow
{
        ArrayList<Sprite>     bricks;
        //ArrayList<FloatRect>  rectangles;
       
        ImageLoader           image;
        Texture               texture;
       
public
        Bricks(ImageLoader  image, String mapFile)
        {
                this.image  = image;
                bricks          = new ArrayList<Sprite>();
                       
                loadMapFile(mapFile);
        }
       
       
        private void loadMapFile(String map)
        {
                Vector2i v = image.getTexture().getSize();
               
                try
                {
                        Scanner scanner = new Scanner( new File(map) );
                       
                        for (int x=0; x<7; ++x)
                        {
                                String line = scanner.nextLine();
                               
                                for (int y=0; y<7; ++y)
                                        if (line.charAt(y)!='.')
                                                bricks.add( image.copySprite( (1+x)*v.x,(1+y)*v.y) );
                                               
                        }
                        //rectangles = new ArrayList<FloatRect>();
                                               
                }
                catch(Exception e)
                {
                        e.printStackTrace();
                }
        }
       
       
       
        @Override
        public
                Sprite[]  getSprites()
                {
                        int s = bricks.size();
                        Sprite[] ret = new Sprite[s];
                       
                        for (int i=0; i<s; ++i) ret[i] = bricks.get(i);

                        return ret;    
                }
               
        @Override
        public
                void draw(RenderWindow  rw)
                {
                        for (Sprite sprite : bricks)  rw.draw(sprite);
                }
}
 
//################################################
//################################################

class FramedAnimation implements IGetSprites, IDrawRenderWindow
{
        ArrayList<ImageLoader>  frames;
       
        Clock                   clock;
       
        int                                     x, y, current, timePerFrame;
       
       
public
        FramedAnimation(String []imgFiles, SpriteType spriteType)
        {
                frames  = new ArrayList<ImageLoader>();
                current = 0;
               
                for (int i=0; i<imgFiles.length; ++i)
                        frames.add(new ImageLoader(imgFiles[i],spriteType) );
                       
                setTimePerFrame(1000);
        }
       
       
public
        FramedAnimation(String []imgFiles, SpriteType spriteType, int x, int y)
        {
                this(imgFiles, spriteType);
                this.setXY(x,y);
        }
       
public
        FramedAnimation(ArrayList<ImageLoader>  frames)
        {
                this.frames = frames;
                current = 0;
                setTimePerFrame(1000);
        }
       
               
        public void setTimePerFrame(int  msTimePerFrame)
        {
                if (clock == null) clock = new Clock();
                timePerFrame = msTimePerFrame;
                clock.restart();
        }
               
       
        public void setXY(int x, int y)
        {
                for (ImageLoader  image  :  frames)  image.setXY(x,y);
        }
       
       
        private void setFrame()
        {
                if (clock.getElapsedTime().asMilliseconds() >= timePerFrame)
                {
                        current++;
                        clock.restart();
                }
                if ( current >= frames.size() ) current = 0;
        }
       
       
        @Override    //IGetSprites
        public
                Sprite[]  getSprites()
                {
                        setFrame();
                       
                        Sprite sprite = frames.get(current).getSprite();
                        sprite.setPosition(x,y);
               
                        return new Sprite[]{ sprite };
                }
               
               
        @Override //IDrawRenderWindow
        public
                void draw(RenderWindow rw)
                {
                        for (Sprite sprite : getSprites()) rw.draw(sprite);
                }
}

//################################################
//################################################

class Background implements IGetSprites, IDrawRenderWindow
{
        FramedAnimation             frames;
        Vector2i                            vsize;
        Time                                    lastUpdate;
       
       
public
        Background(FramedAnimation  animation, int  msPerFrame)
        {
                frames = animation;
                frames.setTimePerFrame(msPerFrame);
        }
       
       
        @Override    //IGetSprites
        public
                Sprite[]  getSprites()
                {
                        Sprite []sprites = frames.getSprites();
                       
                        vsize = sprites[0].getTexture().getSize();
                       
                        ArrayList<Sprite>  background  =  new ArrayList<Sprite>();
                       
                        int index=0;
                       
                        for (int x=0;  x<800+vsize.x;  x+=vsize.x)
                                for (int y=0;  y<600+vsize.y;  y+=vsize.y)
                                {
                                        if (index == sprites.length-1) index=0; else index+=1;
                                       
                                        Sprite sp = new Sprite( sprites[index].getTexture() );
                                        sp.setPosition(x,y);
                                       
                                        background.add( sp );
                                }
                        return background.toArray( new Sprite[ background.size() ] );
                }
                       
                       
        @Override //IDrawRenderWindow
        public
                void draw(RenderWindow rw)
                {
                        for ( Sprite sprite : this.getSprites() )  rw.draw(sprite);
                }
}

//################################################
//################################################

class Player     implements IGetSprites
{
        ImageLoader  image;
        Vector2i     last, vleft, vright, vup, vdown;
       
        Sprite[]     bricks;
       
        int          speed;

public
        Player(ImageLoader  loader, int startx, int starty, int speed)
        {
                image = loader;
                image.setXY(100,100);
               
                last = new Vector2i(100,100);
               
                this.speed = speed;
        }
       
       
        public void setBricksMap(Sprite[]  safeZone)
        {
                this.bricks = /*new ArrayList<Sprite>( */ safeZone; /* );*/
        }
       
       
        /*
         * this code should checks collisions!
         */

        public void tryMoveTo(Vector2f  newPosition)
        {

                FloatRect  pos   = image.getSprite().getLocalBounds();
                Vector2i   vi    = new Vector2i(newPosition);
               
                if (vi.x> 800 || vi.x<0 || vi.y>600-pos.top || vi.y<pos.height) return;
               
                if (SafeZone.isColliding(image.getSprite(), bricks) == true)
                {
                        System.out.println("KOLIZJA");
                        return;
                }
               
                image.setXY(vi.x, vi.y);
               
                last = vi;
        }
       
       
        public void nextMove(Time dt, KeybAction  action)
        {
                if (action == KeybAction.none) return;
               
                float fmove = (dt.asMicroseconds() * speed)/5000;
               
                switch (action)
                {
                        case left  : tryMoveTo(new Vector2f(last.x -fmove, last.y)); break;
                        case right : tryMoveTo(new Vector2f(last.x +fmove, last.y)); break;
                        case up    : tryMoveTo(new Vector2f(last.x, last.y -fmove)); break;
                        case down  : tryMoveTo(new Vector2f(last.x, last.y +fmove)); break;
                }
        }
       
       
        @Override // IGetSprites
        public
                Sprite[] getSprites()
                {
                        return new Sprite[]{ image.getSprite() };
                }

}


                 
            /** ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 
                                                GAME`S MAIN LOOP
                 
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **/



class GameLoop
{

        //internal helper class
        class World
        {
                ArrayList<Sprite>  list;// list of sprites to be drawn
                RenderWindow       window;
               
                public
                        World(RenderWindow renderWindow)
                        {
                                list = new ArrayList<Sprite>();
                               
                                this.window = renderWindow;
                        }
                       
                       
                public
                        void add(IGetSprites  toBeDrawn) //adds by interface
                        {
                                if (toBeDrawn==null) return;
                               
                                Sprite []sprites = toBeDrawn.getSprites();
                               
                                if (sprites==null || sprites.length == 0) return;
                               
                                this.add(sprites);
                        }
               
                       
                public
                        void add(Sprite[]  sprites) //adds by array
                        {
                                for (Sprite s : sprites) list.add(s);
                        }
               
                       
                public
                        void clear()
                        {
                                list.clear();
                        }
               
                       
                public
                        void render(RenderWindow rw)
                        {
                                rw.clear();
                               
                                for (Sprite s : list) rw.draw(s);
                                       
                                rw.display();
                                this.clear();
                        }
                       
                public
                        void render()
                        {
                                render(window);
                        }
                       
                public
                        void close()
                        {
                                this.clear();
                                //window.clear();
                                window.close();
                        }              
        }

                                                                        /* - - - -
                                        GameLoop`s interface
                          - - - - */

 
        FloatRect     bounds;
        World             world;
       
        Background    background;
        Bricks        bricks;
        Player        player;
       
        Time              timePerFrame;
       
        RenderWindow  window;
       
        String            mediaDirPath;
        boolean       isRun;
       
       
                                                /*  ~  ~  ~
                                                        IMPLEMENTATION
                                                                           ~  ~  ~  */

       
public
        GameLoop(String mediaDirPath)
        {
                this.mediaDirPath = mediaDirPath;
               
                timePerFrame = Time.getSeconds(1.0f / 60.0f);
               
                bounds     = new FloatRect(new IntRect(0, 0, 800, 600));
                window     = new RenderWindow(new VideoMode(800,600), "GameFromScratch");
               
                background = new Background
                                   (    new FramedAnimation
                                                (       new ArrayList<ImageLoader>
                                                        (    Arrays.asList
                                                                 (      new ImageLoader[]
                                                                        {
                                                                                new ImageLoader("C:\\PROJ\\Media\\Maps\\map1.png",SpriteType.BACK),
                                                                                new ImageLoader("C:\\PROJ\\Media\\Maps\\map2.png",SpriteType.BACK),
                                                                                new ImageLoader("C:\\PROJ\\Media\\Maps\\map3.png",SpriteType.BACK),
                                                                                new ImageLoader("C:\\PROJ\\Media\\Maps\\map4.png",SpriteType.BACK),
                                                                        }
                                                                 )
                                                        )      
                                                ),
                                                250 //ms per frame
                                   );
               
                bricks     = new Bricks
                                   (
                                                new ImageLoader
                                                        (
                                                                "c:\\PROJ\\MEDIA\\Maps\\map1.png",
                                                                SpriteType.BRICK
                                                        ),
                                                "C:\\PROJ\\Media\\Maps\\map1.txt"
                                   );
                                   
                player     = new Player
                                   (
                                                new ImageLoader
                                                (
                                                        mediaDirPath+"\\Textures\\player2.png",
                                                        SpriteType.PLAYER
                                                ),
                                                100, //startX
                                                100, //startY
                                                5    //speed
                                   );
                player.setBricksMap(bricks.getSprites());
        }
       
       
        private KeybAction  getKey()
        {
                for (Event event : window.pollEvents())
        {
            if (Keyboard.isKeyPressed(Keyboard.Key.LEFT))  return KeybAction.left;
            if (Keyboard.isKeyPressed(Keyboard.Key.RIGHT)) return KeybAction.right;
            if (Keyboard.isKeyPressed(Keyboard.Key.UP))    return KeybAction.up;
            if (Keyboard.isKeyPressed(Keyboard.Key.DOWN))  return KeybAction.down;
           
            if (event.type == Event.Type.CLOSED) return KeybAction.esc;
           
            if (Keyboard.isKeyPressed(Keyboard.Key.ESCAPE)) return KeybAction.esc;

        }
        return KeybAction.none;
        }
       
       
        public void playGame()
        {
                Clock clock      = new Clock();
        Time  lastUpdate = Time.ZERO;
                       
                window  = new RenderWindow(new VideoMode(800,600),"JSFML RenderTest");
                world   = new World(window);
               
                isRun   = true;
               
                window.setFramerateLimit(60);
                window.setKeyRepeatEnabled(true);

                KeybAction key = KeybAction.none;
               
                while( window.isOpen() )
                {
                        Time dt    = clock.restart();
            lastUpdate = Time.add(lastUpdate, dt);
                     
            while (lastUpdate.asMicroseconds() > timePerFrame.asMicroseconds())
            {
                lastUpdate = Time.sub(lastUpdate, timePerFrame);

                                key = getKey();

                player.nextMove(lastUpdate, key);
               
                if (key==KeybAction.esc) window.close();
            }
     
                world.add(background);
            world.add(player);
            world.add(bricks);
           
            world.render();
                }
                world.close();
        }
}
 


/**
 * Run
 */

public class GameFromScratch
{
    public static void main(String[] args)
    {
        INFO.MEDIA_DIR = "C:\\PROJ\\Media";
       
        System.out.println("tak");
       
        GameLoop game = new GameLoop(INFO.MEDIA_DIR);
        game.playGame();
    }
}
 

Can anybody help? In attachments media for game.

I know that code should be separatet etc, I`ll tidy it in near future. I'm planning to create tutorial about JSFML, it's f.. amazing lib!

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Rectangle collision problem
« Reply #1 on: March 16, 2015, 09:25:31 pm »
I can't believe you are serious, you post 700+ lines of code and expect us to help you? I don't think even Meta Stackexchange expected this kind of post when they wrote the help vampire guidelines. Go get some sleep, learn to use your debugger and read the read before posting thread.

Quote
I'm planning to create tutorial about JSFML

Are you serious? Because I don't think you should be, tutorials should be written by people that know what they are talking about.

And one more thing while I'm thinking about it...

Quote
I`ve been coding for about 20 hours ( xD ) and my brain does not work. I tried various combinations in detecting collisions... and none works.

If this is your homework, then it is your job to do your homework and not have us fix every problem you run into. Feel free however to ask specific questions.
« Last Edit: March 16, 2015, 09:43:27 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

cx3

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Rectangle collision problem
« Reply #2 on: March 16, 2015, 11:04:24 pm »
You`re right... sorry :)

This is class that should detect collisions:

class SafeZone
{
        private static
                boolean isColliding //arglist
                (
                        Vector2f Ax1y1,
                        Vector2f Ax2y2,
                        Vector2f Bx1y1,
                        Vector2f Bx2y2
                )
                {//method`s body start:
                        float
                                widthA  = Math.abs(Ax1y1.x - Ax2y2.x),
                                widthB  = Math.abs(Bx1y1.x - Bx2y2.x),
                               
                                heightA = Math.abs(Ax1y1.y - Ax2y2.y),
                                heightB = Math.abs(Bx1y1.y - Bx2y2.y);
                               
                        if (
                                 (Math.abs(Ax1y1.x - Bx2y2.x) <= widthA + widthB)
                                                                        &&
                                  Math.abs(Ax1y1.y - Bx2y2.y) <= heightA + heightB
                                )      
                                return true;
                               
                        return false;
                }


public static
        boolean isColliding(Sprite A, Sprite B)
        {
                Vector2f
                        vA1 = A.getPosition(), vA2 = A.getOrigin(),
                        vB1 = B.getPosition(), vB2 = B.getOrigin();
                       
                float
                        vAdtx = Math.abs(vA2.x - vA1.x),
                    vAdty = Math.abs(vA2.y - vA1.y),
                   
                    vBdtx = Math.abs(vB2.x - vB1.x),
                    vBdty = Math.abs(vB2.y - vB1.y);
                   
               
                        vA2 = new Vector2f(vA1.x, vA1.x + 2*vAdtx);
                        vB2 = new Vector2f(vB1.x, vB1.x + 2*vBdtx);
               
                return isColliding(vA1, vA2, vB1, vB2);
        }
       
       
public static
        boolean isColliding(Sprite A, Sprite[] sprites)
        {
                for (Sprite sprite : sprites)
                        if (isColliding( sprite, A) == true ) return true;
                return false;
        }
}

And it does not work. I`ll repair it (this is a must), but anybody`s help make it faster.

I`m still learning JSFML, by now I feel that my knowledge about this library increased since last two weeks, so after several months of falling in love with I`m sure I`ll be able to create some video tut on YT ;>

Don't be angry with me, I'm really amazed ;)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Rectangle collision problem
« Reply #3 on: March 17, 2015, 01:24:38 am »
And you are trying to reinvent the wheel of rectangle intersection.... why? I'm sure JSFML provides the equivalent of sf::Rect::intersects(...) function.
« Last Edit: March 17, 2015, 04:19:21 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Rectangle collision problem
« Reply #4 on: March 17, 2015, 07:10:47 am »
And you are trying to reinvent the wheel if rectangle intersection.... why? I'm sure JSFML provides the equivalent of sf::Rect::intersects(...) function.
It does! :D (Javadoc)

Well, kind of! When did the SFML API change from "intersection" (calculate intersection rectangle) to "intersects" (yes/no)? I must have missed that.  :-X

JSFML - The Java binding to SFML.

cx3

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Rectangle collision problem
« Reply #5 on: March 17, 2015, 10:23:38 am »
I did not get that null-pointer is returned by FloatRect.intersection(FloatRect) if no collision detected, therefore i tried to solve collisions by myself. Ehhh, inadvertant.

private Vector2f  calcColl(float x, float y, float r)
        {      
                for (FloatRect  rects : brickRects)
                {
                        FloatRect ins = rects.intersection(new FloatRect(x, y, r, r));
                       
                        if (ins!=null)
                                return new Vector2f
                                (
                                        ins.width -ins.left,
                                        ins.height-ins.top
                                );
                }
                return new Vector2f(0.f, 0.f);
        }
       
       
        public void nextMove(Time dt, KeybAction  action)
        {
                if (action == KeybAction.none) return;
               
                FloatRect pos = image.getSprite().getGlobalBounds(), tmp = null;
               
                Vector2f  v = new Vector2f(pos.left, pos.top), c = null;
               
                float f = dt.asMicroseconds()/1000, r = 50.f;
                       
                        switch(action)
                        {
                                case left:
                                   c = calcColl(v.x-f, v.y, r);
                                   v = new Vector2f(v.x+c.x-f, v.y);
                                   break;
                               
                                case right:
                                   c = calcColl(v.x+f, v.y, r);
                                   v = new Vector2f(v.x+c.x+f, v.y);
                                   break;
                                 
                                case up:
                                   c = calcColl(v.x, v.y-f, r);
                                   v = new Vector2f(v.x, v.y+c.y-f);
                                   break;
                                 
                                case down:
                                   c = calcColl(v.x, v.y+f, r);
                                   v = new Vector2f(v.x, v.y+c.y+f);
                                   break;
                        }
                       
                //if (c!=null) System.out.println(c.toString());
               
                Vector2i vi = new Vector2i(v);
                image.setXY(vi.x, vi.y);
               
                System.out.println(image.getSprite().getPosition().toString());
        }

Part of Player.class. Intersections works sweet, some corrects and show must go on. Sorry again ;x

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Rectangle collision problem
« Reply #6 on: March 17, 2015, 04:24:36 pm »
Well, kind of! When did the SFML API change from "intersection" (calculate intersection rectangle) to "intersects" (yes/no)? I must have missed that.  :-X

Never? ???

https://github.com/SFML/SFML/commits/master/include/SFML/Graphics/Rect.hpp
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Rectangle collision problem
« Reply #7 on: March 18, 2015, 01:02:26 pm »
Never? ???
That's awkward... maybe it's a relic from the beginning, when I was developing against the SFML 1 API?
Anyway, it's on my TODO list. ;D

EDIT:
Ah, Hiura cleared this out for me.
Everything's fine, here's the explanation:
https://github.com/pdinklag/JSFML/issues/65#issuecomment-82158099
« Last Edit: March 18, 2015, 01:22:07 pm by pdinklag »
JSFML - The Java binding to SFML.

 

anything