Draw image

This topic contains 31 replies, has 6 voices, and was last updated by  juliocmfj 1 year, 7 months ago.

Viewing 15 posts - 1 through 15 (of 32 total)
  • Author
    Posts
  • #10117

    juliocmfj
    Participant

    Ex: I have an image drawn on the screen, when moving to the wireside or up side, when touching the corners, the image is automatically erased from the screen. When moving to the right or bottom corner, this does not happen. It is as if you where cutting the image when you hit the left and top corner.

    Any idea what that might be?

    Follow the code below:

    #10121

    Jesse
    Participant

    I could probably figure it out but I would probably burn my two remaining neurons trying to solve. It would be a bit easier if you post complete run-able code. A zip file maybe?

    #10122

    juliocmfj
    Participant

    I can post codes here. I get an illegal operation error. The I send the two code via download.

    https://drive.google.com/open?id=0B2lZ_pN3kwOJLUJTYWUwUjA2dVk

    #10133

    nerobot
    Participant

    There is no playable demo in archive – no images and map file. So I can’t test it.

    (My advices about your code were eaten by antispam, even splitted by parts)

    #10134

    juliocmfj
    Participant

    I forgot to send the whole project. Below is the link
    https://drive.google.com/open?id=0B2lZ_pN3kwOJVm9fTVBqT1hWWTQ

    #10135

    nerobot
    Participant

    Ok, will see.

    And there are my advices 🙂

    https://yadi.sk/i/F5Q1FaJ53MV4cb

    #10136

    juliocmfj
    Participant

    Great tips. I still have not much knowledge about Monkey2. Only now have I realized the rean benefit of overloading an operator…

    I’ll folow some of your tips.

    On the cut in the images when moving to the left or top corner, if I use the canvas.Translate(x, y) method, the same “error” does not happen, however everything on the screen is moved, and I want to do just scroll of the map (in this case).

    #10137

    Jesse
    Participant

    Actually your problem is not in your main file. It’s in your TiledImport in the RenderLayer Method. you have to figure out how to keep on drawing the image once the image position gets less than 0 and until the image position is less then the with of the tile. Right now you are not drawing any tiles if the position of the image is less than 0 so if the position of the image becomes -1 then you stop displaying it but you still have say 31 pixels(of a 32 pixel width image) to display and that is why you get that blank image on the side.
    I hope that’s clear to you.

    #10139

    juliocmfj
    Participant

    Problema solved. I changed the coordinates to Float and, like magic, the problem ended. I do not know if it’s a Monkey2 bug, but for me, that should not happen.

    Anyway, I appreciate everyone’s help and it’s the tip for anyone who has the same problem.

    #10140

    nerobot
    Participant

    The problem here is mixing UInt with Int.

    When you sum int with uint you got uint which have non-negative value only.

    If you replace all UInt with Int (including “for local x:uint = …”) your map will render normally.

    #10141

    juliocmfj
    Participant

    Nerobot, this makes all sense, however, the only change I made was in the x and y of the TiledLayer class, I was Int and I moved to Float.

    The x and y found in: map[x, y], are UInt, since there is no image with id less than zero in the array.

    #10142

    nerobot
    Participant

    Right, and you got Float+UInt=Float types conversion. The only (one) Float in expression make whole result as Float.

    And with float map get its negative coords.

    The x and y found in: map[x, y], are UInt, since there is no image with id less than zero in the array.

    yes, they are, but them “break” you expectation because of type conversion UInt+Int=UInt

    #10143

    juliocmfj
    Participant

    Got it. So I must have done something wrong, but I’ll try to explain my logic behind this rendering loop.

    In the first For Local y, I put it as UInt because it only traverses the array with the id’s of the images that represent the tiles, since there is none with id under 0. And so I did with For Local x.

    When drawing the tiles, I did this based on: x of the tile(float) + x of the loop For(UInt) * tileWidth and in the same way with the y coordinate.

    Does this seem to make sense or dir I really make a mistake?

    #10144

    nerobot
    Participant

    Does this seem to make sense or dir I really make a mistake?

    Using float for coords is OK.

    My posts above just answering for your

    and, like magic, the problem ended. I do not know if it’s a Monkey2 bug, but for me, that should not happen.

    Answer is – there is no magic, it’s just a type conversion rules. 🙂

    #10145

    juliocmfj
    Participant

    I made several basic mistakes there. Lol

    That’s the problem coming from BlitzMax, which did not give you that many options. There it only had Int and not UInt. It was all more “simple”.

    I hope Ia do not make the same mistakes and thank you for the tips.

Viewing 15 posts - 1 through 15 (of 32 total)

You must be logged in to reply to this topic.