Canvas Drawing Loop Problem

This forum is currently in read-only mode.
From the Asset Store
You need this package if you want to program a Street Fighter or battle game.
  • I'm trying to get the canvas to draw a line in a loop between four objects, from one object to the next, in order to draw a polygon.

    Here's the .cap:

    http://www.mediafire.com/?yamw9oepewn

    I have four copies of a sprite, and each copy has it's own private variable called nodenum. They are numbered 1, 2, 3, and 4, and this number is stored in nodenum.

    The I have a counter object that contains drawfrom and drawto variables. It starts at drawfrom = 1 and drawto = 2. It's supposed to find the node who's nodenum equals drawfrom and store that node's x and y coordinates in yet another object's private variables (ax and ay). Then it finds the node that matches drawto and stores it's coordinates in bx, by.

    Hope you're with me so far. Anyway, the counter then counts up drawfrom and drawto, so now drawfrom = 2 and drawto = 3 in preparation for the next line.

    Then it's supposed to draw a line on the canvas from ax,ay to bx,by, and start the loop over again.

    Here's the event sheet:

    <img src="http://i25.tinypic.com/24e81tl.png">

    I'm having two problems:

    1. The canvas seems to be resizing upon running the layout.

    2. It's still drawing a line... but it only draws one line, and the line is offset from the nodes 1 and 2. Like this:

    <img src="http://i32.tinypic.com/2mq3g2b.png">

    The tan part is the canvas. It's supposed to cover the entire image.

    I'm pretty sure the canvas resizing is a bug, but it seems like it wants to draw anyway. But there's only one line... is there something wrong with my loop? Should I be doing this differently?

  • Doh!

    I just realize that the offset of the line was due to the fact that I didn't realign my hotspot when I made the node sprite. But the rest is still broke.

  • Hi!

    Here is my solution. Hope it fits your needs...

    http://www.mediafire.com/?myf9ooaeghm

    ...you can add more nodes with right click

  • I've improved it by adding a text that says the value of each node, now it's much easier to predict where the next connection will be.

    http://www.mediafire.com/?vdcjtaxts99

  • Awesome, thank you both. And neverk... nice first post!

    Still, if possible I would like someone to point out to me why mine doesn't work. Obviously I'm doing something wrong, it would help me learn to know what.

  • Replace 'for each node' with

    Repeat node.count times

    This will fix your engine

    The 'for each' condition does more than just repeat an event a number of times, it automatically picks each single instance in turn. Remember subevents inherit the picked objects from parent events.

  • Ah, okay. I think I see. Maybe. But I just woke up and haven't had my coffee yet. I'm sure that light-bulb-turning-on eureka moment will happen some time though.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ah, okay. I think I see. Maybe. But I just woke up and haven't had my coffee yet. I'm sure that light-bulb-turning-on eureka moment will happen some time though.

    You can borrow one from Ashleys Avatar... he has a lot of them.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)