Canvas Drawing Loop Problem

For questions about using Classic.

Post » Fri Mar 28, 2008 2:28 am

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:



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:



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?
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Mar 28, 2008 3:43 am

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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Mar 28, 2008 1:49 pm

Hi!

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

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

...you can add more nodes with right click
B
63
S
21
G
9
Posts: 154
Reputation: 7,009

Post » Fri Mar 28, 2008 3:15 pm

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
B
2
S
2
G
5
Posts: 512
Reputation: 2,674

Post » Fri Mar 28, 2008 6:10 pm

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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Mar 29, 2008 3:01 pm

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.
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,208

Post » Sat Mar 29, 2008 3:59 pm

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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Mar 29, 2008 4:32 pm

[quote="deadeye":25f1bt2v]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.[/quote:25f1bt2v]
You can borrow one from Ashleys Avatar... he has a lot of them.
B
4
S
2
G
4
Posts: 719
Reputation: 2,938


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest