Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

sprite-image addressing?0, or 1?

an image's lowest coords are 1,1. if you set context to an image and say sprite(s,0,0) does sprite pixel 0,0 go to image 1,1, or does sprite pixel 1,1 go to image 1,1?

i'll try to devise a test, but i'm not sure i can even see one pixel. :smile:

Comments

  • dave1707dave1707 Mod
    Posts: 8,671

    An image created with set context can start at 1,1 to whatever size you set. If you sprite that image, then pixel 1,1 is whatever value you set in sprite. With spriteMode set to CORNER, sprite(0,0) will correspond to pixel 1,1 of the mage. sprite(-10,-10) will be pixel 1,1 of the image. Or am I misinterpreting your question.

  • that seems to be the answer i'm looking for. is there a typo in the last bit? how did you determine the answer?

  • dave1707dave1707 Mod
    Posts: 8,671

    @RonJeffries Heres the code I was playing with. When you create an image with setContext, the pixel positions don’t change for that image. You can move that image anywhere on the screen using sprite, but the pixel positions in the image don’t change. So sprite(-10,-10) places image pixel 1,1 at screen position -10,-10 provided spriteMode is set to CORNER.

    viewer.mode=STANDARD
    
    function setup() 
        parameter.integer("x",-50,50,0)
        parameter.integer("y",-50,50,0)
        noSmooth() 
        spriteMode(CORNER)
        img=image(100,100)
        setContext(img)
        background(255,0,0)
        setContext()      
    end
    
    function draw()
        background(0)
        sprite(img,x,y)
    end
    
    function touched(t)
        if t.state==BEGAN then
            r,g,b,a=img:get(1,1)
            print(r,"",g,"",b,"",a)
            print()
            r,g,b,a=img:get(100,100)
            print(r,"",g,"",b,"",a)
        end
    end
    
  • ah. that's not my question, or i think it isn't. but your code gives me an idea how to ask and answer it. thanks, i may be back. :wink:

  • my question was, when you create an image, which is indexed 1-100, and you write a sprite into that image at 0,0, does sprite 0,0 go into image 1,1, or does sprite 1,1 go into image 1,1? the answer is that sprite 0,0 goes into image 1,1.

    viewer.mode=STANDARD
    
    function setup()
        noSmooth()
        spriteMode(CORNER)
        img=image(100,100)
        jmg = image(100,100)
        setContext(img)
        background(255,0,0)
        setContext(jmg)
        background(0,255,0)
        sprite(img,1,1)
        setContext()
    end
    
    function draw()
        background(0)
        sprite(jmg,100,100)
    end
    
    function touched(t)
        if t.state==BEGAN then
            r,g,b,a=jmg:get(1,1)
            print(r,"",g,"",b,"",a)
            print()
            r,g,b,a=jmg:get(100,100)
            print(r,"",g,"",b,"",a)
        end
    end
    
  • dave1707dave1707 Mod
    edited November 18 Posts: 8,671

    @RonJeffries I guess I didn’t understand your original question. Glad you were able to take my wrong code and change it to get your answer. I now see what you were asking.

  • the whole 0 = 1 thing is weird. :smile:

Sign In or Register to comment.