Sprite pixel position

Create bug reports for the development to investigate, please read the guidelines before posting here!
Post Reply
rpggamer17
Posts: 44
Joined: Wed Jun 07, 2017 2:14 am

Sprite pixel position

Post by rpggamer17 » Fri Jun 16, 2017 1:11 am

Looking at the git hub I think you fixed some of this already.
Result from using the below code as the entry program for the following types of boards:

- Board smaller than screen resolution: Your sprite position will be offest do to the centering of the board on the screen.

- Board same as screen resolution: Your sprite position will be in the literal center of the sprite. I don't mind this really. Perhaps use the sprites collision vectors to determine it's center offset (on loading the sprite not when saving)?

- Board larger than screen resolution: You will never reach that little square. It keeps getting farther and farther away. - . -

Code: Select all

rpgcode.createCanvas(640,480, "Buffer");

rpgcode.registerKeyDown("ENTER", function () {
   Pos = rpgcode.getCharacterLocation(false);
   rpgcode.fillRect(Pos.x-8, Pos.y-8, 16, 16, "Buffer");
   rpgcode.renderNow("Buffer");
   rpgcode.renderNow();
},true);

rpgcode.registerKeyUp("ENTER", function () {
   rpgcode.clearCanvas("Buffer");
},true);

rpgcode.endProgram();
I figured I'd go ahead and post this. Mainly so I'll stop trying to jury rig my code to work with it. :P

User avatar
swordmaster
Site Admin
Posts: 53
Joined: Tue May 23, 2017 11:22 pm

Re: Sprite pixel position

Post by swordmaster » Mon Jun 19, 2017 12:08 pm

Hi rpggamer17,

Thanks for reporting this issue, I will start looking at it from today and I'll hopefully have a resolution by Friday for it. I think I need to figure out an accurate way to tell where the character is relative to the RPGcode screen which only understands coordinates between (0, 0) and the viewport width and height.

If you find yourself working around any other quirks in the Wizard just file them as bug reports, thanks!

rpggamer17
Posts: 44
Joined: Wed Jun 07, 2017 2:14 am

Re: Sprite pixel position

Post by rpggamer17 » Tue Jun 20, 2017 7:48 am

I will do if I find any. I've been checking up on the github every now and then.

I was going to bring up the drop down list not setting the sprite on the board. It's like it isn't being found?
But... it looks like you fixed that 10 days ago.
The bugs that I've found aren't bugs at all. It's just me learning JavaScript...

User avatar
swordmaster
Site Admin
Posts: 53
Joined: Tue May 23, 2017 11:22 pm

Re: Sprite pixel position

Post by swordmaster » Tue Jun 20, 2017 5:59 pm

I've added the function rpgcode.getViewPort(), this gives you access to the viewport object that slides around on the board as the character moves around. Think of it as a frame that slides above a bigger image, using the viewport's x, y, width, and height values it is possible to accurately draw the square in the characters center.

To do this you simply need to calculate the distances in x and y between the upper left corner of the viewport and the character's position, this gives you an (x, y) value in a range the canvas understands, see the modified code example:

Code: Select all

rpgcode.createCanvas(640,480, "Buffer");

rpgcode.registerKeyDown("ENTER", function () {
   var viewPort = rpgcode.getViewport();
   var Pos = rpgcode.getCharacterLocation(false);

   // Calculate the bounds of the viewport in the global (x, y) space.
   var endX = viewPort.x + viewPort.width;
   var endY = viewPort.y + viewPort.height;

   if (Pos.x < endX && Pos.y < endY) { // Check the character is in the viewport bounds.
      // Convert the characters global (x, y) to be relative to the canvas.
      var x = Pos.x - viewPort.x;
      var y = Pos.y- viewPort.y;

      rpgcode.fillRect(x - 8, y - 8, 16, 16, "Buffer");
      rpgcode.renderNow("Buffer");
      rpgcode.renderNow();
   }
},true);

rpgcode.registerKeyUp("ENTER", function () {
   rpgcode.clearCanvas("Buffer");
},true);

rpgcode.endProgram();
You'll be able to use this function with version 1.0.1 which comes out this Friday.

P.S.

Yes there was a bug with board sprites, I noticed it when making my own game. It will be fixed in the version I release on Friday.

rpggamer17
Posts: 44
Joined: Wed Jun 07, 2017 2:14 am

Re: Sprite pixel position

Post by rpggamer17 » Wed Jun 21, 2017 5:26 pm

This program is amazing. The battle system test I've made is a lot faster. I'm even using Mozilla and have a windows xp (In my defense, it was my moms computer and it was free). So far it works like a charm. I edited the board file and removed the folder it saved in front of the enemy file. I can still test my system and make progress. I'm currently simplifying some stuff... well trying to. I don't really know what features I want the skill system to be able to do. You added an awesome feature to the git hub, mouse events. I'll probably be abusing that. :P

User avatar
swordmaster
Site Admin
Posts: 53
Joined: Tue May 23, 2017 11:22 pm

Re: Sprite pixel position

Post by swordmaster » Fri Jun 23, 2017 5:12 pm

Awesome stuff, I can't wait to see what you end up doing with the software!

Slight amendment to getting the character's location if you want to get the visual offset for doing this kind of drawing you need to pass an extra parameter to the getCharacterLocation function. If set to true it will add the shift in x and y as a result of board centering.

Code: Select all

var inTiles = false;
var includeOffset = true;
var loc = rpgcode.getCharacterLocation(inTiles, includeOffset);

Post Reply